Skip to content

Commit f4d4ec1

Browse files
miguelbemartinyannig
andauthored
Have automatic tagging as an option (#35)
Co-authored-by: yannig <[email protected]> Co-authored-by: Miguel Ángel Martín <[email protected]>
2 parents f415d94 + dd179a8 commit f4d4ec1

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ jobs:
1717
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1818
TEAMWORK_URI: "localhost"
1919
TEAMWORK_API_TOKEN: "test_api_token"
20+
AUTOMATIC_TAGGING: true

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4848
TEAMWORK_URI: ${{ secrets.TEAMWORK_URI }}
4949
TEAMWORK_API_TOKEN: ${{ secrets.TEAMWORK_API_TOKEN }}
50+
AUTOMATIC_TAGGING: false
5051

5152
```
5253

@@ -59,7 +60,7 @@ Please note, the comment will be created in Teamwork under the account you have
5960

6061
![Teamwork pr comment](./.github/assets/teamwork_pr_comment.png)
6162

62-
Tags are added automatically on the task:
63+
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:
6364
- A new PR is open: tag `PR Open`
6465
- A PR is approved: tag `PR Approved` added
6566
- A PR is merged: tags `PR Open` and `PR Approved` removed, tag `PR merged` added

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ inputs:
1313
TEAMWORK_API_TOKEN:
1414
description: 'Teamwork API token'
1515
required: true
16+
AUTOMATIC_TAGGING:
17+
description: 'Do you want to enable automatic tagging: true/false'
18+
required: false
1619
runs:
1720
using: 'docker'
1821
image: 'Dockerfile'
1922
args:
2023
- ${{ inputs.GITHUB_TOKEN }}
2124
- ${{ inputs.TEAMWORK_URI }}
2225
- ${{ inputs.TEAMWORK_API_TOKEN }}
26+
- ${{ inputs.AUTOMATIC_TAGGING }}

src/main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ main() {
1212
# Ensure env vars and args exist
1313
ensure::env_variable_exist "GITHUB_REPOSITORY"
1414
ensure::env_variable_exist "GITHUB_EVENT_PATH"
15-
ensure::total_args 3 "$@"
1615

1716
export GITHUB_TOKEN="$1"
1817
export TEAMWORK_URI="$2"
1918
export TEAMWORK_API_TOKEN="$3"
19+
export AUTOMATIC_TAGGING="$4"
2020

2121
env::set_environment
2222

src/teamwork.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ teamwork::add_tag() {
4040
return
4141
fi
4242

43-
response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \
43+
if [ "$AUTOMATIC_TAGGING" == true ]; then
44+
response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \
4445
-u "$TEAMWORK_API_TOKEN"':' \
4546
-H 'Content-Type: application/json; charset=utf-8' \
4647
-d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" } }" )
4748

48-
log::message "$response"
49+
log::message "$response"
50+
fi
4951
}
5052

5153
teamwork::remove_tag() {
@@ -56,12 +58,14 @@ teamwork::remove_tag() {
5658
return
5759
fi
5860

59-
response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \
60-
-u "$TEAMWORK_API_TOKEN"':' \
61-
-H 'Content-Type: application/json; charset=utf-8' \
62-
-d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }" )
61+
if [ "$AUTOMATIC_TAGGING" == true ]; then
62+
response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/tags.json" \
63+
-u "$TEAMWORK_API_TOKEN"':' \
64+
-H 'Content-Type: application/json; charset=utf-8' \
65+
-d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }" )
6366

64-
log::message "$response"
67+
log::message "$response"
68+
fi
6569
}
6670

6771
teamwork::pull_request_opened() {

0 commit comments

Comments
 (0)