@@ -4,25 +4,134 @@ permissions:
44 id-token : write
55 contents : read
66 pull-requests : write
7+ issues : write
8+ actions : read
79
810on :
9- pull_request :
11+ issue_comment :
12+ types : [created]
1013 pull_request_review_comment :
1114 types : [created]
1215
1316concurrency :
14- group : ${{ github.repository }}-${{ github.event.number || github.head_ref ||
15- github.sha }}-${{ github.workflow }}-${{ github.event_name ==
16- ' pull_request_review_comment' && 'pr_comment' || 'pr' }}
17- cancel-in-progress : ${{ github.event_name != 'pull_request_review_comment' }}
17+ group : ${{ github.repository }}-${{ github.event.number || github.event.issue.number || github.head_ref || github.sha }}-${{ github.workflow }}-ai-review
18+ cancel-in-progress : true
1819
1920jobs :
2021 review :
2122 environment : dev
2223 runs-on : ubuntu-latest
24+ # Only run if the comment contains "/ai-review" or if it's a PR review comment
25+ if : |
26+ (github.event_name == 'issue_comment' &&
27+ github.event.issue.pull_request &&
28+ contains(github.event.comment.body, '/ai-review')) ||
29+ github.event_name == 'pull_request_review_comment'
2330 steps :
31+ - name : Get PR details
32+ id : pr
33+ uses : actions/github-script@v8
34+ with :
35+ script : |
36+ let pr;
37+ if (context.eventName === 'issue_comment') {
38+ // Get PR from issue comment
39+ const issue = await github.rest.issues.get({
40+ owner: context.repo.owner,
41+ repo: context.repo.repo,
42+ issue_number: context.issue.number,
43+ });
44+ pr = await github.rest.pulls.get({
45+ owner: context.repo.owner,
46+ repo: context.repo.repo,
47+ pull_number: context.issue.number,
48+ });
49+ } else {
50+ // Get PR from review comment
51+ pr = await github.rest.pulls.get({
52+ owner: context.repo.owner,
53+ repo: context.repo.repo,
54+ pull_number: context.payload.pull_request.number,
55+ });
56+ }
57+ core.setOutput('number', pr.data.number);
58+ core.setOutput('head_sha', pr.data.head.sha);
59+
60+ - name : Clean up old AI review comments
61+ uses : actions/github-script@v8
62+ with :
63+ script : |
64+ // Get all PR comments
65+ const comments = await github.rest.issues.listComments({
66+ owner: context.repo.owner,
67+ repo: context.repo.repo,
68+ issue_number: ${{ steps.pr.outputs.number }},
69+ });
70+
71+ // Delete ALL comments from bots
72+ const botComments = comments.data.filter(comment =>
73+ comment.user.type === 'Bot' || comment.user.login.includes('[bot]')
74+ );
75+
76+ console.log(`Found ${botComments.length} bot comments to delete`);
77+
78+ for (const comment of botComments) {
79+ try {
80+ await github.rest.issues.deleteComment({
81+ owner: context.repo.owner,
82+ repo: context.repo.repo,
83+ comment_id: comment.id,
84+ });
85+ console.log(`Deleted comment ${comment.id} by ${comment.user.login}`);
86+ } catch (error) {
87+ console.log(`Failed to delete comment ${comment.id}: ${error.message}`);
88+ }
89+ }
90+
91+ // Also clean up ALL bot review comments
92+ try {
93+ const reviewComments = await github.rest.pulls.listReviewComments({
94+ owner: context.repo.owner,
95+ repo: context.repo.repo,
96+ pull_number: ${{ steps.pr.outputs.number }},
97+ });
98+
99+ const botReviewComments = reviewComments.data.filter(comment =>
100+ comment.user.type === 'Bot' || comment.user.login.includes('[bot]')
101+ );
102+
103+ console.log(`Found ${botReviewComments.length} bot review comments to delete`);
104+
105+ for (const comment of botReviewComments) {
106+ try {
107+ await github.rest.pulls.deleteReviewComment({
108+ owner: context.repo.owner,
109+ repo: context.repo.repo,
110+ comment_id: comment.id,
111+ });
112+ console.log(`Deleted review comment ${comment.id} by ${comment.user.login}`);
113+ } catch (error) {
114+ console.log(`Failed to delete review comment ${comment.id}: ${error.message}`);
115+ }
116+ }
117+ } catch (error) {
118+ console.log(`Error cleaning up review comments: ${error.message}`);
119+ }
120+
121+ - name : React to trigger comment
122+ if : github.event_name == 'issue_comment'
123+ uses : actions/github-script@v8
124+ with :
125+ script : |
126+ await github.rest.reactions.createForIssueComment({
127+ owner: context.repo.owner,
128+ repo: context.repo.repo,
129+ comment_id: context.payload.comment.id,
130+ content: 'eyes'
131+ });
132+
24133 - name : Configure AWS Credentials
25- uses : aws-actions/configure-aws-credentials@v4
134+ uses : aws-actions/configure-aws-credentials@v5
26135 with :
27136 aws-region : ${{ vars.AWS_REGION }}
28137 role-to-assume : arn:aws:iam::${{ vars.AWS_ACCOUNT }}:role/${{ vars.ROLE_NAME_TO_ASSUME }}
0 commit comments