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.
Solution 1:
There isn’t official released REST API to do that. But you can refer to these steps to achieve your requirements
- Get a list of commits to get a commit’s commit id.
- 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)
- 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.