Skip to content

Commit ea92d72

Browse files
authored
Support to env.IGNORE_PROJECT_IDS setting (#48)
1 parent 42dcac6 commit ea92d72

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</h1>
1010

1111
<p align="center">
12-
This action helps you to sync your PRs with tasks in Teamwork to streamline team collaboration and your development workflows.
12+
This action helps you to sync your PRs with tasks in Teamwork to streamline team collaboration and your development workflows.
1313
</p>
1414

1515
![Linter](https://github.com/Teamwork/github-sync/workflows/Linter/badge.svg)
@@ -21,7 +21,7 @@ Create the next environment vars in your repository:
2121
* `TEAMWORK_URI`: The URL of your installation (e.g.: https://yourcompany.teamwork.com)
2222
* `TEAMWORK_API_TOKEN`: The API token to authenticate the workflow. Follow [this guide](https://developer.teamwork.com/guides/api-key-url/) to find your URL and API key.
2323

24-
**Please Note:** The Teamwork account associated with this API key is the account which these comments will be created under. If this user does not have permission to access the project, this action will be ignored.
24+
**Please Note:** The Teamwork account associated with this API key is the account which these comments will be created under. If this user does not have permission to access the project, this action will be ignored.
2525

2626
`GITHUB_TOKEN` doesn't need to be setup in the repository, this var is always available during the workflows execution.
2727

@@ -51,13 +51,15 @@ jobs:
5151
BOARD_COLUMN_OPENED: 'PR Open'
5252
BOARD_COLUMN_MERGED: 'Ready to Test'
5353
BOARD_COLUMN_CLOSED: 'Rejected'
54+
env:
55+
IGNORE_PROJECT_IDS="1,2,3"
5456

5557
```
5658

5759
## Usage
58-
When creating a new PR, write in the description of the PR the URL of the task. The action will automatically add a comment in the task.
60+
When creating a new PR, write in the description of the PR the URL of the task. The action will automatically add a comment in the task.
5961

60-
Please note, the comment will be created in Teamwork under the account you have attached to this action. If the API key of the user you are using does not have permissions to access certain projects, the comment will not be created.
62+
Please note, the comment will be created in Teamwork under the account you have attached to this action. If the API key of the user you are using does not have permissions to access certain projects, the comment will not be created.
6163

6264
![GitHub pr comment](./.github/assets/github_pr_comment.png)
6365

src/main.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ main() {
4646
project_id="$(teamwork::get_project_id_from_task "$task_id")"
4747
export TEAMWORK_PROJECT_ID=$project_id
4848

49+
ignored_project_ids=("$IGNORE_PROJECT_IDS")
50+
if (( ${#ignored_project_ids[@]} != 0 )) || utils::in_array "$1" "${ignored_project_ids[*]}"
51+
then
52+
log::message "ignored due to IGNORE_PROJECT_IDS"
53+
exit 0
54+
fi
55+
4956
if [ "$event" == "pull_request" ] && [ "$action" == "opened" ]; then
5057
teamwork::pull_request_opened
5158
elif [ "$event" == "pull_request" ] && [ "$action" == "closed" ]; then

src/misc.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ env::set_environment() {
1616
export ENV="prod"
1717
fi
1818
}
19+
20+
utils::in_array() {
21+
ARRAY=$2
22+
for e in ${ARRAY[*]}
23+
do
24+
if [[ "$e" == "$1" ]]
25+
then
26+
return 0
27+
fi
28+
done
29+
return 1
30+
}

0 commit comments

Comments
 (0)