请问是否有API能获取指定commit的文件变更列表和文件变更行数

尝试了v4的commit.diff(),在有文件超大时,diff键不会给出变更记录,无法通过手动处理;
请教下是否有api是直接提供此能力的

可以参考下这个 API 是不是合适:Merge requests API | GitLab

你好,看了下MR相关的API,其中有和commit diff接口一样的返回结构,但是其中不包含stats数据(文件改动addtions、deletions),由于diff字段在文件改动较大时候只会返回空字符串,无法通过遍历diff文件统计文件改动行数,可能不太符合我的要求~

"diffs": [{
    "old_path": "LICENSE",
    "new_path": "LICENSE",
    "a_mode": "0",
    "b_mode": "100644",
    "diff": "--- /dev/null\n+++ b/LICENSE\n@@ -0,0 +1,21 @@\n+The MIT License (MIT)\n+\n+Copyright (c) 2018 Administrator\n+\n+Permission is hereby granted, free of charge, to any person obtaining a copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n+\n+The above copyright notice and this permission notice shall be included in all\n+copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+SOFTWARE.\n",
    "new_file": true,
    "renamed_file": false,
    "deleted_file": false
  }]```

“stats”: {
“additions”: 2,
“deletions”: 2,
“total”: 4
},

在使用gpt寻找解答的过程中,不同工具都提到 diff_stats 接口返回的diff中会包含文件的stats统计信息,但是在文档中没有找到相关接口 :joy: 有无大佬可以帮忙解答下这个接口是否是个隐藏彩蛋

不能听信 GPT 的一面之词哈。因为这部分 api 对性能消耗比较大,所以目前还没有更为详细的。

先用commit diff接口实现了 :relieved:,以后有问题再看是否有更好的解决方案吧~

1 个赞