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

Apply ignoreCommitters config to PR creators #22

Merged
merged 2 commits into from
May 3, 2024
Merged
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
5 changes: 4 additions & 1 deletion src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
79 changes: 77 additions & 2 deletions src/functional/__snapshots__/markdown-full.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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`] = `
"
## [email protected] (1977-05-25)
Expand Down Expand Up @@ -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))


Expand Down Expand Up @@ -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))


Expand Down
60 changes: 60 additions & 0 deletions src/functional/markdown-full.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down Expand Up @@ -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[] } = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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", () => {
Expand All @@ -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]);
Expand Down
Loading