From f2c55fd4da9f0a7bad7f0a41dd424a4dbe26af09 Mon Sep 17 00:00:00 2001 From: Mike Repec Date: Mon, 9 Aug 2021 15:50:08 +0200 Subject: [PATCH 1/4] Fix: make project_id variable non-readonly --- src/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.sh b/src/main.sh index d07f3d8d..546559f9 100644 --- a/src/main.sh +++ b/src/main.sh @@ -42,7 +42,7 @@ main() { log::message "Task found with the id: $task_id" export TEAMWORK_TASK_ID=$task_id - local -r project_id="$(teamwork::get_project_id_from_task "$task_id")" + local project_id="$(teamwork::get_project_id_from_task "$task_id")" export TEAMWORK_PROJECT_ID=$project_id if [ "$event" == "pull_request" ] && [ "$action" == "opened" ]; then From 729fd046649817d8d630613255466cd4be5e35b3 Mon Sep 17 00:00:00 2001 From: Mike Repec Date: Mon, 9 Aug 2021 16:00:13 +0200 Subject: [PATCH 2/4] Lint fix: Declare project_id before assigning it --- src/main.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.sh b/src/main.sh index 546559f9..9fdf1e89 100644 --- a/src/main.sh +++ b/src/main.sh @@ -37,15 +37,16 @@ main() { log::message "Event: $event - Action: $action" + local project_id IFS=',' read -r -a task_ids <<< "$task_ids_str" for task_id in "${task_ids[@]}"; do log::message "Task found with the id: $task_id" export TEAMWORK_TASK_ID=$task_id - local project_id="$(teamwork::get_project_id_from_task "$task_id")" + project_id="$(teamwork::get_project_id_from_task "$task_id")" export TEAMWORK_PROJECT_ID=$project_id - if [ "$event" == "pull_request" ] && [ "$action" == "opened" ]; then + if [ "$event" == "pull_request" ] && [ "$action" == "opened" ] || [ "$action" == "reopened" ]; then teamwork::pull_request_opened elif [ "$event" == "pull_request" ] && [ "$action" == "closed" ]; then teamwork::pull_request_closed From 56f5f52cfe1010a82f4b4b04650a68511a43321c Mon Sep 17 00:00:00 2001 From: Mike Repec Date: Mon, 9 Aug 2021 16:07:02 +0200 Subject: [PATCH 3/4] Always run pull_request_opened as a last case scenario when in test --- src/main.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.sh b/src/main.sh index 9fdf1e89..8172667a 100644 --- a/src/main.sh +++ b/src/main.sh @@ -54,6 +54,8 @@ main() { teamwork::pull_request_review_submitted elif [ "$event" == "pull_request_review" ] && [ "$action" == "dismissed" ]; then teamwork::pull_request_review_dismissed + elif [ "$ENV" == "test" ]; then # always run pull_request_opened at the very least when in test + teamwork::pull_request_opened else log::message "Operation not allowed" exit 0 From 151abee06da2eb126840d5679edd1173a71421b3 Mon Sep 17 00:00:00 2001 From: Mike Repec Date: Mon, 9 Aug 2021 17:42:23 +0200 Subject: [PATCH 4/4] Revert running pull_request_opened when pr is reopened --- src/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.sh b/src/main.sh index 8172667a..4ec5a3e4 100644 --- a/src/main.sh +++ b/src/main.sh @@ -46,7 +46,7 @@ main() { project_id="$(teamwork::get_project_id_from_task "$task_id")" export TEAMWORK_PROJECT_ID=$project_id - if [ "$event" == "pull_request" ] && [ "$action" == "opened" ] || [ "$action" == "reopened" ]; then + if [ "$event" == "pull_request" ] && [ "$action" == "opened" ]; then teamwork::pull_request_opened elif [ "$event" == "pull_request" ] && [ "$action" == "closed" ]; then teamwork::pull_request_closed