Skip to content

Commit

Permalink
Limit commits to specified branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth committed Oct 12, 2022
1 parent 7024505 commit 40bc9b1
Show file tree
Hide file tree
Showing 5 changed files with 36,235 additions and 15,581 deletions.
8 changes: 6 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-transform-runtime", "@babel/plugin-proposal-object-rest-spread"],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-object-rest-spread"
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
},
"targets": "node 14.0"
}
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## vmaster (12/10/2022)


---

## v2.0.0 (26/08/2022)
- [Fix issue with outdated Babel presets](https://github.com/cjbarth/github-release-notes/commit/00cd40446e4adb927df84e8a1afa4585a296a390) - @cjbarth
- [Update code to support >= commander@7](https://github.com/cjbarth/github-release-notes/commit/f012addeb9c8f35aa4ee48650ed5716d2ff9db14) - @cjbarth
- [Enforce date types when checking to retrieve more pages of PRs](https://github.com/cjbarth/github-release-notes/commit/757ae32a42ce822b4b7235cb6312784ca95086b5) - @cjbarth
- [Try semver tag sort when no date is available](https://github.com/cjbarth/github-release-notes/commit/3583b208c14550fb7f459354d85202d94790b0dc) - @cjbarth
- [Update dotfiles for this fork](https://github.com/cjbarth/github-release-notes/commit/1fda4b2db38f347db96d4db59f3826ea9277f7f6) - @cjbarth
- [Update tests for fork and new features](https://github.com/cjbarth/github-release-notes/commit/59f222ac706c5cf0c1737158552cd8482aeb7ea4) - @cjbarth
- [Add option to get commits since last tag; don't skip any commits](https://github.com/cjbarth/github-release-notes/commit/73ba41a7dd926bc9e65e379ae5916736fd78ad18) - @cjbarth
- [Update changelog](https://github.com/cjbarth/github-release-notes/commit/2ba7ee5d15e69085234e3b112191a966ed32ad7b) - @cjbarth
- [Release 2.0.0](https://github.com/cjbarth/github-release-notes/commit/7024505d127242a55822a8cd76b36ea6ba4829f8) - @cjbarth

---

## v1.0.1 (01/04/2022)
- [Update release-it to auto-build](https://github.com/cjbarth/github-release-notes/commit/dbdcfd9a27a260d88952c2fc8319fcf2d3116367) - @cjbarth
- [Update README for new project name](https://github.com/cjbarth/github-release-notes/commit/dc1a6d5285d4921cdf3b63891ee69a7a413655d0) - @cjbarth
Expand Down
46 changes: 40 additions & 6 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,26 @@ class Gren {
});
}

async _getAllCommitsForBranch(branch) {
let page = 1;
const allCommits = [];
let totalPages;

do {
const response = await this.repo.listCommits({
sha: branch,
per_page: 100,
page
});

totalPages = this._getLastPage(response.headers.link);
page++;
allCommits.push(...response.data);
} while (page < totalPages);

return allCommits;
}

/**
* Create the ranges of release dates
*
Expand All @@ -1035,7 +1055,7 @@ class Gren {
*
* @return {Array}
*/
_createReleaseRanges(releaseDates) {
async _createReleaseRanges(releaseDates) {
const ranges = [];
const sortedReleaseDates = this._sortReleasesByDate(releaseDates);

Expand Down Expand Up @@ -1093,25 +1113,39 @@ class Gren {
this.tasks['Getting releases'].text = 'Getting tags';

const tags = await this._getAllTags(releases.length ? releases : false);
const branchCommitShas = (await this._getAllCommitsForBranch(this.options.head)).map(commit => commit.sha);
const filteredTags = tags.filter(tag => branchCommitShas.includes(tag.commit.sha));

this._validateRequiredTagsExists(tags, this.options.tags);
this._validateRequiredTagsExists(filteredTags, this.options.tags);

const releaseObjects = this._transformTagsIntoReleaseObjects(tags);
const releaseObjects = this._transformTagsIntoReleaseObjects(filteredTags);
const releaseDates = this._sortReleasesByDate(releaseObjects);
const selectedTags = (this._getSelectedTags(releaseDates) || (releaseDates.length > 1 ? [releaseDates[0], releaseDates[1]] : releaseDates));

loadedReleases(`Tags found: ${selectedTags.map(({ name }) => name).join(', ')}`);

const releaseRanges = this._createReleaseRanges(selectedTags);
const releaseRanges = await this._createReleaseRanges(selectedTags);

const loadedCommits = utils.task(this, 'Getting lists of commits by release');
for (const releaseRange of releaseRanges) {
let commits;
if (releaseRange[1].name != null) {
({ data: { commits } } = await this.repo.compareBranches(releaseRange[1].name, releaseRange[0].name));
({
data: { commits }
} = await this.repo.compareBranches(
releaseRange[1].name,
releaseRange[0].name
));
} else {
({ data: commits } = await this.repo.listCommits({ since: releaseRange[1].date, until: releaseRange[0].date }));
({ data: commits } = await this.repo.listCommits({
since: releaseRange[1].date,
until: releaseRange[0].date
}));
}

commits = commits.filter((commit) =>
branchCommitShas.includes(commit.sha)
);
releaseRange.push(commits);
}
loadedCommits('Commits acquired');
Expand Down
Loading

0 comments on commit 40bc9b1

Please sign in to comment.