|
3 | 3 |
|
4 | 4 | on:
|
5 | 5 | issues:
|
6 |
| - types: [opened] |
| 6 | + types: [opened, reopened, closed] |
7 | 7 | permissions:
|
8 | 8 | issues: write
|
9 | 9 | contents: read
|
10 | 10 | jobs:
|
11 | 11 | jira_task:
|
12 | 12 | name: Create Jira issue
|
| 13 | + if: github.event.action == 'opened' |
13 | 14 | runs-on: ubuntu-latest
|
14 | 15 | steps:
|
15 | 16 | - name: Create JIRA ticket
|
|
66 | 67 | - Confirmation if Terraform OSS, Terraform Cloud, or Terraform Enterprise deployment
|
67 | 68 |
|
68 | 69 | The ticket [${{ steps.create.outputs.jira-ticket-id }}](https://jira.mongodb.org/browse/${{ steps.create.outputs.jira-ticket-id }}) was created for internal tracking.
|
| 70 | + reopen_jira_ticket: |
| 71 | + name: Reopen JIRA ticket |
| 72 | + if: github.event.action == 'reopened' |
| 73 | + runs-on: ubuntu-latest |
| 74 | + steps: |
| 75 | + - name: Reopened JIRA ticket if exists |
| 76 | + run: | |
| 77 | + ISSUE_NUMBER=${{ github.event.issue.number }} |
| 78 | + JIRA_API_TOKEN=${{ secrets.JIRA_API_TOKEN }} |
| 79 | +
|
| 80 | + JIRA_QUERY="project = CLOUDP AND issuetype = Story AND resolution = Declined AND text ~ \"HELP: GitHub Issue n. $ISSUE_NUMBER\"" |
| 81 | + |
| 82 | + # URL encode the query |
| 83 | + JIRA_URL=$(echo "$JIRA_QUERY" | jq -s -R -r @uri) |
| 84 | +
|
| 85 | + json_response=$(curl -s --request GET \ |
| 86 | + --url "https://jira.mongodb.org/rest/api/2/search?fields=id&jql=${JIRA_URL}" \ |
| 87 | + --header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \ |
| 88 | + --header 'Accept: application/json') |
| 89 | +
|
| 90 | + JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.issues[0].id') |
| 91 | + if [ -z "$JIRA_TICKET_ID" ]; then |
| 92 | + echo "JIRA_TICKET_ID is not defined. Exiting the script." |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | +
|
| 96 | + JIRA_REOPENED_URL="https://jira.mongodb.org/rest/api/2/issue/${JIRA_TICKET_ID}/transitions" |
| 97 | +
|
| 98 | + json_response=$(curl -s --request POST \ |
| 99 | + --url "${JIRA_REOPENED_URL}" \ |
| 100 | + --header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \ |
| 101 | + --header 'Accept: application/json' \ |
| 102 | + --header 'Content-Type: application/json' \ |
| 103 | + --data '{ |
| 104 | + "transition": { |
| 105 | + "id": 3 |
| 106 | + }, |
| 107 | + "update": { |
| 108 | + "comment": [ |
| 109 | + { |
| 110 | + "add": { |
| 111 | + "body": "The related GitHub issue was reopened. Updated via automated process." |
| 112 | + } |
| 113 | + } |
| 114 | + ] |
| 115 | + } |
| 116 | + }') |
| 117 | + echo "Response: ${json_response}" |
| 118 | + close_jira_ticket: |
| 119 | + name: Close JIRA ticket |
| 120 | + if: github.event.action == 'closed' |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - name: Close JIRA ticket if exists |
| 124 | + run: | |
| 125 | + ISSUE_NUMBER=${{ github.event.issue.number }} |
| 126 | + JIRA_API_TOKEN=${{ secrets.JIRA_API_TOKEN }} |
| 127 | +
|
| 128 | + JIRA_QUERY="project = CLOUDP AND issuetype = Story AND resolution = Unresolved AND text ~ \"HELP: GitHub Issue n. $ISSUE_NUMBER\"" |
| 129 | + |
| 130 | + # URL encode the query |
| 131 | + JIRA_URL=$(echo "$JIRA_QUERY" | jq -s -R -r @uri) |
| 132 | +
|
| 133 | + json_response=$(curl -s --request GET \ |
| 134 | + --url "https://jira.mongodb.org/rest/api/2/search?fields=id&jql=${JIRA_URL}" \ |
| 135 | + --header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \ |
| 136 | + --header 'Accept: application/json') |
| 137 | +
|
| 138 | + JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.issues[0].id') |
| 139 | + if [ -z "$JIRA_TICKET_ID" ]; then |
| 140 | + echo "JIRA_TICKET_ID is not defined. Exiting the script." |
| 141 | + exit 1 |
| 142 | + fi |
| 143 | +
|
| 144 | + JIRA_CLOSE_URL="https://jira.mongodb.org/rest/api/2/issue/${JIRA_TICKET_ID}/transitions" |
| 145 | +
|
| 146 | + json_response=$(curl -s --request POST \ |
| 147 | + --url "${JIRA_CLOSE_URL}" \ |
| 148 | + --header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \ |
| 149 | + --header 'Accept: application/json' \ |
| 150 | + --header 'Content-Type: application/json' \ |
| 151 | + --data '{ |
| 152 | + "transition": { |
| 153 | + "id": 1371 |
| 154 | + }, |
| 155 | + "update": { |
| 156 | + "comment": [ |
| 157 | + { |
| 158 | + "add": { |
| 159 | + "body": "The related GitHub issue was closed. Resolved via automated process." |
| 160 | + } |
| 161 | + } |
| 162 | + ] |
| 163 | + }, |
| 164 | + "fields": { |
| 165 | + "resolution": { |
| 166 | + "name": "Declined" |
| 167 | + } |
| 168 | + } |
| 169 | + }') |
| 170 | + echo "Response: ${json_response}" |
0 commit comments