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

查看:17
本文介绍了在 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 获取提交 (steps 1) to get parents value and repository id (the value at the end of _links>Repository>href)(使用_links>Changes>href的URL可以获取文件路径,如果你不知道)
  3. 通过此 POST 请求获取文件差异 https://[account].visualstudio.com/[team 项目名称]/_api/_versioncontrol/fileDiff?__v=5&diffParameters=[data 1]&repositoryId=[repository 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
    }

您可以使用 开发者工具网络捕获.

这篇关于在 TFS rest api 中的每个 Commit 中修改的代码行.如何得到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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