From 79aa3db4569ad2ca1327444ef71cd671b740d71d Mon Sep 17 00:00:00 2001 From: nickschot Date: Fri, 3 May 2024 15:45:10 +0200 Subject: [PATCH 1/2] Apply ignoreCommitters config to PR creators --- src/changelog.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/changelog.ts b/src/changelog.ts index 162ad04..45ad416 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -203,7 +203,10 @@ export default class Changelog { releaseMap[currentTag] = { name: currentTag, date, commits: [] }; } - releaseMap[currentTag].commits.push(commit); + let prUserLogin = commit.githubIssue?.user.login; + if (prUserLogin && !this.ignoreCommitter(prUserLogin)) { + releaseMap[currentTag].commits.push(commit); + } } } From 0f921553a254d490674e049f564b49b77ee21dc7 Mon Sep 17 00:00:00 2001 From: nickschot Date: Fri, 3 May 2024 16:33:12 +0200 Subject: [PATCH 2/2] Add test case --- .../__snapshots__/markdown-full.spec.ts.snap | 79 ++++++++++++++++++- src/functional/markdown-full.spec.ts | 60 ++++++++++++++ 2 files changed, 137 insertions(+), 2 deletions(-) diff --git a/src/functional/__snapshots__/markdown-full.spec.ts.snap b/src/functional/__snapshots__/markdown-full.spec.ts.snap index 8e7f8f3..9535d03 100644 --- a/src/functional/__snapshots__/markdown-full.spec.ts.snap +++ b/src/functional/__snapshots__/markdown-full.spec.ts.snap @@ -1,5 +1,70 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`createMarkdown ignore config ignores PRs from bot users even if they were not the (merge) committer 1`] = ` +" +## Unreleased (2099-01-01) + +#### :rocket: New Feature +* \`the-force-awakens\`, \`rogue-one\` + * [#7](https://github.com/embroider-build/github-changelog/pull/7) feat: that is not how the Force works! ([@han-solo](https://github.com/han-solo)) + +#### :nail_care: Enhancement +* \`the-force-awakens\`, \`rogue-one\` + * [#7](https://github.com/embroider-build/github-changelog/pull/7) feat: that is not how the Force works! ([@han-solo](https://github.com/han-solo)) + +#### Committers: 1 +- Han Solo ([@han-solo](https://github.com/han-solo)) + + +## v6.0.0 (1983-05-25) + +#### :rocket: New Feature +* \`return-of-the-jedi\` + * [#5](https://github.com/embroider-build/github-changelog/pull/5) feat: I am your father ([@vader](https://github.com/vader)) + +#### :bug: Bug Fix +* \`return-of-the-jedi\` + * [#4](https://github.com/embroider-build/github-changelog/pull/4) fix: RRRAARRWHHGWWR ([@chewbacca](https://github.com/chewbacca)) + +#### :nail_care: Enhancement +* \`return-of-the-jedi\` + * [#6](https://github.com/embroider-build/github-changelog/pull/6) refactor: he is my brother ([@princess-leia](https://github.com/princess-leia)) + +#### :house: Maintenance +* \`return-of-the-jedi\` + * [#4](https://github.com/embroider-build/github-changelog/pull/4) fix: RRRAARRWHHGWWR ([@chewbacca](https://github.com/chewbacca)) + +#### Committers: 3 +- Chwebacca ([@chewbacca](https://github.com/chewbacca)) +- Darth Vader ([@vader](https://github.com/vader)) +- Princess Leia Organa ([@princess-leia](https://github.com/princess-leia)) + + +## v5.0.0 (1980-05-17) + +#### :boom: Breaking Change +* \`empire-strikes-back\` + * [#2](https://github.com/embroider-build/github-changelog/pull/2) chore: Terminate her... immediately! ([@gtarkin](https://github.com/gtarkin)) + +#### :bug: Bug Fix +* \`empire-strikes-back\` + * [#3](https://github.com/embroider-build/github-changelog/pull/3) fix: Get me the rebels base! ([@vader](https://github.com/vader)) + +#### Committers: 2 +- Darth Vader ([@vader](https://github.com/vader)) +- Governor Tarkin ([@gtarkin](https://github.com/gtarkin)) + + +## v4.0.0 (1977-05-25) + +#### :rocket: New Feature +* \`a-new-hope\` + * [#1](https://github.com/embroider-build/github-changelog/pull/1) feat: May the force be with you ([@luke](https://github.com/luke)) + +#### Committers: 1 +- Luke Skywalker ([@luke](https://github.com/luke))" +`; + exports[`createMarkdown multiple tags outputs correct changelog 1`] = ` " ## a-new-hope@4.0.0 (1977-05-25) @@ -42,7 +107,12 @@ exports[`createMarkdown single project outputs correct changelog 1`] = ` #### :nail_care: Enhancement * [#7](https://github.com/embroider-build/github-changelog/pull/7) feat: that is not how the Force works! ([@han-solo](https://github.com/han-solo)) -#### Committers: 1 +#### :house: Maintenance +* \`return-of-the-jedi\` + * This is the commit title for the issue (#8) ([@bot-user](https://github.com/bot-user)) + +#### Committers: 2 +- Bot User ([@bot-user](https://github.com/bot-user)) - Han Solo ([@han-solo](https://github.com/han-solo)) @@ -100,7 +170,12 @@ exports[`createMarkdown single tags outputs correct changelog 1`] = ` * \`the-force-awakens\`, \`rogue-one\` * [#7](https://github.com/embroider-build/github-changelog/pull/7) feat: that is not how the Force works! ([@han-solo](https://github.com/han-solo)) -#### Committers: 1 +#### :house: Maintenance +* \`return-of-the-jedi\` + * This is the commit title for the issue (#8) ([@bot-user](https://github.com/bot-user)) + +#### Committers: 2 +- Bot User ([@bot-user](https://github.com/bot-user)) - Han Solo ([@han-solo](https://github.com/han-solo)) diff --git a/src/functional/markdown-full.spec.ts b/src/functional/markdown-full.spec.ts index ffcad2a..6595006 100644 --- a/src/functional/markdown-full.spec.ts +++ b/src/functional/markdown-full.spec.ts @@ -7,6 +7,18 @@ jest.mock("../git"); jest.mock("../fetch"); const listOfCommits: CommitListItem[] = [ + { + sha: "a0000017", + refName: "", + summary: "Merge pull request #8 from my-dependency", + date: "2017-01-01", + }, + { + sha: "a0000016", + refName: "", + summary: "chore: Update dependency", + date: "2017-01-01", + }, { sha: "a0000015", refName: "", @@ -117,6 +129,8 @@ const listOfPackagesForEachCommit: { [id: string]: string[] } = { a0000013: ["packages/return-of-the-jedi/package.json"], a0000014: ["packages/the-force-awakens/mission.js", "packages/rogue-one/mission.js"], a0000015: ["packages/untitled/script.md"], + a0000016: ["packages/return-of-the-jedi/package.json"], + a0000017: ["packages/return-of-the-jedi/package.json"], }; const listOfFileForEachCommit: { [id: string]: string[] } = { @@ -135,6 +149,8 @@ const listOfFileForEachCommit: { [id: string]: string[] } = { a0000013: ["return-of-the-jedi/package.json"], a0000014: ["the-force-awakens/mission.js", "rogue-one/mission.js"], a0000015: ["untitled/script.md"], + a0000016: ["packages/return-of-the-jedi/package.json"], + a0000017: ["packages/return-of-the-jedi/package.json"], }; const usersCache = { @@ -194,6 +210,13 @@ const usersCache = { name: "C-3PO", }, }, + "https://api.github.com/users/bot-user": { + body: { + login: "bot-user", + html_url: "https://github.com/bot-user", + name: "Bot User", + }, + }, }; const issuesCache = { "https://api.github.com/repos/embroider-build/github-changelog/issues/1": { @@ -273,6 +296,18 @@ const issuesCache = { user: usersCache["https://api.github.com/users/han-solo"].body, }, }, + "https://api.github.com/repos/embroider-build/github-changelog/issues/8": { + body: { + number: 8, + title: "This is the commit title for the issue (#8)", + labels: [{ name: "Type: Maintenance" }, { name: "Status: In Progress" }], + user: { + login: "bot-user", + html_url: "https://github.com/bot-user", + name: "Bot User", + }, + }, + }, }; describe("createMarkdown", () => { @@ -284,6 +319,31 @@ describe("createMarkdown", () => { jest.resetAllMocks(); }); + describe("ignore config", () => { + it("ignores PRs from bot users even if they were not the (merge) committer", async () => { + require("../git").changedPaths.mockImplementation((sha: string) => { + return listOfPackagesForEachCommit[sha]; + }); + require("../git").lastTag.mockImplementation(() => "v8.0.0"); + require("../git").listCommits.mockImplementation(() => listOfCommits); + require("../git").listTagNames.mockImplementation(() => listOfTags); + + require("../fetch").__setMockResponses({ + ...usersCache, + ...issuesCache, + }); + + const MockedChangelog = require("../changelog").default; + const changelog = new MockedChangelog({ + ignoreCommitters: ["bot-user"], + }); + + const markdown = await changelog.createMarkdown(); + + expect(markdown).toMatchSnapshot(); + }); + }); + describe("single tags", () => { it("outputs correct changelog", async () => { require("../git").changedPaths.mockImplementation((sha: string) => listOfPackagesForEachCommit[sha]);