|
| 1 | +# This workflow is centrally managed at https://github.com/asyncapi/.github/ |
| 2 | +# Don't make changes to this file in this repository, as they will be overwritten with |
| 3 | +# changes made to the same file in the abovementioned repository. |
| 4 | + |
| 5 | +# The purpose of this workflow is to allow Bounty Team members |
| 6 | +# (https://github.com/orgs/asyncapi/teams/bounty_team) to issue commands to the |
| 7 | +# organization's global AsyncAPI bot related to the Bounty Program, while at the |
| 8 | +# same time preventing unauthorized users from misusing them. |
| 9 | + |
| 10 | +name: Bounty Program commands |
| 11 | + |
| 12 | +on: |
| 13 | + issue_comment: |
| 14 | + types: |
| 15 | + - created |
| 16 | + |
| 17 | +jobs: |
| 18 | + guard-against-unauthorized-use: |
| 19 | + if: > |
| 20 | + github.actor != ('aeworxet' || 'thulieblack') && |
| 21 | + ( |
| 22 | + contains(github.event.comment.body, '/bounty' ) |
| 23 | + ) |
| 24 | +
|
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: ❌ @${{github.actor}} made an unauthorized attempt to use a Bounty Program's command |
| 29 | + uses: actions/github-script@v6 |
| 30 | + |
| 31 | + with: |
| 32 | + github-token: ${{ secrets.GH_TOKEN }} |
| 33 | + script: | |
| 34 | + const commentText = `❌ @${{github.actor}} is not authorized to use the Bounty Program's commands. |
| 35 | + These commands can only be used by members of the [Bounty Team](https://github.com/orgs/asyncapi/teams/bounty_team).`; |
| 36 | +
|
| 37 | + console.log(`❌ @${{github.actor}} made an unauthorized attempt to use a Bounty Program's command.`); |
| 38 | + github.rest.issues.createComment({ |
| 39 | + issue_number: context.issue.number, |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + body: commentText |
| 43 | + }) |
| 44 | +
|
| 45 | + add-label-bounty: |
| 46 | + if: > |
| 47 | + github.actor == ('aeworxet' || 'thulieblack') && |
| 48 | + ( |
| 49 | + contains(github.event.comment.body, '/bounty' ) |
| 50 | + ) |
| 51 | +
|
| 52 | + runs-on: ubuntu-latest |
| 53 | + env: |
| 54 | + BOUNTY_PROGRAM_LABELS_JSON: | |
| 55 | + [ |
| 56 | + {"name": "bounty", "color": "0e8a16", "description": "Participation in the Bounty Program"} |
| 57 | + ] |
| 58 | +
|
| 59 | + steps: |
| 60 | + - name: Add label `bounty` |
| 61 | + uses: actions/github-script@v6 |
| 62 | + |
| 63 | + with: |
| 64 | + github-token: ${{ secrets.GH_TOKEN }} |
| 65 | + script: | |
| 66 | + const BOUNTY_PROGRAM_LABELS = JSON.parse(process.env.BOUNTY_PROGRAM_LABELS_JSON); |
| 67 | + let LIST_OF_LABELS_FOR_REPO = await github.rest.issues.listLabelsForRepo({ |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + }); |
| 71 | + |
| 72 | + LIST_OF_LABELS_FOR_REPO = LIST_OF_LABELS_FOR_REPO.data.map(key => key.name); |
| 73 | +
|
| 74 | + if (!LIST_OF_LABELS_FOR_REPO.includes(BOUNTY_PROGRAM_LABELS[0].name)) { |
| 75 | + await github.rest.issues.createLabel({ |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + name: BOUNTY_PROGRAM_LABELS[0].name, |
| 79 | + color: BOUNTY_PROGRAM_LABELS[0].color, |
| 80 | + description: BOUNTY_PROGRAM_LABELS[0].description |
| 81 | + }); |
| 82 | + } |
| 83 | +
|
| 84 | + console.log('Adding label `bounty`...'); |
| 85 | + github.rest.issues.addLabels({ |
| 86 | + issue_number: context.issue.number, |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + labels: [BOUNTY_PROGRAM_LABELS[0].name] |
| 90 | + }) |
0 commit comments