|
35 | 35 | permissions: |
36 | 36 | actions: read |
37 | 37 | contents: read |
38 | | - issues: write |
39 | | - pull-requests: write |
| 38 | + pull-requests: read |
40 | 39 |
|
41 | 40 | env: |
42 | 41 | FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" |
|
99 | 98 | crabbox_provider: ${{ steps.resolve.outputs.crabbox_provider }} |
100 | 99 | lease_id: ${{ steps.resolve.outputs.lease_id }} |
101 | 100 | pr_number: ${{ steps.resolve.outputs.pr_number }} |
| 101 | + reaction_id: ${{ steps.add_reaction.outputs.reaction_id }} |
102 | 102 | request_source: ${{ steps.resolve.outputs.request_source }} |
103 | 103 | scenario: ${{ steps.resolve.outputs.scenario }} |
104 | 104 | should_run: ${{ steps.resolve.outputs.should_run }} |
@@ -193,12 +193,35 @@ jobs: |
193 | 193 | setOutput("lease_id", leaseMatch?.[1] || ""); |
194 | 194 | setOutput("request_source", "issue_comment"); |
195 | 195 |
|
196 | | - await github.rest.reactions.createForIssueComment({ |
197 | | - owner, |
198 | | - repo, |
199 | | - comment_id: context.payload.comment.id, |
200 | | - content: "eyes", |
201 | | - }).catch((error) => core.warning(`Could not add eyes reaction: ${error.message}`)); |
| 196 | + - name: Create Mantis reaction GitHub App token |
| 197 | + id: mantis_reaction_token |
| 198 | + if: ${{ steps.resolve.outputs.request_source == 'issue_comment' }} |
| 199 | + continue-on-error: true |
| 200 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 |
| 201 | + with: |
| 202 | + app-id: ${{ secrets.MANTIS_GITHUB_APP_ID }} |
| 203 | + private-key: ${{ secrets.MANTIS_GITHUB_APP_PRIVATE_KEY }} |
| 204 | + owner: ${{ github.repository_owner }} |
| 205 | + repositories: ${{ github.event.repository.name }} |
| 206 | + permission-issues: write |
| 207 | + |
| 208 | + - name: Add Mantis eyes reaction |
| 209 | + id: add_reaction |
| 210 | + if: ${{ steps.resolve.outputs.request_source == 'issue_comment' && steps.mantis_reaction_token.outcome == 'success' }} |
| 211 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 |
| 212 | + with: |
| 213 | + github-token: ${{ steps.mantis_reaction_token.outputs.token }} |
| 214 | + script: | |
| 215 | + const { owner, repo } = context.repo; |
| 216 | + await github.rest.reactions |
| 217 | + .createForIssueComment({ |
| 218 | + owner, |
| 219 | + repo, |
| 220 | + comment_id: context.payload.comment.id, |
| 221 | + content: "eyes", |
| 222 | + }) |
| 223 | + .then(({ data: reaction }) => core.setOutput("reaction_id", String(reaction.id))) |
| 224 | + .catch((error) => core.warning(`Could not add eyes reaction: ${error.message}`)); |
202 | 225 |
|
203 | 226 | validate_ref: |
204 | 227 | name: Validate candidate ref |
@@ -566,40 +589,33 @@ jobs: |
566 | 589 | clear_issue_comment_reaction: |
567 | 590 | name: Clear Mantis command reaction |
568 | 591 | needs: [resolve_request, validate_ref, run_telegram_live] |
569 | | - if: ${{ always() && github.event_name == 'issue_comment' && needs.resolve_request.outputs.request_source == 'issue_comment' }} |
| 592 | + if: ${{ always() && github.event_name == 'issue_comment' && needs.resolve_request.outputs.request_source == 'issue_comment' && needs.resolve_request.outputs.reaction_id != '' }} |
570 | 593 | runs-on: ubuntu-24.04 |
571 | | - permissions: |
572 | | - issues: write |
| 594 | + permissions: {} |
573 | 595 | steps: |
574 | | - - name: Remove workflow eyes reaction |
| 596 | + - name: Create Mantis cleanup GitHub App token |
| 597 | + id: mantis_reaction_token |
| 598 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 |
| 599 | + with: |
| 600 | + app-id: ${{ secrets.MANTIS_GITHUB_APP_ID }} |
| 601 | + private-key: ${{ secrets.MANTIS_GITHUB_APP_PRIVATE_KEY }} |
| 602 | + owner: ${{ github.repository_owner }} |
| 603 | + repositories: ${{ github.event.repository.name }} |
| 604 | + permission-issues: write |
| 605 | + |
| 606 | + - name: Remove Mantis eyes reaction |
575 | 607 | uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 |
| 608 | + env: |
| 609 | + REACTION_ID: ${{ needs.resolve_request.outputs.reaction_id }} |
576 | 610 | with: |
| 611 | + github-token: ${{ steps.mantis_reaction_token.outputs.token }} |
577 | 612 | script: | |
578 | 613 | const { owner, repo } = context.repo; |
579 | | - const commentId = context.payload.comment?.id; |
580 | | - if (!commentId) { |
581 | | - core.info("No issue comment id found; skipping reaction cleanup."); |
582 | | - return; |
583 | | - } |
584 | | -
|
585 | | - const reactions = await github.paginate(github.rest.reactions.listForIssueComment, { |
| 614 | + const reactionId = Number(process.env.REACTION_ID); |
| 615 | + await github.rest.reactions.deleteForIssueComment({ |
586 | 616 | owner, |
587 | 617 | repo, |
588 | | - comment_id: commentId, |
589 | | - per_page: 100, |
| 618 | + comment_id: context.payload.comment.id, |
| 619 | + reaction_id: reactionId, |
590 | 620 | }); |
591 | | - const eyes = reactions.filter( |
592 | | - (reaction) => reaction.content === "eyes" && reaction.user?.login === "github-actions[bot]", |
593 | | - ); |
594 | | - for (const reaction of eyes) { |
595 | | - await github.rest.reactions.deleteForIssueComment({ |
596 | | - owner, |
597 | | - repo, |
598 | | - comment_id: commentId, |
599 | | - reaction_id: reaction.id, |
600 | | - }); |
601 | | - core.info(`Removed eyes reaction ${reaction.id} from comment ${commentId}.`); |
602 | | - } |
603 | | - if (eyes.length === 0) { |
604 | | - core.info(`No workflow eyes reaction found on comment ${commentId}.`); |
605 | | - } |
| 621 | + core.info(`Removed Mantis eyes reaction ${reactionId}.`); |
0 commit comments