From 9d8691bc19195e00eb5fc158f127e931a11df6bd Mon Sep 17 00:00:00 2001 From: yannig Date: Thu, 26 Nov 2020 20:54:02 +0000 Subject: [PATCH] Have automatic tagging as an option --- .github/workflows/test.yml | 1 + README.md | 3 ++- action.yml | 4 ++++ src/main.sh | 2 +- src/teamwork.sh | 18 +++++++++++------- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af707858..f4ac80ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,3 +17,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TEAMWORK_URI: "localhost" TEAMWORK_API_TOKEN: "test_api_token" + AUTOMATIC_TAGGING: true diff --git a/README.md b/README.md index d50ebd69..504b85bb 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TEAMWORK_URI: ${{ secrets.TEAMWORK_URI }} TEAMWORK_API_TOKEN: ${{ secrets.TEAMWORK_API_TOKEN }} + AUTOMATIC_TAGGING: false ``` @@ -59,7 +60,7 @@ Please note, the comment will be created in Teamwork under the account you have ![Teamwork pr comment](./.github/assets/teamwork_pr_comment.png) -Tags are added automatically on the task: +Tags are added automatically on the task if you are have the option `AUTOMATIC_TAGGING` set to `true` and the tag exists in you targeting project: - A new PR is open: tag `PR Open` - A PR is approved: tag `PR Approved` added - A PR is merged: tags `PR Open` and `PR Approved` removed, tag `PR merged` added diff --git a/action.yml b/action.yml index 4d296433..c9889170 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: TEAMWORK_API_TOKEN: description: 'Teamwork API token' required: true + AUTOMATIC_TAGGING: + description: 'Do you want to enable automatic tagging: true/false' + required: false runs: using: 'docker' image: 'Dockerfile' @@ -20,3 +23,4 @@ runs: - ${{ inputs.GITHUB_TOKEN }} - ${{ inputs.TEAMWORK_URI }} - ${{ inputs.TEAMWORK_API_TOKEN }} + - ${{ inputs.AUTOMATIC_TAGGING }} diff --git a/src/main.sh b/src/main.sh index 0186cabe..e05b8b0f 100644 --- a/src/main.sh +++ b/src/main.sh @@ -12,11 +12,11 @@ main() { # Ensure env vars and args exist ensure::env_variable_exist "GITHUB_REPOSITORY" ensure::env_variable_exist "GITHUB_EVENT_PATH" - ensure::total_args 3 "$@" export GITHUB_TOKEN="$1" export TEAMWORK_URI="$2" export TEAMWORK_API_TOKEN="$3" + export AUTOMATIC_TAGGING="$4" env::set_environment diff --git a/src/teamwork.sh b/src/teamwork.sh index 1aee9883..8e06df9e 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -40,12 +40,14 @@ teamwork::add_tag() { return fi - response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \ + if [ "$AUTOMATIC_TAGGING" == true ]; then + response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \ -u "$TEAMWORK_API_TOKEN"':' \ -H 'Content-Type: application/json; charset=utf-8' \ -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" } }" ) - log::message "$response" + log::message "$response" + fi } teamwork::remove_tag() { @@ -56,12 +58,14 @@ teamwork::remove_tag() { return fi - response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \ - -u "$TEAMWORK_API_TOKEN"':' \ - -H 'Content-Type: application/json; charset=utf-8' \ - -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }" ) + if [ "$AUTOMATIC_TAGGING" == true ]; then + response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \ + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }" ) - log::message "$response" + log::message "$response" + fi } teamwork::pull_request_opened() {