在TFS rest api的每个Commit中修改的代码行.如何得到? [英] Lines of Code modified in each Commit in TFS rest api. How do i get?

查看:108
本文介绍了在TFS rest api的每个Commit中修改的代码行.如何得到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TFS api中,只允许获取修改后的文件数.但是需要为rest调用中的每个提交获取每个文件的修改后的行数(添加/删除).

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.

推荐答案

目前尚无官方发布的REST API.但是您可以参考这些步骤来达到您的要求

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

  1. 获取提交列表以获取提交的提交ID.
  2. 通过提交获取提交id (步骤1)以获取父级值和存储库ID(_links> Repository> href末尾的值)(使用_links> Changes> href的URL可以获取文件路径)
  3. 通过此 POST 请求获取文件差异>://://account ] .visualstudio.com/[团队项目名称]/_api/_versioncontrol/fileDiff?__ v = 5& diffParameters = [数据1]& repositoryId = [存储库ID]
  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]

[data 1]值是JSON数据(删除空白).

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

JSON喜欢:

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

结果包含此内容(您需要计算changeType不等于0、2表示删除,1表示添加的项目):

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
    }

您可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆