-
Notifications
You must be signed in to change notification settings - Fork 1
173 lines (156 loc) · 6.96 KB
/
issues.yml
File metadata and controls
173 lines (156 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
name: JIRA Tickets for GH Issues
on:
issues:
types: [opened, reopened, closed]
jobs:
jira_task:
name: Create Jira issue
if: github.event.action == 'opened'
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.APIX_BOT_PAT }}
steps:
- name: Create JIRA ticket
id: create
shell: bash
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_URL: ${{ github.event.issue.html_url }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_ASSIGNEE: ${{ secrets.ASSIGNEE_JIRA_TICKET }}
run: |
json_response=$(curl --request POST \
--url 'https://jira.mongodb.org/rest/api/2/issue' \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"fields": {
"project": {
"id": "10984"
},
"summary": "TF plugin HELP: GitHub Issue n. '"${ISSUE_NUMBER}"'",
"issuetype": {
"id": "12"
},
"customfield_12751": [{
"id": "25550"
}],
"description": "This ticket tracks the following GitHub issue: '"${ISSUE_URL}"'.",
"components": [
{
"id": "34035"
}
]
}
}')
echo "Response: ${json_response}"
JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.key')
echo "The following JIRA ticket has been created: ${JIRA_TICKET_ID}"
echo "jira-ticket-id=${JIRA_TICKET_ID}" >> "${GITHUB_OUTPUT}"
- name: Add comment
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9
with:
issue-number: ${{ github.event.issue.number }}
body: |
Thanks for opening this issue! Please make sure you've followed [our guidelines](https://github.com/mongodb/terraform-provider-mongodbatlas/issues/new?assignees=&labels=&projects=&template=Bug_Report.md) when opening the issue. In short, to help us reproduce the issue we need:
- Terraform configuration file used to reproduce the issue
- Terraform log files from the run where the issue occurred
- Terraform Atlas provider version used to reproduce the issue
- Terraform version used to reproduce the issue
- Confirmation if Terraform OSS, Terraform Cloud, or Terraform Enterprise deployment
The ticket [${{ steps.create.outputs.jira-ticket-id }}](https://jira.mongodb.org/browse/${{ steps.create.outputs.jira-ticket-id }}) was created for internal tracking.
reopen_jira_ticket:
name: Reopen JIRA ticket
if: github.event.action == 'reopened'
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.APIX_BOT_PAT }}
steps:
- name: Reopened JIRA ticket if exists
run: |
ISSUE_NUMBER=${{ github.event.issue.number }}
JIRA_API_TOKEN=${{ secrets.JIRA_API_TOKEN }}
JIRA_QUERY="project = CLOUDP AND issuetype = Story AND resolution = Declined AND text ~ \"TF plugin HELP: GitHub Issue n. $ISSUE_NUMBER\""
# URL encode the query
JIRA_URL=$(echo "$JIRA_QUERY" | jq -s -R -r @uri)
json_response=$(curl -s --request GET \
--url "https://jira.mongodb.org/rest/api/2/search?fields=id&jql=${JIRA_URL}" \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
--header 'Accept: application/json')
JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.issues[0].id')
if [ -z "$JIRA_TICKET_ID" ]; then
echo "JIRA_TICKET_ID is not defined. Exiting the script."
exit 1
fi
JIRA_REOPENED_URL="https://jira.mongodb.org/rest/api/2/issue/${JIRA_TICKET_ID}/transitions"
json_response=$(curl -s --request POST \
--url "${JIRA_REOPENED_URL}" \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"transition": {
"id": 3
},
"update": {
"comment": [
{
"add": {
"body": "The related GitHub issue was reopened. Updated via automated process."
}
}
]
}
}')
echo "Response: ${json_response}"
close_jira_ticket:
name: Close JIRA ticket
if: github.event.action == 'closed'
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.APIX_BOT_PAT }}
steps:
- name: Close JIRA ticket if exists
run: |
ISSUE_NUMBER=${{ github.event.issue.number }}
JIRA_API_TOKEN=${{ secrets.JIRA_API_TOKEN }}
JIRA_QUERY="project = CLOUDP AND issuetype = Story AND resolution = Unresolved AND text ~ \"TF plugin HELP: GitHub Issue n. $ISSUE_NUMBER\""
# URL encode the query
JIRA_URL=$(echo "$JIRA_QUERY" | jq -s -R -r @uri)
json_response=$(curl -s --request GET \
--url "https://jira.mongodb.org/rest/api/2/search?fields=id&jql=${JIRA_URL}" \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
--header 'Accept: application/json')
JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.issues[0].id')
if [ -z "$JIRA_TICKET_ID" ]; then
echo "JIRA_TICKET_ID is not defined. Exiting the script."
exit 1
fi
JIRA_CLOSE_URL="https://jira.mongodb.org/rest/api/2/issue/${JIRA_TICKET_ID}/transitions"
json_response=$(curl -s --request POST \
--url "${JIRA_CLOSE_URL}" \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"transition": {
"id": 1371
},
"update": {
"comment": [
{
"add": {
"body": "The related GitHub issue was closed. Resolved via automated process."
}
}
]
},
"fields": {
"resolution": {
"name": "Declined"
}
}
}')
echo "Response: ${json_response}"