💬 Comment on the pull request #1800
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: 💬 Comment on the pull request | |
| on: | |
| workflow_run: | |
| workflows: | |
| - 📝 Check Conventional Commit | |
| - ✨ Check Conventional Commit Title | |
| - 🧪 Test | |
| types: | |
| - completed | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| comment: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: 📥 Download artifact | |
| uses: actions/download-artifact@v6 | |
| with: | |
| github-token: ${{ github.token }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: ⚙️ Setup Environment | |
| run: | | |
| echo "PR_NUMBER=$(cat pr_number/pr_number.txt | tr -cd '0-9')" >> $GITHUB_ENV | |
| echo "TITLE=$(cat title/title.txt | tr -d '\n')" >> $GITHUB_ENV | |
| UUID=$(uuidgen) | |
| { | |
| echo "COMMENT<<EOF_$UUID" | |
| cat comment/comment.txt | |
| echo "EOF_$UUID" | |
| } >> "$GITHUB_ENV" | |
| - name: 💬 Add a comment | |
| uses: actions/github-script@v8 | |
| env: | |
| CONCLUSION: ${{ github.event.workflow_run.conclusion }} | |
| with: | |
| script: | | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: process.env.PR_NUMBER, | |
| }) | |
| const oldComment = comments.find(comment => { | |
| return comment.user.type === 'Bot' && comment.body.includes(process.env.TITLE) | |
| }) | |
| if (oldComment) { | |
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: oldComment.id, | |
| }) | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: process.env.PR_NUMBER, | |
| body: process.env.COMMENT | |
| }) | |
| return | |
| } | |
| if (process.env.CONCLUSION === 'failure') { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: process.env.PR_NUMBER, | |
| body: process.env.COMMENT | |
| }) | |
| } |