|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +source "$PROJECT_HOME/src/ensure.sh" |
| 4 | +source "$PROJECT_HOME/src/github.sh" |
| 5 | +source "$PROJECT_HOME/src/misc.sh" |
| 6 | +source "$PROJECT_HOME/src/teamwork.sh" |
| 7 | + |
| 8 | +main() { |
| 9 | + log::message "Running the process..." |
| 10 | + |
| 11 | + # Ensure env vars and args exist |
| 12 | + ensure::env_variable_exist "GITHUB_REPOSITORY" |
| 13 | + ensure::env_variable_exist "GITHUB_EVENT_PATH" |
| 14 | + ensure::total_args 3 "$@" |
| 15 | + |
| 16 | + export GITHUB_TOKEN="$1" |
| 17 | + export TEAMWORK_URI="$2" |
| 18 | + export TEAMWORK_API_TOKEN="$3" |
| 19 | + |
| 20 | + # Check if there is a task link in the PR |
| 21 | + local -r pr_body=$(github::get_pr_body) |
| 22 | + local -r task_id=$(teamwork::get_task_id_from_body "$pr_body" ) |
| 23 | + |
| 24 | + if [ "$task_id" == "" ]; then |
| 25 | + log::message "Task not found" |
| 26 | + exit 0 |
| 27 | + fi |
| 28 | + |
| 29 | + log::message "Task found with the id: "$task_id |
| 30 | + |
| 31 | + export TEAMWORK_TASK_ID=$task_id |
| 32 | + |
| 33 | + local -r event=$(github::get_event_name) |
| 34 | + local -r action=$(github::get_action) |
| 35 | + |
| 36 | + log::message "Event: " $event " - Action: " $action |
| 37 | + |
| 38 | + if [ "$event" == "pull_request" ] && [ "$action" == "opened" ]; then |
| 39 | + teamwork::pull_request_opened |
| 40 | + elif [ "$event" == "pull_request" ] && [ "$action" == "synchronize" ]; then |
| 41 | + teamwork::pull_request_synchronize |
| 42 | + elif [ "$event" == "pull_request" ] && [ "$action" == "closed" ]; then |
| 43 | + teamwork::pull_request_closed |
| 44 | + elif [ "$event" == "pull_request_review" ] && [ "$action" == "submitted" ]; then |
| 45 | + teamwork::pull_request_review_submitted |
| 46 | + elif [ "$event" == "pull_request_review" ] && [ "$action" == "edited" ]; then |
| 47 | + teamwork::pull_request_review_edited |
| 48 | + elif [ "$event" == "pull_request_review" ] && [ "$action" == "dismissed" ]; then |
| 49 | + teamwork::pull_request_review_dismissed |
| 50 | + elif [ "$event" == "pull_request_review_comment" ] && [ "$action" == "created" ]; then |
| 51 | + teamwork::pull_request_review_comment_created |
| 52 | + elif [ "$event" == "pull_request_review_comment" ] && [ "$action" == "deleted" ]; then |
| 53 | + teamwork::pull_request_review_comment_deleted |
| 54 | + elif [ "$event" == "issue_comment" ] && [ "$action" == "created" ]; then |
| 55 | + teamwork::issue_comment_created |
| 56 | + else |
| 57 | + log::message "Operation not allowed" |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | + |
| 61 | + exit $? |
| 62 | +} |
0 commit comments