Skip to content

Commit

Permalink
Support to env.IGNORE_PROJECT_IDS setting (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
aetheon authored Dec 14, 2021
1 parent 42dcac6 commit ea92d72
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</h1>

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

![Linter](https://github.com/Teamwork/github-sync/workflows/Linter/badge.svg)
Expand All @@ -21,7 +21,7 @@ Create the next environment vars in your repository:
* `TEAMWORK_URI`: The URL of your installation (e.g.: https://yourcompany.teamwork.com)
* `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.

**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.
**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.

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

Expand Down Expand Up @@ -51,13 +51,15 @@ jobs:
BOARD_COLUMN_OPENED: 'PR Open'
BOARD_COLUMN_MERGED: 'Ready to Test'
BOARD_COLUMN_CLOSED: 'Rejected'
env:
IGNORE_PROJECT_IDS="1,2,3"

```

## Usage
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.
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.

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.
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.

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

Expand Down
7 changes: 7 additions & 0 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ main() {
project_id="$(teamwork::get_project_id_from_task "$task_id")"
export TEAMWORK_PROJECT_ID=$project_id

ignored_project_ids=("$IGNORE_PROJECT_IDS")
if (( ${#ignored_project_ids[@]} != 0 )) || utils::in_array "$1" "${ignored_project_ids[*]}"
then
log::message "ignored due to IGNORE_PROJECT_IDS"
exit 0
fi

if [ "$event" == "pull_request" ] && [ "$action" == "opened" ]; then
teamwork::pull_request_opened
elif [ "$event" == "pull_request" ] && [ "$action" == "closed" ]; then
Expand Down
12 changes: 12 additions & 0 deletions src/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ env::set_environment() {
export ENV="prod"
fi
}

utils::in_array() {
ARRAY=$2
for e in ${ARRAY[*]}
do
if [[ "$e" == "$1" ]]
then
return 0
fi
done
return 1
}

0 comments on commit ea92d72

Please sign in to comment.