Skip to content

Commit 98ec78f

Browse files
Add logic to check for a Jira ticket with the same title
This commit update the logic in the create_jira_ticket.sh to check for a ticket with the same title before creating the ticket
1 parent 6fd4900 commit 98ec78f

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

.github/scripts/create_jira_ticket.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
#!/bin/bash
2+
3+
# This script creates a JIRA ticket if one does not already exist with the same title.
4+
# It performs the following steps:
5+
# 1. Defines a function to URL encode a given string.
6+
# 2. URL encodes the JIRA ticket title.
7+
# 3. Checks if a JIRA ticket with the same title already exists in the specified project (id=10984) and component (id=35986).
8+
# 4. If a ticket already exists, it exits without creating a new ticket.
9+
# 5. If no ticket exists, it creates a new JIRA ticket with the provided title and description.
10+
# 6. Outputs the ID of the created JIRA ticket and sets it as a GitHub Actions output variable.
11+
212
set -eou pipefail
313

14+
url_encode() {
15+
local string="$1"
16+
printf '%s' "$string" | xxd -p | sed 's/\(..\)/%\1/g'
17+
}
18+
19+
encoded_jira_ticket_title=$(url_encode "${JIRA_TICKET_TITLE:?}")
20+
echo "${encoded_jira_ticket_title}"
21+
22+
found_issue=$(curl --request GET \
23+
--url 'https://jira.mongodb.org/rest/api/2/search?jql=project=10984%20AND%20issuetype=12%20AND%20component=35986%20AND%20summary~'"${encoded_jira_ticket_title:?}" \
24+
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
25+
--header 'Accept: application/json' \
26+
--header 'Content-Type: application/json' | jq .total)
27+
28+
if [ "$found_issue" -ne 0 ]; then
29+
echo "There is already a Jira ticket with the title ${JIRA_TICKET_TITLE:?}"
30+
echo "No new Jira ticket will be created"
31+
exit 0
32+
fi
33+
434
json_response=$(curl --request POST \
535
--url 'https://jira.mongodb.org/rest/api/2/issue' \
636
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
@@ -11,14 +41,14 @@ json_response=$(curl --request POST \
1141
"project": {
1242
"id": "10984"
1343
},
14-
"summary": "('"${TARGET_ENV:?}"') The '"${RELEASE_NAME:?}"' release has failed",
44+
"summary": "'"${JIRA_TICKET_TITLE:?}"'",
1545
"issuetype": {
1646
"id": "12"
1747
},
1848
"customfield_12751": [{
1949
"id": "22223"
2050
}],
21-
"description": "The release process '"${RELEASE_NAME:?}"' in [mongodb/openapi|https://github.com/mongodb/openapi] has failed. Please, look at the [issue-'"${ISSUE_ID:?}"'|https://github.com/mongodb/openapi/issues/'"${ISSUE_ID}"'] for more details.",
51+
"description": "'"${JIRA_TICKET_DESCRIPTION:?}"'",
2252
"components": [
2353
{
2454
"id": "35986"

.github/scripts/upcoming_api_releases.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ URL="https://raw.githubusercontent.com/mongodb/openapi/dev/openapi/v2/versions.j
77
# Fetch the version.json file
88
response=$(curl -s "${URL}")
99

10-
# Parse the dates from the JSON response using jq
11-
dates=$(echo "${response}" | jq -r '.[]')
10+
# Parse the version_dates from the JSON response using jq
11+
version_dates=$(echo "${response}" | jq -r '.[]')
1212

13-
# Initialize an empty list to store dates within 3 weeks
14-
dates_within_3_weeks=()
13+
# Initialize an empty list to store version_dates within 3 weeks
14+
version_dates_within_3_weeks=()
1515

1616
# Get the current date in seconds since epoch
1717
current_date=$(date +%s)
@@ -26,23 +26,23 @@ else
2626
fi
2727

2828
# Iterate through each date
29-
for date in $dates; do
29+
for version_date in ${version_dates}; do
3030
# Convert the date to seconds since epoch with explicit format
31-
date_in_seconds=$($date_command "${date}" +%s 2>/dev/null)
31+
date_in_seconds=$($date_command "${version_date}" +%s 2>/dev/null)
3232

3333
# Calculate the difference in days between the date and the current date
3434
diff_in_days=$(( (date_in_seconds - current_date) / (60 * 60 * 24) ))
3535

3636
# Check if the date is within 3 weeks (21 days)
3737
if [[ "${diff_in_days}" -ge 0 && "${diff_in_days}" -le 21 ]]; then
3838
# Add the date to the list if within 3 weeks
39-
dates_within_3_weeks+=("${date}")
39+
version_dates_within_3_weeks+=("${date}")
4040
fi
4141
done
4242

43-
if [[ ${#dates_within_3_weeks[@]} -gt 0 ]]; then
44-
echo "API Versions that will be release in the next 3 weeks: ${dates_within_3_weeks[*]}"
45-
echo api_versions="${dates_within_3_weeks[*]}" >> "${GITHUB_OUTPUT:?}"
43+
if [[ ${#version_dates_within_3_weeks[@]} -gt 0 ]]; then
44+
echo "API Versions that will be release in the next 3 weeks: ${version_dates_within_3_weeks[*]}"
45+
echo api_versions="${version_dates_within_3_weeks[*]}" >> "${GITHUB_OUTPUT:?}"
4646
else
4747
echo "No API Versions that will be released within the next 3 weeks."
4848
fi

.github/workflows/api-versions-reminder.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: 'Send a Slack Notification for upcoming release of API versions'
33
on:
44
workflow_dispatch: # Allow manual triggering
55
schedule:
6-
- cron: '0 9 * * 1' # Run at 09:00 UTC every Monday
6+
- cron: '0 9 * * *' # Run once a day at 09:00 UTC
77

88
jobs:
99
send-changelog-report:
@@ -17,14 +17,26 @@ jobs:
1717
- name: Check if there are upcoming API versions releases
1818
id: check-api-versions
1919
run: .github/scripts/upcoming_api_releases.sh
20-
- name: Get Start and End Dates
20+
21+
# Create a JIRA ticket for the upcoming API versions only if the there is not already a ticket with the same title
22+
- name: Create JIRA Ticket
23+
id: create-jira-ticket
2124
if: steps.check-api-versions.outputs.api_versions != null
25+
env:
26+
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
27+
JIRA_TICKET_TITLE: "New API Versions ${{steps.check-api-versions.outputs.api_versions}} are about to be released"
28+
JIRA_TICKET_DESCRIPTION: "The following API Versions are scheduled to be released in the next 3 weeks: ${{steps.check-api-versions.outputs.api_versions}}"
29+
run: .github/scripts/create_jira_ticket.sh
30+
31+
- name: Send Slack Notification
32+
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
2233
env:
2334
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }}
2435
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
2536
API_VERSIONS: ${{ steps.check-api-versions.outputs.api_versions }}
37+
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
2638
run: |
2739
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
2840
-H 'Content-type: application/json' \
29-
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following API Versions are scheduled to be released in the next 3 weeks: '"${API_VERSIONS}"'. CC @apix-2-on-call","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
41+
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following API Versions are scheduled to be released in the next 3 weeks: '"${API_VERSIONS}"'. Jira Ticket: https://jira.mongodb.org/browse/'"${env.JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
3042
echo "message_id=${message_id}"

.github/workflows/failure-handler.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ jobs:
6969
if: ${{ steps.create-issue.outputs.number != null }}
7070
id: create-jira-ticket
7171
env:
72-
TARGET_ENV: ${{ inputs.env }}
73-
RELEASE_NAME: ${{ inputs.release_name }}
7472
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
75-
ISSUE_ID: ${{ steps.create-issue.outputs.number }}
73+
JIRA_TICKET_TITLE: "(${{inputs.env}}) The ${{inputs.release_name}} release has failed. GH Issue: ${{steps.create-issue.outputs.number}}"
74+
JIRA_TICKET_DESCRIPTION: "The release process ${{inputs.release_name}} in [mongodb/openapi|https://github.com/mongodb/openapi] has failed. Please, look at the [issue-${{steps.create-issue.outputs.number}}|https://github.com/mongodb/openapi/issues/${{steps.create-issue.outputs.number}}] for more details."
7675
run: .github/scripts/create_jira_ticket.sh
7776
- name: Add comment to GH Issue
7877
if: ${{ steps.create-issue.outputs.number != null }}

0 commit comments

Comments
 (0)