Skip to content

Commit

Permalink
feat: Add self-approval message check
Browse files Browse the repository at this point in the history
Signed-off-by: Qian Qian "Cubik"‎ <[email protected]>
  • Loading branch information
Cubik65536 committed Jan 10, 2024
1 parent b942afa commit b2a784d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ In order to use the bot, the config file should be provided. Config file should
Define the list of comments that will be considered as self-approval.

```yml
self_approval_comments:
self_approval_messages:
- "I self-approve!"
- "I self-certify!"
```
Expand Down
20 changes: 18 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export default (app: Probot) => {
if (context.isBot) return; // ignore bot comments
if (!new IsMessageForApp(context).verify()) return; // ignore comments that don't mention the app

// Get configuration
const config: any = await context.config('self-approval.yml');

// The pull request and comment creators
const issueUser = context.payload.issue.user.login;
const reviewUser = context.payload.comment.user.login;

// Get the comment sent by the user
const comment = context.payload.comment.body;
context.log("comment received: " + comment);
Expand All @@ -17,7 +24,16 @@ export default (app: Probot) => {
const message = comment.split(" ").slice(1).join(" ");
context.log("message from comment: " + message);

const issueUser = context.payload.issue.user.login;
const reviewUser = context.payload.comment.user.login;
// If the message is not in the list of self-approval messages, add a confused reaction
const isSelfApproval = config.self_approval_messages.includes(message);
context.log("is self approval: " + isSelfApproval);
if (!isSelfApproval) {
return context.octokit.reactions.createForIssueComment({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
comment_id: context.payload.comment.id,
content: "confused"
});
}
});
};

0 comments on commit b2a784d

Please sign in to comment.