Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add limit-commits option #67

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ But the comparison isn't quite as strict, generally leading to a shorter list of
* `--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).
* `--user`: Override the auto-detected GitHub user/org derived from package.json
* `--repo`: Override the auto-detected GitHub repository name derived from package.json
* `--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.
* `--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`.

### Reducing the amount of commits to avoid hitting GitHub rate limits

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.

## License

Expand Down
22 changes: 22 additions & 0 deletions branch-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ async function diffCollected (options, branchCommits) {

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

if (options.limitCommits > 0) {
list = list.slice(-options.limitCommits)
}

// TODO: finish clean up the transition to skipCommits
// TODO: branch-diff should error with exit code on GitHub API error
if (options.skipCommits > 0) {
list = list.slice(options.skipCommits)
}

await collectCommitLabels(list)

if (options.excludeLabels.length > 0) {
Expand Down Expand Up @@ -125,6 +135,8 @@ async function main () {
const endRef = argv['end-ref']
let excludeLabels = []
let requireLabels = []
let limitCommits;
let skipCommits;

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

if (argv['limit-commits']) {
limitCommits = parseInt(argv['limit-commits'], 10);
}

if (argv['skip-commits']) {
skipCommits = parseInt(argv['skip-commits'], 10);
}

if (argv.user) {
ghId.user = argv.user
}
Expand All @@ -160,6 +180,8 @@ async function main () {
group,
excludeLabels,
requireLabels,
limitCommits,
skipCommits,
endRef
}

Expand Down
Loading