Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

azure devops - Lines of Code modified in each Commit in TFS rest api. How do i get?

In TFS api only allow to get the modified file count only.But needed to get each file modified line count (added/deleted) for each commit in rest call.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There isn’t official released REST API to do that. But you can refer to these steps to achieve your requirements

  1. Get a list of commits to get a commit’s commit id.
  2. Get a commit by commit id (steps 1) to get parents value and repository id (The value at the end of _links>Repository>href) (Using the URL of _links>Changes>href can get file path if you don’t know)
  3. Get file diff by this POST request https://[account].visualstudio.com/[team project name] /_api/_versioncontrol/fileDiff?__v=5&diffParameters=[data 1]&repositoryId=[repository id]

The [data 1] value is the JSON data (remove whitespace).

JSON likes:

{
"originalPath":"/index.html",
"originalVersion":"GC[a parent value, step 2]",
"modifiedPath":"/index.html(path: step 2)",
"modifiedVersion":"GC[commit id]",
"partialDiff":true,
"includeCharDiffs":true
}

The result contains this (you need to calculate the items that changeType isn’t equal 0, 2 means remove, 1 means add):

 {
      "changeType": 2,
      "mLine": 9,
      "mLines": [],
      "mLinesCount": 0,
      "oLine": 9,
      "oLines": [
        "    <!-- Polyfill(s) for older browsers -->"
      ],
      "oLinesCount": 1
    },
 {
      "changeType": 1,
      "mLine": 22,
      "mLines": [
        "      <div>2</div>"
      ],
      "mLinesCount": 1,
      "oLine": 23,
      "oLines": [],
      "oLinesCount": 0
    }

You can capture the request URL of a commit (History > Commits > Select a commit) by using Developer Tools Network capture.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...