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

Commit c4a5ce5

Browse files
authored
JIRA GHA Integration (#165)
* JIRA GHA Integration * fix format
1 parent 02fa2cf commit c4a5ce5

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

.github/workflows/jira-issues.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright (c) HashiCorp, Inc.
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
on:
5+
issues:
6+
types: [opened, closed, deleted, reopened, edited]
7+
issue_comment:
8+
types: [created]
9+
workflow_dispatch:
10+
11+
name: Jira Community Issue Sync
12+
13+
jobs:
14+
sync:
15+
runs-on: ubuntu-latest
16+
name: Jira Community Issue sync
17+
steps:
18+
- name: Login
19+
uses: atlassian/gajira-login@ca13f8850ea309cf44a6e4e0c49d9aa48ac3ca4c # v3
20+
env:
21+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
22+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
23+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
24+
25+
- name: Set ticket type
26+
id: set-ticket-type
27+
run: |
28+
echo "TYPE=GH Issue" >> $GITHUB_OUTPUT
29+
30+
- name: Set ticket labels
31+
if: github.event.action == 'opened'
32+
id: set-ticket-labels
33+
run: |
34+
LABELS="[\"${{github.event.repository.name}}\", "
35+
if [[ "${{ contains(github.event.issue.labels.*.name, 'bug') }}" == "true" ]]; then LABELS+="\"bug\", "; fi
36+
if [[ "${{ contains(github.event.issue.labels.*.name, 'enhancement') }}" == "true" ]]; then LABELS+="\"enhancement\", "; fi
37+
if [[ "${{ contains(github.event.issue.labels.*.name, 'documentation') }}" == "true" ]]; then LABELS+="\"documentation\", "; fi
38+
if [[ "${{ contains(github.event.issue.labels.*.name, 'needs-investigation') }}" == "true" ]]; then LABELS+="\"needs-investigation\", "; fi
39+
if [[ "${{ contains(github.event.issue.labels.*.name, 'question') }}" == "true" ]]; then LABELS+="\"question\", "; fi
40+
if [[ "${{ contains(github.event.issue.labels.*.name, 'size/XS') }}" == "true" ]]; then LABELS+="\"size/XS\", "; fi
41+
if [[ "${{ contains(github.event.issue.labels.*.name, 'size/S') }}" == "true" ]]; then LABELS+="\"size/S\", "; fi
42+
if [[ "${{ contains(github.event.issue.labels.*.name, 'size/M') }}" == "true" ]]; then LABELS+="\"size/M\", "; fi
43+
if [[ "${{ contains(github.event.issue.labels.*.name, 'size/L') }}" == "true" ]]; then LABELS+="\"size/L\", "; fi
44+
if [[ "${{ contains(github.event.issue.labels.*.name, 'size/XL') }}" == "true" ]]; then LABELS+="\"size/XL\", "; fi
45+
if [[ "${{ contains(github.event.issue.labels.*.name, 'size/XXL') }}" == "true" ]]; then LABELS+="\"size/XXL\", "; fi
46+
if [[ "${{ contains(github.event.issue.labels.*.name, 'acknowledged') }}" == "true" ]]; then LABELS+="\"acknowledged\", "; fi
47+
if [[ "${{ contains(github.event.issue.labels.*.name, 'help wanted') }}" == "true" ]]; then LABELS+="\"help wanted\", "; fi
48+
if [[ "${{ contains(github.event.issue.labels.*.name, 'upstream-helm') }}" == "true" ]]; then LABELS+="\"upstream-helm\", "; fi
49+
if [[ "${{ contains(github.event.issue.labels.*.name, 'upstream-terraform') }}" == "true" ]]; then LABELS+="\"upstream-terraform\", "; fi
50+
if [[ "${{ contains(github.event.issue.labels.*.name, 'progressive apply') }}" == "true" ]]; then LABELS+="\"progressive apply\", "; fi
51+
if [[ "${{ contains(github.event.issue.labels.*.name, 'pr/changelog') }}" == "true" ]]; then LABELS+="\"pr/changelog\", "; fi
52+
if [[ "${{ contains(github.event.issue.labels.*.name, 'crash') }}" == "true" ]]; then LABELS+="\"crash\", "; fi
53+
if [[ "${{ contains(github.event.issue.labels.*.name, 'breaking-change') }}" == "true" ]]; then LABELS+="\"breaking-change\", "; fi
54+
if [[ "${{ contains(github.event.issue.labels.*.name, 'provider') }}" == "true" ]]; then LABELS+="\"provider\", "; fi
55+
if [[ "${{ contains(github.event.issue.labels.*.name, 'stale') }}" == "true" ]]; then LABELS+="\"stale\", "; fi
56+
if [[ ${#LABELS} != 1 ]]; then LABELS=${LABELS::-2}"]"; else LABELS+="]"; fi
57+
echo "LABELS=${LABELS}" >> $GITHUB_OUTPUT
58+
59+
- name: Create ticket if an issue is filed, or if PR not by a team member is opened
60+
if: github.event.action == 'opened'
61+
uses: tomhjp/gh-action-jira-create@3ed1789cad3521292e591a7cfa703215ec1348bf # v0.2.1
62+
with:
63+
project: TFECO
64+
issuetype: "${{ steps.set-ticket-type.outputs.TYPE }}"
65+
summary: "${{ github.event.issue.title }}:[Issue-${{ github.event.issue.number }}] (${{ github.event.repository.name }})"
66+
description: "${{ github.event.issue.body || github.event.pull_request.body }}\n\n_Created in GitHub by ${{ github.actor }}._\n\n${{ github.event.issue.html_url || github.event.pull_request.html_url }}"
67+
# customfield_10089 is "Issue Link", customfield_10371 is "Source" (use JIRA API to retrieve)
68+
extraFields: '{ "customfield_10089": "${{ github.event.issue.html_url || github.event.pull_request.html_url }}",
69+
"customfield_10371": { "value": "GitHub" },
70+
"customfield_10091": ["TF-HybridCloud"],
71+
"labels": ${{ steps.set-ticket-labels.outputs.LABELS }} }'
72+
env:
73+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
74+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
75+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
76+
77+
- name: Search
78+
if: github.event.action != 'opened'
79+
id: search
80+
uses: tomhjp/gh-action-jira-search@04700b457f317c3e341ce90da5a3ff4ce058f2fa # v0.2.2
81+
with:
82+
# cf[10089] is Issue Link (use JIRA API to retrieve)
83+
jql: 'issuetype = "${{ steps.set-ticket-type.outputs.TYPE }}" and cf[10089] = "${{ github.event.issue.html_url || github.event.pull_request.html_url }}"'
84+
85+
- name: Sync comment
86+
if: github.event.action == 'created' && steps.search.outputs.issue
87+
uses: tomhjp/gh-action-jira-comment@6eb6b9ead70221916b6badd118c24535ed220bd9 # v0.2.0
88+
with:
89+
issue: ${{ steps.search.outputs.issue }}
90+
comment: "${{ github.actor }} ${{ github.event.review.state || 'commented' }}:\n\n${{ github.event.comment.body || github.event.review.body }}\n\n${{ github.event.comment.html_url || github.event.review.html_url }}"
91+
92+
- name: Close ticket
93+
if: ( github.event.action == 'closed' || github.event.action == 'deleted' ) && steps.search.outputs.issue
94+
uses: atlassian/gajira-transition@38fc9cd61b03d6a53dd35fcccda172fe04b36de3 # v3
95+
with:
96+
issue: ${{ steps.search.outputs.issue }}
97+
transition: "Closed"
98+
99+
- name: Reopen ticket
100+
if: github.event.action == 'reopened' && steps.search.outputs.issue
101+
uses: atlassian/gajira-transition@38fc9cd61b03d6a53dd35fcccda172fe04b36de3 # v3
102+
with:
103+
issue: ${{ steps.search.outputs.issue }}
104+
transition: "To Do"

.github/workflows/jira.pr.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright (c) HashiCorp, Inc.
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
on:
5+
pull_request_target:
6+
types: [opened, closed, reopened, edited]
7+
workflow_dispatch:
8+
9+
name: Jira Community PR Sync
10+
11+
jobs:
12+
sync:
13+
runs-on: ubuntu-latest
14+
name: Jira sync
15+
steps:
16+
- name: Login
17+
uses: atlassian/gajira-login@ca13f8850ea309cf44a6e4e0c49d9aa48ac3ca4c # v3
18+
env:
19+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
20+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
21+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
22+
23+
- name: Set ticket type
24+
id: set-ticket-type
25+
run: |
26+
echo "TYPE=GH Issue" >> $GITHUB_OUTPUT
27+
28+
- name: Set ticket labels
29+
if: github.event.action == 'opened'
30+
id: set-ticket-labels
31+
run: |
32+
LABELS="[\"${{github.event.repository.name}}\", "
33+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'bug') }}" == "true" ]]; then LABELS+="\"bug\", "; fi
34+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'enhancement') }}" == "true" ]]; then LABELS+="\"enhancement\", "; fi
35+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'documentation') }}" == "true" ]]; then LABELS+="\"documentation\", "; fi
36+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'needs-investigation') }}" == "true" ]]; then LABELS+="\"needs-investigation\", "; fi
37+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'question') }}" == "true" ]]; then LABELS+="\"question\", "; fi
38+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'size/XS') }}" == "true" ]]; then LABELS+="\"size/XS\", "; fi
39+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'size/S') }}" == "true" ]]; then LABELS+="\"size/S\", "; fi
40+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'size/M') }}" == "true" ]]; then LABELS+="\"size/M\", "; fi
41+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'size/L') }}" == "true" ]]; then LABELS+="\"size/L\", "; fi
42+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'size/XL') }}" == "true" ]]; then LABELS+="\"size/XL\", "; fi
43+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'size/XXL') }}" == "true" ]]; then LABELS+="\"size/XXL\", "; fi
44+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'acknowledged') }}" == "true" ]]; then LABELS+="\"acknowledged\", "; fi
45+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'help wanted') }}" == "true" ]]; then LABELS+="\"help wanted\", "; fi
46+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'dependencies') }}" == "true" ]]; then LABELS+="\"dependencies\", "; fi
47+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'upstream-tfc') }}" == "true" ]]; then LABELS+="\"upstream-tfc\", "; fi
48+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'go') }}" == "true" ]]; then LABELS+="\"go\", "; fi
49+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'progressive apply') }}" == "true" ]]; then LABELS+="\"progressive apply\", "; fi
50+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'pr/changelog') }}" == "true" ]]; then LABELS+="\"pr/changelog\", "; fi
51+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'crash') }}" == "true" ]]; then LABELS+="\"crash\", "; fi
52+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'breaking-change') }}" == "true" ]]; then LABELS+="\"breaking-change\", "; fi
53+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'provider') }}" == "true" ]]; then LABELS+="\"provider\", "; fi
54+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'stale') }}" == "true" ]]; then LABELS+="\"stale\", "; fi
55+
if [[ ${#LABELS} != 1 ]]; then LABELS=${LABELS::-2}"]"; else LABELS+="]"; fi
56+
echo "LABELS=${LABELS}" >> $GITHUB_OUTPUT
57+
58+
- name: Create ticket if a PR is opened
59+
if: ( github.event.action == 'opened')
60+
uses: tomhjp/gh-action-jira-create@3ed1789cad3521292e591a7cfa703215ec1348bf # v0.2.1
61+
with:
62+
project: TFECO
63+
issuetype: "${{ steps.set-ticket-type.outputs.TYPE }}"
64+
summary: "${{ github.event.pull_request.title }}:[PR-${{ github.event.pull_request.number }}] (${{ github.event.repository.name }})"
65+
description: "${{ github.event.issue.body || github.event.pull_request.body }}\n\n_Created in GitHub by ${{ github.actor }}._\n\n${{ github.event.pull_request.html_url }}"
66+
# customfield_10089 is "Issue Link", customfield_10371 is "Source" (use JIRA API to retrieve)
67+
extraFields: '{ "customfield_10089": "${{ github.event.pull_request.html_url }}",
68+
"customfield_10371": { "value": "GitHub" },
69+
"customfield_10091": ["TF-HybridCloud"],
70+
"labels": ${{ steps.set-ticket-labels.outputs.LABELS }} }'
71+
env:
72+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
73+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
74+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
75+
76+
- name: Search
77+
if: github.event.action != 'opened'
78+
id: search
79+
uses: tomhjp/gh-action-jira-search@04700b457f317c3e341ce90da5a3ff4ce058f2fa # v0.2.2
80+
with:
81+
# cf[10089] is Issue Link (use JIRA API to retrieve)
82+
jql: 'issuetype = "${{ steps.set-ticket-type.outputs.TYPE }}" and cf[10089] = "${{ github.event.issue.html_url || github.event.pull_request.html_url }}"'
83+
84+
- name: Sync comment
85+
if: github.event.action == 'created' && steps.search.outputs.issue
86+
uses: tomhjp/gh-action-jira-comment@6eb6b9ead70221916b6badd118c24535ed220bd9 # v0.2.0
87+
with:
88+
issue: ${{ steps.search.outputs.issue }}
89+
comment: "${{ github.actor }} ${{ github.event.review.state || 'commented' }}:\n\n${{ github.event.comment.body || github.event.review.body }}\n\n${{ github.event.comment.html_url || github.event.review.html_url }}"
90+
91+
- name: Close PR
92+
if: ( github.event.action == 'closed' || github.event.action == 'deleted' || github.event.pull_request.merged == true) && steps.search.outputs.issue
93+
uses: atlassian/gajira-transition@38fc9cd61b03d6a53dd35fcccda172fe04b36de3 # v3
94+
with:
95+
issue: ${{ steps.search.outputs.issue }}
96+
transition: "Closed"
97+
98+
- name: Reopen PR
99+
if: github.event.action == 'reopened' && steps.search.outputs.issue
100+
uses: atlassian/gajira-transition@38fc9cd61b03d6a53dd35fcccda172fe04b36de3 # v3
101+
with:
102+
issue: ${{ steps.search.outputs.issue }}
103+
transition: "To Do"

0 commit comments

Comments
 (0)