Refactor issue acknowledgment workflow #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Acknowledge GH Issues | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| permissions: | ||
| issues: read | ||
| issues: write | ||
| jobs: | ||
| acknowledge: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: read | ||
| steps: | ||
| - name: Wait 15 minutes | ||
| run: sleep 30 | ||
| - name: Check for existing maintainer response | ||
| id: check | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const maintainers = ['sumitmsft']; | ||
| const issueNumber = context.payload.inputs?.issue_number | ||
| ? parseInt(context.payload.inputs.issue_number) | ||
| : context.payload.issue.number; | ||
| const comments = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber | ||
| }); | ||
| const maintainerReplied = comments.data.some( | ||
| comment => maintainers.includes(comment.user.login) | ||
| ); | ||
| core.setOutput('skip', maintainerReplied.toString()); | ||
| core.setOutput('issue_number', issueNumber.toString()); | ||
| console.log(`Maintainer already replied: ${maintainerReplied}`); | ||
| # Generate a short-lived token from the GitHub App | ||
| - name: Generate App Token | ||
| if: steps.check.outputs.skip == 'false' | ||
| id: app-token | ||
| uses: actions/create-github-app-token@v1 | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
| - name: Post acknowledgement comment | ||
| if: steps.check.outputs.skip == 'false' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ steps.app-token.outputs.token }} | ||
| script: | | ||
| const issueNumber = parseInt('${{ steps.check.outputs.issue_number }}'); | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| body: `Hi @${context.payload.issue?.user?.login || 'there'}, thank you for opening this issue!\n\nOur team will review it shortly. We aim to triage all new issues within 24-48 hours.\n\nThank you for your patience!` | ||
| }); | ||