From 850aa8b7010fda490667e4363a9f942b75227f9c Mon Sep 17 00:00:00 2001 From: Ismoh Date: Mon, 26 Sep 2022 16:50:38 +0200 Subject: [PATCH] #78 Added gh cli to get all comments regarding versioning and removing them to add a comment with the latest version. --- .../version-and-changelog-update.yml | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/version-and-changelog-update.yml b/.github/workflows/version-and-changelog-update.yml index c8b8f42d1..f5f23c587 100644 --- a/.github/workflows/version-and-changelog-update.yml +++ b/.github/workflows/version-and-changelog-update.yml @@ -105,23 +105,26 @@ jobs: run: | commentList=`gh api -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments` echo "commentList="$commentList - exit 1 - - + # https://jqplay.org/s/WsuVZ8f-YiB + commentIds=jq -e '.[] | select(.body | contains("Version will be automatically increase to")) | .id' + echo "commentIds="$commentIds + + for commentId in $commentIds do + statusCode=`gh api --method DELETE -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments/$commentId` + echo "statusCode="$statusCode + if [[ $statusCode != *"204"* ]] + then + echo "Unable to delete comment with id $commentId" + fi + done body="{\"body\":\"When this pull request was merged\\\:\r\n- Version will be automatically increase to **$NEXT_VERSION** in **${{ github.base_ref }}**\r\n- Tag **$NEXT_VERSION** will be created to the specific commit.\"}" - - curlResponse=`curl --write-out '%{http_code}' --output /dev/null --request POST \ - --header 'Accept: application/vnd.github+json' \ - --header 'Authorization: token ${{ github.token }}' \ - --url 'https://api.github.com/repos/${{github.repository}}/issues/${{github.event.number}}/comments' \ - --data-raw "$body"` - - if [[ $curlResponse == *"201"* ]] + statusCode=`gh api --method POST -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments -f body=$body` + echo "statusCode="$statusCode + + if [[ $statusCode != *"201"* ]] then - echo "SUCCESS" - else - echo "FAILURE" + echo "Unable to add comment to pull request" exit 1 fi