From db6de740d6b7697bfae1f79141aa16c34de958f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Thu, 12 Sep 2024 16:52:43 -0400 Subject: [PATCH] fix: only comment about no contributions after checking all contributors (#489) **What**: Fixes #468. **Why**: Currently, the bot comments _"I couldn't determine ..."_ as soon as a potential contributor is found to not have any contributions. But if there are multiple potential contributors, that comment shouldn't happen. **How**: With these changes, the comment is only added after all potential contributors are checked for sending a PR. **Checklist**: - [x] Documentation _(n/a for bug fix)_ - [x] Ready to be merged - ~[ ] Added myself to contributors table.~ --- lib/process-issue-comment.js | 43 +++++++++++++----------- test/fixtures/issue_comment.created.json | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/process-issue-comment.js b/lib/process-issue-comment.js index b0c4c836..73360cd5 100644 --- a/lib/process-issue-comment.js +++ b/lib/process-issue-comment.js @@ -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]; @@ -45,7 +47,7 @@ async function processIssueComment({ context, commentReply }) { success: false, }); - await triggerActionAdd( + pullCreated ||= await triggerActionAdd( context, commentReply, log, @@ -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( @@ -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 @@ -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; } diff --git a/test/fixtures/issue_comment.created.json b/test/fixtures/issue_comment.created.json index 09749e2c..75c6ffea 100644 --- a/test/fixtures/issue_comment.created.json +++ b/test/fixtures/issue_comment.created.json @@ -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,