Skip to content

Commit

Permalink
Have automatic tagging as an option (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: yannig <[email protected]>
Co-authored-by: Miguel Ángel Martín <[email protected]>
  • Loading branch information
miguelbemartin and yannig authored Nov 27, 2020
2 parents f415d94 + dd179a8 commit f4d4ec1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEAMWORK_URI: "localhost"
TEAMWORK_API_TOKEN: "test_api_token"
AUTOMATIC_TAGGING: true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ 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'
args:
- ${{ inputs.GITHUB_TOKEN }}
- ${{ inputs.TEAMWORK_URI }}
- ${{ inputs.TEAMWORK_API_TOKEN }}
- ${{ inputs.AUTOMATIC_TAGGING }}
2 changes: 1 addition & 1 deletion src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 11 additions & 7 deletions src/teamwork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit f4d4ec1

Please sign in to comment.