计算 GitHub 拉取请求中的总更改行数(即两个分支之间)

Counting the Total Lines of Changes in a GitHub pull request(i.e. between two branches)

有没有办法计算拉取请求中出现的更改总数?我想构建一个工具,如果 PR 变更线超过一定的阈值,应该限制用户提交。

我试过 git diff origin/master..<featureBranch> 但它给出了一些不正确的更改行。感谢任何帮助。

要计算拉取请求中更改的代码行数,您应该使用

git log --shortstat sha_of_commit

git log --stat sha_of_commit (more verbose output)

或者如果你有一些差异,没有提交,那么你应该用日志交换差异:

git diff --stat / --shortstat

好的,dangerJs 似乎是进行 PR 检查的有效方法。我实际上是在寻找这种 PR 构建器检查:

https://github.com/ReactiveX/rxjs/blob/master/dangerfile.js#L17-L22

// Warn when PR size is large
var bigPRThreshold = 600;
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
  warn(':exclamation: Big PR (' + ++errorCount + ')');
  markdown('> (' + errorCount + ') : Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.');
}