-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmain.sh
More file actions
74 lines (60 loc) · 2.21 KB
/
main.sh
File metadata and controls
74 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# shellcheck disable=SC1090
source "$PROJECT_HOME/src/ensure.sh"
source "$PROJECT_HOME/src/github.sh"
source "$PROJECT_HOME/src/misc.sh"
source "$PROJECT_HOME/src/teamwork.sh"
main() {
log::message "Running the process..."
# Ensure env vars and args exist
ensure::env_variable_exist "GITHUB_REPOSITORY"
ensure::env_variable_exist "GITHUB_EVENT_PATH"
export GITHUB_TOKEN="$1"
export TEAMWORK_URI="$2"
export TEAMWORK_API_TOKEN="$3"
export AUTOMATIC_TAGGING="$4"
export BOARD_COLUMN_OPENED="$5"
export BOARD_COLUMN_MERGED="$6"
export BOARD_COLUMN_CLOSED="$7"
export LIGHTWEIGHT_COMMENT="$8"
env::set_environment
# Check if there is a task link in the PR
local -r pr_body=$(github::get_pr_body)
local -r task_ids_str=$(teamwork::get_task_id_from_body "$pr_body" )
if [ "$task_ids_str" == "" ]; then
log::message "Task not found"
exit 0
fi
local -r event=$(github::get_event_name)
local -r action=$(github::get_action)
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
project_id="$(teamwork::get_project_id_from_task "$task_id")"
export TEAMWORK_PROJECT_ID=$project_id
ignored_project_ids=("${IGNORE_PROJECT_IDS:-}")
if utils::in_array "$project_id" "${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
teamwork::pull_request_closed
elif [ "$event" == "pull_request_review" ] && [ "$action" == "submitted" ]; then
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
fi
done
exit $?
}