|
| 1 | +name: "/git command" |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [ jira-command ] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.event.client_payload.github.payload.issue.number }}-${{ github.event.client_payload.slash_command.command }}-${{ github.event.client_payload.slash_command.args.unnamed.arg1 || github.event.client_payload.slash_command.args.all }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + create: |
| 12 | + if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'create' }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 3 |
| 15 | + steps: |
| 16 | + |
| 17 | + |
| 18 | + - name: Check user's membership |
| 19 | + uses: actions/github-script@v7 |
| 20 | + id: check-membership |
| 21 | + env: |
| 22 | + ACTOR: ${{ github.actor }} |
| 23 | + with: |
| 24 | + github-token: ${{ secrets.GIT_PAT }} |
| 25 | + script: | |
| 26 | + const { repo, owner } = context.repo; |
| 27 | + const actor = process.env.ACTOR; |
| 28 | + const { data: membership } = await github.rest.orgs.getMembershipForUser({ |
| 29 | + org: owner, |
| 30 | + username: actor, |
| 31 | + }); |
| 32 | + if (membership.state != "active") { |
| 33 | + const error = `Unfortunately you don't have membership in ${owner} organization, Jira Issue was not created`; |
| 34 | + core.setOutput("error", error); |
| 35 | + core.setFailed(error); |
| 36 | + } |
| 37 | +
|
| 38 | + - name: Checkout Actions Hub |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + token: ${{ secrets.GIT_PAT }} |
| 42 | + repository: HumanSignal/actions-hub |
| 43 | + path: ./.github/actions-hub |
| 44 | + |
| 45 | + - name: Jira Create Issue |
| 46 | + id: jira-create-issue |
| 47 | + uses: ./.github/actions-hub/actions/jira-create-issue |
| 48 | + with: |
| 49 | + jira_server: ${{ vars.JIRA_SERVER }} |
| 50 | + jira_username: ${{ secrets.JIRA_USERNAME }} |
| 51 | + jira_token: ${{ secrets.JIRA_TOKEN }} |
| 52 | + summary: ${{ github.event.client_payload.github.payload.issue.title }} |
| 53 | + description: ${{ github.event.client_payload.github.payload.issue.body }} |
| 54 | + project: ${{ github.event.client_payload.slash_command.args.unnamed.arg3 || 'TRIAG' }} |
| 55 | + type: ${{ github.event.client_payload.slash_command.args.unnamed.arg2 || 'task' }} |
| 56 | + |
| 57 | + - name: Add reaction to command comment on success |
| 58 | + uses: peter-evans/create-or-update-comment@v3 |
| 59 | + with: |
| 60 | + token: ${{ secrets.GIT_PAT }} |
| 61 | + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} |
| 62 | + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} |
| 63 | + body: | |
| 64 | + > Jira issue [${{ steps.jira-create-issue.outputs.key }}](${{ steps.jira-create-issue.outputs.link }}) is created |
| 65 | + > |
| 66 | + > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 67 | + reactions: "+1" |
| 68 | + |
| 69 | + - name: Add reaction to command comment on failure |
| 70 | + uses: peter-evans/create-or-update-comment@v3 |
| 71 | + if: failure() |
| 72 | + with: |
| 73 | + token: ${{ secrets.GIT_PAT }} |
| 74 | + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} |
| 75 | + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} |
| 76 | + body: | |
| 77 | + > **Error**: failed to execute "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" command |
| 78 | + > ${{ steps.check-membership.outputs.error }} |
| 79 | + > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 80 | + reactions: "-1" |
| 81 | + |
| 82 | + help: |
| 83 | + if: github.event.client_payload.slash_command.args.unnamed.arg1 == 'help' || !contains(fromJson('["create"]'), github.event.client_payload.slash_command.args.unnamed.arg1) |
| 84 | + runs-on: ubuntu-latest |
| 85 | + timeout-minutes: 1 |
| 86 | + steps: |
| 87 | + - name: Update comment |
| 88 | + uses: peter-evans/create-or-update-comment@v3 |
| 89 | + with: |
| 90 | + token: ${{ secrets.GIT_PAT }} |
| 91 | + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} |
| 92 | + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} |
| 93 | + body: | |
| 94 | + > Command | Description |
| 95 | + > --- | --- |
| 96 | + > /jira create [task|bug|story] `PROJECT` | Create a Jira issue in project `PROJECT` |
| 97 | + reaction-type: hooray |
0 commit comments