|
| 1 | +# This action is centrally managed in https://github.com/asyncapi/.github/ |
| 2 | +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo |
| 3 | + |
| 4 | +# It uses Github actions to listen for comments on issues and pull requests and |
| 5 | +# if the comment contains /ping-for-attention or /pfa it will add a comment pinging |
| 6 | +# the code-owners who have not yet reviewed the pull request |
| 7 | + |
| 8 | +name: Please take a Look |
| 9 | + |
| 10 | +on: |
| 11 | + issue_comment: |
| 12 | + types: [created] |
| 13 | + |
| 14 | +jobs: |
| 15 | + ping-for-attention: |
| 16 | + if: > |
| 17 | + github.event.issue.pull_request && |
| 18 | + github.event.issue.state != 'closed' && |
| 19 | + github.actor != 'asyncapi-bot' && |
| 20 | + ( |
| 21 | + contains(github.event.comment.body, '/please-take-a-look') || |
| 22 | + contains(github.event.comment.body, '/ptal') || |
| 23 | + contains(github.event.comment.body, '/PTAL') |
| 24 | + ) |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Check for Please Take a Look Command |
| 28 | + uses: actions/github-script@v6 |
| 29 | + with: |
| 30 | + github-token: ${{ secrets.GH_TOKEN }} |
| 31 | + script: | |
| 32 | + const prDetailsUrl = context.payload.issue.pull_request.url; |
| 33 | + const { data: pull } = await github.request(prDetailsUrl); |
| 34 | + const reviewers = pull.requested_reviewers.map(reviewer => reviewer.login); |
| 35 | +
|
| 36 | + const { data: reviews } = await github.rest.pulls.listReviews({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + pull_number: context.issue.number |
| 40 | + }); |
| 41 | +
|
| 42 | + const reviewersWhoHaveReviewed = reviews.map(review => review.user.login); |
| 43 | +
|
| 44 | + const reviewersWhoHaveNotReviewed = reviewers.filter(reviewer => !reviewersWhoHaveReviewed.includes(reviewer)); |
| 45 | +
|
| 46 | + if (reviewersWhoHaveNotReviewed.length > 0) { |
| 47 | + const comment = reviewersWhoHaveNotReviewed.map(reviewer => `@${reviewer}`).join(' '); |
| 48 | + await github.rest.issues.createComment({ |
| 49 | + issue_number: context.issue.number, |
| 50 | + owner: context.repo.owner, |
| 51 | + repo: context.repo.repo, |
| 52 | + body: `${comment} Please take a look at this PR. Thanks! :wave:` |
| 53 | + }); |
| 54 | + } |
0 commit comments