Skip to content

Commit

Permalink
fix: only comment about no contributions after checking all contribut…
Browse files Browse the repository at this point in the history
…ors (#489)

**What**: Fixes #468.

<!-- Why are these changes necessary? -->
**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 were these changes implemented? -->
**How**: With these changes, the comment is only added after all
potential contributors are checked for sending a PR.

<!-- Have you done all of these things?  -->
**Checklist**:
<!-- add "N/A" to the end of each line that's irrelevant to your changes
-->
<!-- to check an item, place an "x" in the box like so: "- [x]
Documentation" -->
- [x] Documentation _(n/a for bug fix)_
- [x] Ready to be merged <!-- In your opinion, is this ready to be
merged as soon as it's reviewed? -->
- ~[ ] Added myself to contributors table.~
  • Loading branch information
JoshuaKGoldberg authored Sep 12, 2024
1 parent 86d6bc7 commit db6de74
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 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

1 comment on commit db6de74

@Jircs1
Copy link

@Jircs1 Jircs1 commented on db6de74 Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.