Tiny to iframe #82
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: Notice about review approved via Matrix | |
| on: | |
| pull_request_review: | |
| types: [ submitted ] | |
| jobs: | |
| build: | |
| if: github.event.review.state == 'approved' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Count approvals and check conditions | |
| id: check | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request; | |
| const { data: reviews } = await github.rest.pulls.listReviews({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr.number | |
| }); | |
| const approvers = new Set(); | |
| reviews.forEach(r => r.state === 'APPROVED' && r.user.login !== pr.user.login && approvers.add(r.user.login)); | |
| // Main condition to skip the JOB | |
| const shouldRun = pr.requested_reviewers.length === 0 || approvers.size >= 2; | |
| console.log(`Should run: ${shouldRun} (approvers: ${approvers.size}, requested: ${pr.requested_reviewers.length})`); | |
| return shouldRun ? 'true' : 'false'; | |
| result-encoding: string | |
| - name: Exit if conditions not met | |
| if: steps.check.outputs.result == 'false' | |
| run: exit 0 | |
| - name: Convert date format | |
| id: date | |
| run: echo "date=$(date -d "${{ github.event.pull_request.created_at }}" +"%Y-%m-%d")" | |
| - name: Send Matrix message on review approved | |
| uses: Glomberg/matrix-messenger-action@master | |
| with: | |
| server: ${{ secrets.MATRIX_SERVER }} | |
| to: ${{ secrets.MATRIX_SPOTFIX_ROOM }} | |
| token: ${{ secrets.MATRIX_USER_TOKEN }} | |
| message: | | |
| 💥🎉🎉🎉💥 Pull-request <a href="${{ github.event.pull_request.html_url }}"><strong>${{ github.event.pull_request.title }}</strong></a> | |
| submitted by <strong>${{ github.event.pull_request.user.login }}</strong> at <strong>${{ steps.date.outputs.date }}</strong> | |
| was <strong>approved</strong> and is ready to merge <a href="${{ github.event.pull_request.html_url }}">➡️</a> !!! |