Skip to content

Commit 86d58ed

Browse files
committed
PR Bot Suggestions Emoji Check
1 parent 15e8519 commit 86d58ed

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# This workflow ensures that PR authors have acknowledged and reviewed the code suggestions made by the PR agent
2+
# by checking if the author has marked a self-review checkbox in the comments and approves the PR if it is checked.
3+
4+
name: Verify Author Self-Review
5+
6+
on:
7+
# Since `issue_comment` cannot directly trigger a PR workflow, this must be done via the main branch workflow.
8+
issue_comment:
9+
types: [edited]
10+
11+
jobs:
12+
verify-author-self-review:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Check for Author self-review in comments and Approve PR
17+
uses: actions/github-script@v7
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
script: |
21+
const issue_number = context.payload.issue.number;
22+
23+
if (!context.payload.issue.pull_request) {
24+
console.log('This comment is not on a pull request.');
25+
return;
26+
}
27+
28+
console.log(`Pull Request Number: ${issue_number}`);
29+
30+
const { data: comments } = await github.rest.issues.listComments({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
issue_number: issue_number
34+
});
35+
36+
const foundChecked = comments.some(comment =>
37+
comment.body.trim().includes('- [x] **Author self-review**:')
38+
);
39+
40+
console.log(`foundChecked: ${foundChecked}`);
41+
42+
if (foundChecked) {
43+
// Check if the PR has already been approved by kojo-bot
44+
const { data: reviews } = await github.rest.pulls.listReviews({
45+
owner: context.repo.owner,
46+
repo: context.repo.repo,
47+
pull_number: issue_number
48+
});
49+
50+
console.log('Reviewers:');
51+
reviews.forEach(review => {
52+
console.log(`- ${review.user.login} (State: ${review.state})`);
53+
});
54+
55+
const botApproval = reviews.some(review =>
56+
review.user.login === 'github-actions[bot]' && review.state === 'APPROVED'
57+
);
58+
59+
if (botApproval) {
60+
console.log('Pull request has already been approved by kojo-bot. Skipping approval.');
61+
return;
62+
}
63+
64+
// Approve the pull request if the self-review is checked and not already approved
65+
await github.rest.pulls.createReview({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
pull_number: issue_number,
69+
event: 'APPROVE',
70+
});
71+
console.log('Pull request approved.');
72+
}

.github/workflows/pr-comment.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: PR Comment
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
7+
jobs:
8+
add-comment:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Add PR Comment
13+
uses: actions/github-script@v7
14+
with:
15+
script: |
16+
await github.rest.issues.createComment({
17+
issue_number: context.issue.number,
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
body: "## PR Code Suggestions ✨"
21+
})

0 commit comments

Comments
 (0)