From 96aea90bca397ef7eeab2ba3c7a860a459e651f0 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Sat, 3 Aug 2019 20:32:15 +0200 Subject: [PATCH] MON-490 add support to create version if does not exist --- scripts/changelog.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/changelog.sh b/scripts/changelog.sh index 31ff7a8..ffcc473 100755 --- a/scripts/changelog.sh +++ b/scripts/changelog.sh @@ -107,14 +107,16 @@ if [[ "$answer" == "y" ]]; then echo -e "$(cat $TMP_CHANGELOG)${separator}$(cat CHANGELOG.md)" > CHANGELOG.md fi -if jira --endpoint=${JIRA_ENDPOINT} --login=${JIRA_LOGIN} editmeta $(head -n 1 $TMP_ALLOWED_ISSUES) --template=versions | grep $TAG_TARGET; then - read -p "Close all issues and fix version $TAG_TARGET ? (y/n): " -r answer - if [[ "$answer" == "y" ]]; then - for issue in $(cat $TMP_ALLOWED_ISSUES); do - echo jira --endpoint=${JIRA_ENDPOINT} --login=${JIRA_LOGIN} transition Close $issue - echo jira --endpoint=${JIRA_ENDPOINT} --login=${JIRA_LOGIN} edit $issue --template=fixversion --override fixVersions=${TAG_TARGET} --noedit - done +read -p "Close all issues and fix version $TAG_TARGET ? (y/n): " -r answer +if [[ "$answer" == "y" ]]; then + # Create version if does not exists + one_issue=$(head -n 1 $TMP_ALLOWED_ISSUES) + auth_header=$(printf "${JIRA_LOGIN}:${JIRA_API_TOKEN}" | base64) + if ! jira --endpoint=${JIRA_ENDPOINT} --login=${JIRA_LOGIN} editmeta $one_issue --template=versions | grep -q $TAG_TARGET; then + curl -H "Authorization: Basic $auth_header" -H "Content-Type: application/json" -X POST -d "{\"name\": \"${TAG_TARGET}\",\"userReleaseDate\": \"$(echo -n $(LANG=eng date +'%-d/%b/%Y'))\",\"project\": \"$(echo -n $one_issue | cut -d'-' -f1)\",\"archived\": false,\"released\": true}" ${JIRA_ENDPOINT}/rest/api/latest/version fi -else - echo "Impossible to close issues because version \"${TAG_TARGET}\" does not exists, please create it on JIRA" + for issue in $(cat $TMP_ALLOWED_ISSUES); do + jira --endpoint=${JIRA_ENDPOINT} --login=${JIRA_LOGIN} transition Close $issue + jira --endpoint=${JIRA_ENDPOINT} --login=${JIRA_LOGIN} edit $issue --template=fixversion --override fixVersions=${TAG_TARGET} --noedit + done fi