Skip to content

Commit fd27d72

Browse files
committed
feat: add limit-commits option
Adds a new option that can be used to set a maximum number of commits that branch-diff should work with prior to starting requesting GitHub APIs. This is an essential feature to help releasers avoid exceeding GitHub API secondary rate limit.
1 parent 5159aee commit fd27d72

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ But the comparison isn't quite as strict, generally leading to a shorter list of
4242
* `--commit-url`:A URL template which will be used to generate commit URLs for a repository not hosted in GitHub. `{ref}` is the placeholder that will be replaced with the commit, i.e. `--commit-url=https://gitlab.com/myUser/myRepo/commit/{ref}`. `{ghUser}` and `{ghRepo}` are available if they can be derived from package.json (Gitlab and Bitbucket URLs should be understood in package.json).
4343
* `--user`: Override the auto-detected GitHub user/org derived from package.json
4444
* `--repo`: Override the auto-detected GitHub repository name derived from package.json
45+
* `--limit-commits`: `number` Limits the number of commits for branch-diff to work with, e.g: `--limit-commits=500`. Note that this limit is set prior to applying all filters, this number does not represent the number of resulting commits.
46+
* `--skip-commits`: `number` Defines an amount of commits to be skipped from the initial difference list built between `base-branch` and `comparison-branch`, e.g: `--skip-commits=400`.
47+
48+
### Reducing the amount of commits to avoid hitting GitHub rate limits
49+
50+
Using the `limit-commits` and `skip-commits` options allow users to reduce the amount of commits that branch-diff will work with in order to avoid hitting GitHub API rate limits.
4551

4652
## License
4753

branch-diff.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ async function diffCollected (options, branchCommits) {
7575

7676
let list = branchCommits[1].filter((commit) => !isInList(commit))
7777

78+
if (options.limitCommits > 0) {
79+
list = list.slice(-options.limitCommits)
80+
}
81+
82+
// TODO: finish clean up the transition to skipCommits
83+
// TODO: branch-diff should error with exit code on GitHub API error
84+
if (options.skipCommits > 0) {
85+
list = list.slice(options.skipCommits)
86+
}
87+
7888
await collectCommitLabels(list)
7989

8090
if (options.excludeLabels.length > 0) {
@@ -125,6 +135,8 @@ async function main () {
125135
const endRef = argv['end-ref']
126136
let excludeLabels = []
127137
let requireLabels = []
138+
let limitCommits;
139+
let skipCommits;
128140

129141
if (argv.version || argv.v) {
130142
return console.log(`v ${require('./package.json').version}`)
@@ -148,6 +160,14 @@ async function main () {
148160
requireLabels = requireLabels.concat(argv['require-label'])
149161
}
150162

163+
if (argv['limit-commits']) {
164+
limitCommits = parseInt(argv['limit-commits'], 10);
165+
}
166+
167+
if (argv['skip-commits']) {
168+
skipCommits = parseInt(argv['skip-commits'], 10);
169+
}
170+
151171
if (argv.user) {
152172
ghId.user = argv.user
153173
}
@@ -160,6 +180,8 @@ async function main () {
160180
group,
161181
excludeLabels,
162182
requireLabels,
183+
limitCommits,
184+
skipCommits,
163185
endRef
164186
}
165187

0 commit comments

Comments
 (0)