Skip to content

Commit

Permalink
fix: only comment about no contributions after checking all contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Feb 17, 2024
1 parent 811c487 commit e749416
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 121 deletions.
43 changes: 24 additions & 19 deletions lib/process-issue-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ async function processIssueComment({ context, commentReply }) {
return;
}

let pullCreated = false;

for (var contributor in contributors) {
const who = contributor;
const contributions = contributors[who];
Expand All @@ -45,7 +47,7 @@ async function processIssueComment({ context, commentReply }) {
success: false,
});

await triggerActionAdd(
pullCreated ||= await triggerActionAdd(
context,
commentReply,
log,
Expand All @@ -54,6 +56,13 @@ async function processIssueComment({ context, commentReply }) {
branchName
);
}

if (!pullCreated) {
commentReply.reply(
`I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use [valid contribution names](https://allcontributors.org/docs/en/emoji-key).`
);
}
}

async function triggerActionAdd(
Expand All @@ -65,12 +74,8 @@ async function triggerActionAdd(
branchName
) {
if (contributions.length === 0) {
log.info("No contributions");
commentReply.reply(
`I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use [valid contribution names](https://allcontributors.org/docs/en/emoji-key).`
);
return;
log.info(`No contributions for ${who}`);
return false;
}

// set up repository instance. Uses branch if it exists, falls back to repository's default branch
Expand Down Expand Up @@ -100,17 +105,17 @@ async function triggerActionAdd(
},
`${who} already have ${contributions.join(", ")}`
);
return;
} else {
log.info(
{
pullCreated,
success: true,
createdFor: user.id,
createdForType: "user",
createdForLogin: user.login.toLowerCase(),
},
`${who} added for ${contributions.join(", ")}`
);
}

log.info(
{
pullCreated,
success: true,
createdFor: user.id,
createdForType: "user",
createdForLogin: user.login.toLowerCase(),
},
`${who} added for ${contributions.join(", ")}`
);
return true;
}
2 changes: 1 addition & 1 deletion test/fixtures/issue_comment.created.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"created_at": "2019-01-10T08:36:52Z",
"updated_at": "2019-01-10T08:36:52Z",
"author_association": "MEMBER",
"body": "@all-contributors please add jakebolam for code, doc and infra"
"body": "@all-contributors please add jakebolam for code, doc and infra\n🤖 Beep boop! This comment was added automatically by [all-contributors-auto-action](https://github.com/marketplace/actions/all-contributors-auto-action).\nNot all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed.\n...and of course, thank you for contributing! 💙"
},
"repository": {
"id": 164268911,
Expand Down
110 changes: 9 additions & 101 deletions test/integration/__snapshots__/issue_comment.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ Array [
"action": "created",
"comment": Object {
"author_association": "MEMBER",
"body": "@all-contributors please add jakebolam for code, doc and infra",
"body": "@all-contributors please add jakebolam for code, doc and infra
🤖 Beep boop! This comment was added automatically by [all-contributors-auto-action](https://github.com/marketplace/actions/all-contributors-auto-action).
Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed.
...and of course, thank you for contributing! 💙",
"created_at": "2019-01-10T08:36:52Z",
"html_url": "https://github.com/all-contributors/all-contributors-bot/pull/1#issuecomment-453012966",
"id": 453012966,
Expand Down Expand Up @@ -668,62 +671,6 @@ I've put up [a pull request](https://github.com/all-contributors/all-contributor
}
`;
exports[`issue_comment event Happy path, add correct new multiple contributors: logs 1`] = `
Array [
Object {
"account": 46410174,
"accountLogin": "all-contributors",
"accountType": "organization",
"action": "add",
"contributions": Array [
"code",
"doc",
"infra",
],
"createdBy": 3534236,
"createdByLogin": "jakebolam",
"createdByType": "user",
"createdFor": 13580338,
"createdForLogin": "tenshiamd",
"createdForType": "user",
"id": "1",
"level": 30,
"msg": "tenshiamd added for code, doc, infra",
"name": "event",
"private": false,
"pullCreated": true,
"repository": 164268911,
"success": true,
"who": "tenshiamd",
},
Object {
"account": 46410174,
"accountLogin": "all-contributors",
"accountType": "organization",
"action": "add",
"contributions": Array [
"design",
"test",
],
"createdBy": 3534236,
"createdByLogin": "jakebolam",
"createdByType": "user",
"createdFor": 60179179,
"createdForLogin": "gr2m",
"createdForType": "user",
"id": "1",
"level": 30,
"msg": "gr2m added for design, test",
"name": "event",
"private": false,
"pullCreated": true,
"repository": 164268911,
"success": true,
"who": "gr2m",
},
]
`;
exports[`issue_comment event Happy path, add correct new multiple contributors: request body 1`] = `
Object {
"ref": "refs/heads/all-contributors/add-tenshiamd",
Expand Down Expand Up @@ -762,49 +709,10 @@ This was requested by jakebolam [in this comment](https://github.com/all-contrib
`;
exports[`issue_comment event Happy path, add correct new multiple contributors: request body 5`] = `
Object {
"ref": "refs/heads/all-contributors/add-gr2m",
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
}
`;
exports[`issue_comment event Happy path, add correct new multiple contributors: request body 6`] = `
Object {
"branch": "all-contributors/add-gr2m",
"content": "IyBBbGxDb250cmlidXRvcnNCb3QKQSBib3QgZm9yIGF1dG9tYXRpY2FsbHkgYWRkaW5nIGFsbC1jb250cmlidXRvcnMuIPCfpJYKClshW0J1aWxkXShodHRwczovL2ltZy5zaGllbGRzLmlvL2NpcmNsZWNpL3Byb2plY3QvZ2l0aHViL2FsbC1jb250cmlidXRvcnMvYWxsLWNvbnRyaWJ1dG9ycy1ib3QvbWFzdGVyLnN2ZyldKGh0dHBzOi8vY2lyY2xlY2kuY29tL2doL2FsbC1jb250cmlidXRvcnMvYWxsLWNvbnRyaWJ1dG9ycy1ib3QpClshW0NvdmVyYWdlXShodHRwczovL2ltZy5zaGllbGRzLmlvL2NvZGVjb3YvYy9naXRodWIvYWxsLWNvbnRyaWJ1dG9ycy9hbGwtY29udHJpYnV0b3JzLWJvdC5zdmcpXShodHRwczovL2NvZGVjb3YuaW8vZ2l0aHViL2FsbC1jb250cmlidXRvcnMvYWxsLWNvbnRyaWJ1dG9ycy1ib3QpClshW0FsbCBDb250cmlidXRvcnNdKGh0dHBzOi8vaW1nLnNoaWVsZHMuaW8vYmFkZ2UvYWxsX2NvbnRyaWJ1dG9ycy0xLW9yYW5nZS5zdmcpX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j7wn46oPC9hPiA8YSBocmVmPSJodHRwczovL2dpdGh1Yi5jb20vYWxsLWNvbnRyaWJ1dG9ycy9hbGwtY29udHJpYnV0b3JzLWJvdC9jb21taXRzP2F1dGhvcj1ncjJtIiB0aXRsZT0iVGVzdHMiPuKaoO+4jzwvYT48L3RkPgogICAgPC90cj4KICA8L3Rib2R5Pgo8L3RhYmxlPgoKPCEtLSBtYXJrZG93bmxpbnQtcmVzdG9yZSAtLT4KPCEtLSBwcmV0dGllci1pZ25vcmUtZW5kIC0tPgoKPCEtLSBBTEwtQ09OVFJJQlVUT1JTLUxJU1Q6RU5EIC0tPgoKVGhpcyBwcm9qZWN0IGZvbGxvd3MgdGhlIFthbGwtY29udHJpYnV0b3JzXShodHRwczovL2dpdGh1Yi5jb20vYWxsLWNvbnRyaWJ1dG9ycy9hbGwtY29udHJpYnV0b3JzKSBzcGVjaWZpY2F0aW9uLiBDb250cmlidXRpb25zIG9mIGFueSBraW5kIHdlbGNvbWUKCiMjIExJQ0VOU0UKCltNSVRdKExJQ0VOU0UpCg==",
"message": "docs: update README.md",
"sha": "bfce087f5fbed22257de1ee5056b20de63da0a13",
}
`;
exports[`issue_comment event Happy path, add correct new multiple contributors: request body 7`] = `
Object {
"branch": "all-contributors/add-gr2m",
"content": "ewogICJwcm9qZWN0TmFtZSI6ICJhbGwtY29udHJpYnV0b3JzLWJvdCIsCiAgInByb2plY3RPd25lciI6ICJhbGwtY29udHJpYnV0b3JzIiwKICAicmVwb1R5cGUiOiAiZ2l0aHViIiwKICAicmVwb0hvc3QiOiAiaHR0cHM6Ly9naXRodWIuY29tIiwKICAiZmlsZXMiOiBbCiAgICAiUkVBRE1FLm1kIgogIF0sCiAgImltYWdlU2l6ZSI6IDEwMCwKICAiY29tbWl0IjogZmFsc2UsCiAgInNraXBDaSI6IGZhbHNlLAogICJjb250cmlidXRvcnMiOiBbCiAgICB7CiAgICAgICJsb2dpbiI6ICJqYWtlYm9sYW0iLAogICAgICAibmFtZSI6ICJKYWtlIEJvbGFtIiwKICAgICAgImF2YXRhcl91cmwiOiAiaHR0cHM6Ly9hdmF0YXJzMi5naXRodWJ1c2VyY29udGVudC5jb20vdS8zNTM0MjM2P3Y9NCIsCiAgICAgICJwcm9maWxlIjogImh0dHBzOi8vamFrZWJvbGFtLmNvbSIsCiAgICAgICJjb250cmlidXRpb25zIjogWwogICAgICAgICJjb2RlIiwKICAgICAgICAiaWRlYXMiLAogICAgICAgICJpbmZyYSIsCiAgICAgICAgInRlc3QiCiAgICAgIF0KICAgIH0sCiAgICB7CiAgICAgICJsb2dpbiI6ICJncjJtIiwKICAgICAgIm5hbWUiOiAiZ3IybSIsCiAgICAgICJhdmF0YXJfdXJsIjogImh0dHBzOi8vYXZhdGFycy5naXRodWJ1c2VyY29udGVudC5jb20vdS82MDE3OTE3OT92PTQiLAogICAgICAicHJvZmlsZSI6ICJodHRwczovL2dpdGh1Yi5jb20vZ3IybSIsCiAgICAgICJjb250cmlidXRpb25zIjogWwogICAgICAgICJkZXNpZ24iLAogICAgICAgICJ0ZXN0IgogICAgICBdCiAgICB9CiAgXSwKICAiY29tbWl0VHlwZSI6ICJkb2NzIiwKICAiY29tbWl0Q29udmVudGlvbiI6ICJhbmd1bGFyIiwKICAiY29udHJpYnV0b3JzUGVyTGluZSI6IDcKfQo=",
"message": "docs: update .all-contributorsrc",
"sha": "dff34f715bca51114c0336a49381456a926806d5",
}
`;
exports[`issue_comment event Happy path, add correct new multiple contributors: request body 8`] = `
Object {
"base": "master",
"body": "Adds @gr2m as a contributor for design, test.
This was requested by jakebolam [in this comment](https://github.com/all-contributors/all-contributors-bot/pull/1#issuecomment-453012966)",
"head": "all-contributors/add-gr2m",
"maintainer_can_modify": true,
"title": "docs: add gr2m as a contributor for design, and test",
}
`;
exports[`issue_comment event Happy path, add correct new multiple contributors: request body 9`] = `
Object {
"body": "@jakebolam
I've put up [a pull request](https://github.com/all-contributors/all-contributors-bot/pull/1347) to add @tenshiamd! :tada:
I've put up [a pull request](https://github.com/all-contributors/all-contributors-bot/pull/1347) to add @gr2m! :tada:",
I've put up [a pull request](https://github.com/all-contributors/all-contributors-bot/pull/1347) to add @tenshiamd! :tada:",
}
`;
Expand All @@ -821,7 +729,7 @@ Array [
"createdByType": "user",
"id": "1",
"level": 30,
"msg": "No contributions",
"msg": "No contributions for jakebolam",
"name": "event",
"private": false,
"repository": 164268911,
Expand All @@ -836,7 +744,7 @@ Object {
"body": "@jakebolam
I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use [valid contribution names](https://allcontributors.org/docs/en/emoji-key).",
Please make sure to use [valid contribution names](https://allcontributors.org/docs/en/emoji-key).",
}
`;
Expand Down Expand Up @@ -923,7 +831,7 @@ Array [
"id": "1",
"isKnownError": true,
"level": 30,
"msg": "This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected token o in JSON at position 1",
"msg": "This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected token 'o', \\"nope\\" is not valid JSON",
"name": "event",
},
]
Expand All @@ -933,7 +841,7 @@ exports[`issue_comment event invalid .all-contributorsrc: request body 1`] = `
Object {
"body": "@jakebolam
This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected token o in JSON at position 1",
This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected token 'o', \\"nope\\" is not valid JSON",
}
`;
Expand Down

0 comments on commit e749416

Please sign in to comment.