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