Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit e02f9f5

Browse files
ci: PLATE-675: Add /jira chatops command (#275)
1 parent f7e188d commit e02f9f5

File tree

2 files changed

+101
-3
lines changed

2 files changed

+101
-3
lines changed

.github/workflows/jira-command.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
- uses: hmarr/[email protected]
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

.github/workflows/slash-command-dispatch.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "/Slash Command Dispatch"
1+
name: Slash Command Dispatch
22
on:
33
issue_comment:
44
types: [created]
@@ -7,6 +7,7 @@ env:
77
commands_list: |
88
help
99
git
10+
jira
1011
1112
jobs:
1213
slashCommandDispatch:
@@ -39,7 +40,7 @@ jobs:
3940
4041
- name: Slash Command Dispatch
4142
id: scd
42-
if: steps.determine_command.outputs.command_state != 'unknown'
43+
if: ${{ steps.determine_command.outputs.command_state != 'unknown' }}
4344
uses: peter-evans/slash-command-dispatch@v3
4445
with:
4546
token: ${{ secrets.GIT_PAT }}
@@ -48,7 +49,7 @@ jobs:
4849
commands: ${{ env.commands_list }}
4950

5051
- name: Edit comment with error message
51-
if: steps.determine_command.outputs.command_state == 'unknown'
52+
if: ${{ steps.determine_command.outputs.command_state == 'unknown' }}
5253
uses: peter-evans/create-or-update-comment@v3
5354
with:
5455
comment-id: ${{ github.event.comment.id }}

0 commit comments

Comments
 (0)