Ayan
Ayan

Reputation: 2380

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

Is there a way to count the total number of change that appears in a pull request ? I wanted to build a tool that should restrict the users to commit, if the PR Lines of Change is more than a certian threshold.

I tried doing git diff origin/master..<featureBranch> but it's giving some incorrect lines of change. Any help is appreciated.

Upvotes: 4

Views: 9328

Answers (2)

Ayan
Ayan

Reputation: 2380

Ok, dangerJs seems an effective way to do the PR checks. I was actually looking for this kind of PR builder check:

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.');
}

Upvotes: 0

Robert Pawlak
Robert Pawlak

Reputation: 529

For counting changed lines of code in pull request you should use

git log --shortstat sha_of_commit

or

git log --stat sha_of_commit (more verbose output)

or if you have some diff, not commit, then you should swap diff with log:

git diff --stat / --shortstat

Upvotes: 3

Related Questions