forked from django-cms/django-filer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Verify Jira tickets status | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
current-branch-status: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: '0' | ||
- name: Assume Role | ||
uses: aws-actions/configure-aws-credentials@master | ||
with: | ||
aws-region: ${{ secrets.REGION }} | ||
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_NUMBER }}:role/service/${{ secrets.ROLE_NAME }} | ||
- name: Get Gorson | ||
shell: bash | ||
run: | | ||
wget -O /usr/local/bin/gorson https://github.com/pbs/gorson/releases/download/4.0.0/gorson-4.0.0-linux-amd64 | ||
chmod +x /usr/local/bin/gorson | ||
- name: Checking for JIRA tickets status | ||
env: | ||
AWS_PROFILE: pbs-digi-preprod | ||
AWS_REGION: us-east-1 | ||
shell: bash | ||
run : ./ check_both |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
#!/bin/bash | ||
|
||
# Reset | ||
NC='\033[0m' # Text Reset | ||
RED='\033[0;31m' # Red | ||
GREEN='\033[0;32m' # Green | ||
YELLOW='\033[0;33m' # Yellow | ||
SLACK_RED="FF0000" | ||
SLACK_GREEN="008000" | ||
|
||
PARAMETER_PATH='/WS/BENTO3/QA/COMMON/JIRA_API_KEY' | ||
JIRA_API_BASE_URL="https://projects.pbs.org/jira/rest/api/2" | ||
JIRA_API_SEARCH_URL="$JIRA_API_BASE_URL/search" | ||
JIRA_RELEASE_VERSIONS="$JIRA_API_BASE_URL/project/BEN/versions" | ||
|
||
GIT_CURRENT_BRANCH="origin/master_pbs" | ||
GIT_LOGS=$(git log origin/master_pbs --oneline --merges) | ||
TICKETS_FROM_GIT=$( echo ${GIT_LOGS[@]} | grep -e '[A-Z]\+-[0-9]\+' -o | sort -u | tr '\n' ',' | sed 's/,$/\n/') | ||
JIRA_TOKEN=$( echo $(gorson get ${PARAMETER_PATH}) | jq -r ".TOKEN") | ||
RELEASE_VERSION=$( | ||
curl --compressed \ | ||
--location $JIRA_RELEASE_VERSIONS \ | ||
-H "Authorization: Bearer ${JIRA_TOKEN[@]}" \ | ||
--get | jq .[-1].name | sed -e 's/^"//' -e 's/"$//') | ||
SLACK_BOT_TOKEN=$(gorson get /WS/BENTO3/QA/COMMON/JIRA | jq -r '.CHECK_JIRA_TICKETS') | ||
SLACK_CHANNEL=$(gorson get /WS/BENTO3/QA/COMMON/JIRA | jq -r '.SLACK_NOTIF_CHANNEL') | ||
|
||
get_slack_json_tamplate(){ | ||
local JSON=$(cat <<-EOF | ||
{ | ||
"channel": "$1", | ||
"text": "$2", | ||
"attachments": [ | ||
{ | ||
"text":"$(cat ./$3 | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')", | ||
"color":"$4" | ||
} | ||
] | ||
} | ||
EOF | ||
) | ||
echo "${JSON}" | ||
} | ||
|
||
post_slack_message(){ | ||
curl --compressed -X POST -H "Authorization: Bearer ${SLACK_BOT_TOKEN[@]}" \ | ||
-H 'Content-type: application/json' \ | ||
--data "${1}" \ | ||
https://slack.com/api/chat.postMessage | ||
} | ||
|
||
check_tickets_version_from_release(){ | ||
SLACK_TITLE="[FILER] Checking for JIRA tickets from release that don't have fix version on FILER" | ||
SLACK_LOG="check_tickets_version_from_release_logs" | ||
COLOR=${SLACK_GREEN} | ||
|
||
touch ./check_tickets_version_from_release_logs | ||
echo -e "\n${GREEN}Checking for JIRA tickets from release that don't have fix version${NC} \n" | ||
if [ -z "$TICKETS_FROM_GIT" ] | ||
then | ||
echo -e "${GREEN}There aren't new JIRA Tickets in ${GIT_CURRENT_BRANCH}. This branch might have been merged already in master. ${NC}" | ||
echo "There aren't new JIRA Tickets in ${GIT_CURRENT_BRANCH}. This branch might have been merged already in master." >> ./check_tickets_version_from_release_logs | ||
JSON=$(get_slack_json_tamplate "${SLACK_CHANNEL}" "${SLACK_TITLE}" "${SLACK_LOG}" "${COLOR}") | ||
post_slack_message "${JSON}" | ||
return 0 | ||
fi | ||
|
||
JIRA_TICKETS_INFO=$( | ||
curl --compressed \ | ||
--location $JIRA_API_SEARCH_URL \ | ||
-H "Authorization: Bearer ${JIRA_TOKEN[@]}" \ | ||
--get \ | ||
--data-urlencode "jql=project=BEN and component = filer and (labels != no-code or labels is empty) and key in (${TICKETS_FROM_GIT})" \ | ||
--data-urlencode "fields=fixVersions") | ||
|
||
ISSUES_JSON=$(jq -r '.issues' <<< $JIRA_TICKETS_INFO) | ||
ISSUES=$(jq -r 'def groups(d): if d | length > 0 then d | map(.name) | join(",") else "-" end;map([.key, groups(.fields.fixVersions), "\n"])[] | @tsv' <<< ${ISSUES_JSON}) | ||
|
||
echo -e "${GREEN}Printing JIRA tickets that don't have fix version ${RELEASE_VERSION} ${NC} \n" | ||
echo -e "Printing JIRA tickets that don't have fix version ${RELEASE_VERSION} \n" >> ./check_tickets_version_from_release_logs | ||
|
||
echo -e "${ISSUES} \n" | grep -v "${RELEASE_VERSION}" | ||
echo -e "${ISSUES} \n" | grep -v "${RELEASE_VERSION}" >> ./check_tickets_version_from_release_logs | ||
tickets=$(echo -e ${ISSUES} | grep -v "${RELEASE_VERSION}") | ||
|
||
if [ -z "$tickets" ] | ||
then | ||
COLOR=${SLACK_GREEN} | ||
else | ||
COLOR=${SLACK_RED} | ||
fi | ||
|
||
JSON=$(get_slack_json_tamplate "${SLACK_CHANNEL}" "${SLACK_TITLE}" "${SLACK_LOG}" "${COLOR}") | ||
post_slack_message "${JSON}" | ||
|
||
|
||
if [ -z "$tickets" ] | ||
then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# the function bellow must be run before the release/hotfix is merged into master | ||
# in case the release/hotfix is merged into master there won't be any diffs | ||
# and all tickets will appear as not merged into release | ||
check_tickets_version_from_jira(){ | ||
SLACK_TITLE="[FILER] Checking for JIRA FILER tickets that aren't merged in master and have this fix version" | ||
SLACK_LOG="check_tickets_version_from_jira_logs" | ||
COLOR=${SLACK_GREEN} | ||
|
||
touch ./check_tickets_version_from_jira_logs | ||
echo -e "\n${GREEN}Checking for JIRA tickets that aren't merged in release and have this fix version${NC} \n" | ||
JIRA_TICKETS_INFO=$( | ||
curl --compressed \ | ||
--location $JIRA_API_SEARCH_URL \ | ||
-H "Authorization: Bearer ${JIRA_TOKEN[@]}" \ | ||
--get \ | ||
--data-urlencode "jql=project=BEN and status != closed and component = filer and (labels != no-code or labels is empty) and fixVersion=${RELEASE_VERSION}" \ | ||
--data-urlencode "fields=fixVersions") | ||
|
||
ISSUES_JSON=$(jq -r '.issues' <<< $JIRA_TICKETS_INFO) | ||
|
||
if [ -z "$ISSUES_JSON" ] || [ "$ISSUES_JSON" = null ] | ||
then | ||
echo -e "${GREEN}All JIRA tickets from ${RELEASE_VERSION} have been closed${NC}" | ||
echo "All JIRA tickets from ${RELEASE_VERSION} have been closed" >> ./check_tickets_version_from_jira_logs | ||
JSON=$(get_slack_json_tamplate "${SLACK_CHANNEL}" "${SLACK_TITLE}" "${SLACK_LOG}" "${COLOR}") | ||
post_slack_message "${JSON}" | ||
return 0 | ||
fi | ||
|
||
ISSUES=$(jq -r '. | map(.key) | join(",")' <<< ${ISSUES_JSON}) | ||
|
||
|
||
IFS=',' read -r -a TICKETS_FROM_JIRA <<< "${ISSUES}" | ||
echo -e "${GREEN}Printing JIRA tickets that aren't merged in ${RELEASE_VERSION}${NC} \n" | ||
echo -e "Printing JIRA tickets that aren't merged in ${RELEASE_VERSION} \n" >> ./check_tickets_version_from_jira_logs | ||
|
||
OK=0 | ||
for element in "${TICKETS_FROM_JIRA[@]}" | ||
do | ||
if [[ "$TICKETS_FROM_GIT" == *"$element"* ]]; then | ||
continue | ||
else | ||
echo "${element}" | ||
echo "${element}" >> ./check_tickets_version_from_jira_logs | ||
OK=1 | ||
fi | ||
done | ||
|
||
if [[ $OK == 0 ]]; then | ||
COLOR=${SLACK_GREEN} | ||
else | ||
COLOR=${SLACK_RED} | ||
fi | ||
|
||
JSON=$(get_slack_json_tamplate "${SLACK_CHANNEL}" "${SLACK_TITLE}" "${SLACK_LOG}" "${COLOR}") | ||
post_slack_message "${JSON}" | ||
|
||
if [[ $OK == 0 ]]; then | ||
return 0 | ||
fi | ||
|
||
return 1 | ||
} | ||
|
||
SLACK_TITLE="Error running check_jira_tickets_fix_version.sh script" | ||
SLACK_LOG="check_jira_tickets_fix_version_logs" | ||
COLOR=${SLACK_RED} | ||
touch ./check_jira_tickets_fix_version_logs | ||
|
||
if [ -z "$JIRA_TOKEN" ] | ||
then | ||
echo -e "${RED}JIRA_TOKEN is empty ${NC}" | ||
echo "JIRA_TOKEN is empty" >> ./check_jira_tickets_fix_version_logs | ||
JSON=$(get_slack_json_tamplate "${SLACK_CHANNEL}" "${SLACK_TITLE}" "${SLACK_LOG}" "${COLOR}") | ||
post_slack_message "${JSON}" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$1" ] | ||
then | ||
echo -e "${RED}Script called without mandatory check param ${NC}" | ||
echo "Script called without mandatory check param" >> ./check_jira_tickets_fix_version_logs | ||
JSON=$(get_slack_json_tamplate "${SLACK_CHANNEL}" "${SLACK_TITLE}" "${SLACK_LOG}" "${COLOR}") | ||
post_slack_message "${JSON}" | ||
exit 1 | ||
fi | ||
|
||
# DEBUGGING GIT_LOGS command | ||
# echo -e "${YELLOW}Debug GIT LOGS \n ${GIT_LOGS} \n${NC}" | ||
|
||
case $1 in | ||
check_tickets_version_from_jira) | ||
OK=0 | ||
if (! check_tickets_version_from_jira); then | ||
OK=1 | ||
fi | ||
|
||
if [[ $OK == 0 ]]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
;; | ||
check_tickets_version_from_release) | ||
OK=0 | ||
if(! check_tickets_version_from_release); then | ||
OK=1 | ||
fi | ||
|
||
if [[ $OK == 0 ]]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
;; | ||
check_both) | ||
OK=0 | ||
if(! check_tickets_version_from_release); then | ||
OK=1 | ||
fi | ||
|
||
if (! check_tickets_version_from_jira); then | ||
OK=1 | ||
fi | ||
|
||
if [[ $OK == 0 ]]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
;; | ||
esac |