Skip to content

Commit 0f24ab6

Browse files
CLOUDP-292660: Update api-versions-reminder.yml to send a slack reminder and create jira ticket when APIs are approaching sunset (#340)
1 parent 5421120 commit 0f24ab6

File tree

2 files changed

+127
-24
lines changed

2 files changed

+127
-24
lines changed

.github/scripts/create_jira_ticket.sh

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,65 @@ url_encode() {
1919
}
2020

2121
encoded_jira_ticket_title=$(url_encode "${JIRA_TICKET_TITLE:?}")
22-
echo "${encoded_jira_ticket_title}"
22+
echo "encoded_jira_ticket_title: ${encoded_jira_ticket_title}"
2323

2424
found_issue=$(curl --request GET \
2525
--url 'https://jira.mongodb.org/rest/api/2/search?jql=project=10984%20AND%20issuetype=12%20AND%20component=35986%20AND%20summary~"'"${encoded_jira_ticket_title:?}"'"' \
2626
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
2727
--header 'Accept: application/json' \
2828
--header 'Content-Type: application/json' | jq .total)
2929

30+
echo "found_issue: ${found_issue}"
3031
if [ "$found_issue" -ne 0 ]; then
3132
echo "There is already a Jira ticket with the title \"${JIRA_TICKET_TITLE:?}\""
3233
echo "No new Jira ticket will be created."
3334
exit 0
3435
fi
3536

37+
echo "Creating Jira ticket...."
38+
echo "JIRA_TICKET_TITLE: ${JIRA_TICKET_TITLE}"
39+
echo "JIRA_TICKET_DESCRIPTION: ${JIRA_TICKET_DESCRIPTION}"
40+
3641
json_response=$(curl --request POST \
3742
--url 'https://jira.mongodb.org/rest/api/2/issue' \
3843
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
3944
--header 'Accept: application/json' \
4045
--header 'Content-Type: application/json' \
41-
--data '{
42-
"fields": {
43-
"project": {
44-
"id": "10984"
45-
},
46-
"summary": "'"${JIRA_TICKET_TITLE:?}"'",
47-
"issuetype": {
48-
"id": "12"
49-
},
50-
"customfield_12751": [{
51-
"id": "22223"
52-
}],
53-
"description": "'"${JIRA_TICKET_DESCRIPTION:?}"'",
54-
"components": [
55-
{
56-
"id": "35986"
57-
}
58-
]
59-
}
60-
}')
46+
--data @- <<EOF
47+
{
48+
"fields": {
49+
"project": {
50+
"id": "10984"
51+
},
52+
"summary": "${JIRA_TICKET_TITLE:?}",
53+
"issuetype": {
54+
"id": "12"
55+
},
56+
"customfield_12751": [
57+
{
58+
"id": "22223"
59+
}
60+
],
61+
"description": "${JIRA_TICKET_DESCRIPTION:?}",
62+
"components": [
63+
{
64+
"id": "35986"
65+
}
66+
]
67+
}
68+
}
69+
EOF
70+
)
6171

6272
echo "Response: ${json_response}"
6373

6474
JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.key')
6575

6676
echo "The following JIRA ticket has been created: ${JIRA_TICKET_ID}"
67-
echo "jira-ticket-id=${JIRA_TICKET_ID}" >> "${GITHUB_OUTPUT}"
77+
if [ "${JIRA_TICKET_ID}" != "null" ]; then
78+
echo "jira-ticket-id=${JIRA_TICKET_ID}" >> "${GITHUB_OUTPUT}"
79+
exit 0
80+
fi
81+
82+
exit 1
83+

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

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
name: 'Send a Slack Notification for upcoming release of API versions'
1+
name: 'Send a Slack Notification for APIs important events'
22

33
on:
44
workflow_dispatch: # Allow manual triggering
55
schedule:
66
- cron: '0 9 * * 1-5' # Run once a day at 09:00 UTC between Monday and Friday
77

88
jobs:
9-
send-api-version-reminder:
9+
new-api-version-reminder:
10+
name: New API Version Release Reminder
1011
runs-on: ubuntu-latest
1112
steps:
1213
- name: Checkout repository (dev branch)
@@ -47,3 +48,89 @@ jobs:
4748
-H 'Content-type: application/json' \
4849
--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/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
4950
echo "message_id=${message_id}"
51+
52+
sunset-api-version-reminder:
53+
name: Sunset APIs Reminder
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
58+
59+
- name: Install Python
60+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
61+
with:
62+
python-version: '3.12'
63+
64+
- name: Install FOASCLI
65+
env:
66+
foascli_version: ${{ vars.FOASCLI_VERSION }}
67+
run: |
68+
wget https://github.com/mongodb/openapi/releases/download/v"${foascli_version}"/mongodb-foas-cli_"${foascli_version}"_linux_x86_64.tar.gz -O foascli.tar.gz
69+
tar -xzvf foascli.tar.gz
70+
pushd mongodb-foas-cli_*
71+
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
72+
popd
73+
74+
- name: Retrieve Sunset APIs
75+
id: retrieve-sunset-apis
76+
env:
77+
openapi_spec_url: "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/v2.json"
78+
run: |
79+
three_months_date=""
80+
81+
# Determine if the system is macOS or Linux
82+
if [[ "$(uname)" == "Darwin" ]]; then
83+
# macOS date command format
84+
three_months_date=$(date -v+3m +"%Y-%m-%d")
85+
else
86+
# Linux date command format
87+
three_months_date=$(date --date="3 months" +"%Y-%m-%d")
88+
fi
89+
90+
echo "three_months_date: ${three_months_date}"
91+
92+
current_date=$(date +"%Y-%m-%d")
93+
echo "current_date: ${current_date}"
94+
95+
sunset_apis=$(foascli sunset ls -s "${openapi_spec_url}" --from "${current_date}" --to "${three_months_date}")
96+
if [[ "${sunset_apis}" != "null" ]]; then
97+
echo "API Versions that will be sunsets in the next 3 months: ${sunset_apis}"
98+
99+
# We calculate the md5sum of the JSON object which will be included in the Jira ticket title.
100+
# This approach ensures we create a new jira ticket only if the there is not already a ticket
101+
# with the same title
102+
hash_code_sunset_apis=$(echo "$sunset_apis" | jq -cS . | md5sum | awk '{print $1}')
103+
echo "hash: ${hash_code_sunset_apis}"
104+
echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}"
105+
echo "${sunset_apis}" > sunset_apis.json
106+
107+
else
108+
echo "No API Versions will be sunset within the next 3 months."
109+
fi
110+
111+
# Create a JIRA ticket only if the there is not already a ticket with the same title
112+
- name: Create JIRA Ticket
113+
id: create-jira-ticket
114+
if: steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis != null
115+
env:
116+
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
117+
JIRA_TICKET_TITLE: "[API Platform] Some APIs are approaching their sunset date in the next 3 months. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}"
118+
run: |
119+
sunset_apis=$(sed 's/"/\\"/g' sunset_apis.json)
120+
JIRA_TICKET_DESCRIPTION="The following APIs will be sunset in the next 3 months. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {noformat}${sunset_apis}{noformat}"
121+
export JIRA_TICKET_DESCRIPTION
122+
.github/scripts/create_jira_ticket.sh
123+
124+
# Send Slack notification only if the Jira ticket was created
125+
- name: Send Slack Notification
126+
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
127+
env:
128+
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }}
129+
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
130+
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
131+
run: |
132+
echo "JIRA_TICKET_ID: ${JIRA_TICKET_ID}"
133+
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
134+
-H 'Content-type: application/json' \
135+
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following APIs are scheduled to be sunset in the next 3 months. See Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
136+
echo "message_id=${message_id}"]

0 commit comments

Comments
 (0)