diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bab5c6c..5e306b76 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,3 +20,4 @@ jobs: BOARD_COLUMN_OPENED: "PR Open" BOARD_COLUMN_MERGED: "Ready to Test" BOARD_COLUMN_CLOSED: "Rejected" + BOARD_COLUMN_FEEDBACK: "PR Open" diff --git a/README.md b/README.md index 3c54c77b..f1b57e00 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ jobs: BOARD_COLUMN_OPENED: 'PR Open' BOARD_COLUMN_MERGED: 'Ready to Test' BOARD_COLUMN_CLOSED: 'Rejected' + BOARD_COLUMN_FEEDBACK: 'PR Open' env: IGNORE_PROJECT_IDS: '1 2 3' @@ -75,6 +76,7 @@ You may also specify columns you'd like the task to be moved to on every stage o - `BOARD_COLUMN_OPENED`: The case-sensitive column name of the column you'd like the task to be moved to once the PR has been opened - `BOARD_COLUMN_MERGED`: The case-sensitive column name of the column you'd like the task to be moved to once the PR has been merged - `BOARD_COLUMN_CLOSED`: The case-sensitive column name of the column you'd like the task to be moved to if the PR was closed without being merged +- `BOARD_COLUMN_FEEDBACK`: The case-sensitive column name of the column you would like the task to be moved to when the PR receives feedback The column names will be checked against all board columns in the task's project, this will be using a `contains()` method so you may specify part of the name instead of the full name, however this `contains()` check is case-sensitive. The first matching column will be used. diff --git a/action.yml b/action.yml index f704b08a..c032b1db 100644 --- a/action.yml +++ b/action.yml @@ -15,19 +15,23 @@ inputs: required: true AUTOMATIC_TAGGING: description: 'Do you want to enable automatic tagging: true/false' - required: false + required: true BOARD_COLUMN_OPENED: description: 'The case-sensitive column name of the column you would like the task to be moved to once the PR has been opened' required: false - default: '' + default: 'Testing ROX' BOARD_COLUMN_MERGED: description: 'The case-sensitive column name of the column you would like the task to be moved to once the PR has been merged' required: false - default: '' + default: 'Testing klant/PO' BOARD_COLUMN_CLOSED: description: 'The case-sensitive column name of the column you would like the task to be moved to if the PR was closed without being merged' required: false - default: '' + default: 'To do' + BOARD_COLUMN_FEEDBACK: + description: 'The case-sensitive column name of the column you would like the task to be moved to when the PR receives feedback' + required: false + default: 'In progress' runs: using: 'docker' image: 'Dockerfile' @@ -39,3 +43,4 @@ runs: - ${{ inputs.BOARD_COLUMN_OPENED }} - ${{ inputs.BOARD_COLUMN_MERGED }} - ${{ inputs.BOARD_COLUMN_CLOSED }} + - ${{ inputs.BOARD_COLUMN_FEEDBACK }} diff --git a/src/github.sh b/src/github.sh index 726b906b..36cb7bed 100644 --- a/src/github.sh +++ b/src/github.sh @@ -37,7 +37,7 @@ github::get_pr_title() { } github::get_pr_patch_stats() { - jq --raw-output '.pull_request | "\(.commits) \(.changed_files) \(.additions) \(.deletions)"' "$GITHUB_EVENT_PATH" + jq --raw-output '.pull_request | "\(.commits) \(.changed_files) \(.additions) \(.deletions)"' "$GITHUB_EVENT_PATH" } github::get_pr_merged() { @@ -59,3 +59,9 @@ github::get_review_comment() { github::print_all_data() { cat "$GITHUB_EVENT_PATH" } + +github::get_pr_body_without_task() { + local -r pr_body=$(github::get_pr_body) + local output=$(echo "$pr_body" | sed -n '/^#### Description/,$p') + log::message "$output" +} diff --git a/src/main.sh b/src/main.sh index cf553262..a1040e3c 100644 --- a/src/main.sh +++ b/src/main.sh @@ -20,6 +20,7 @@ main() { export BOARD_COLUMN_OPENED="$5" export BOARD_COLUMN_MERGED="$6" export BOARD_COLUMN_CLOSED="$7" + export BOARD_COLUMN_FEEDBACK="$8" env::set_environment @@ -55,6 +56,8 @@ main() { if [ "$event" == "pull_request" ] && [ "$action" == "opened" ]; then teamwork::pull_request_opened + elif [ "$event" == "pull_request" ] && [ "$action" == "ready_for_review" ]; then + teamwork::pull_request_opened elif [ "$event" == "pull_request" ] && [ "$action" == "closed" ]; then teamwork::pull_request_closed elif [ "$event" == "pull_request_review" ] && [ "$action" == "submitted" ]; then diff --git a/src/teamwork.sh b/src/teamwork.sh index b3c5e687..97062e1f 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -6,7 +6,7 @@ teamwork::get_task_id_from_body() { pat='tasks\/([0-9]{1,})' while [[ $body =~ $pat ]]; do - task_ids+=( "${BASH_REMATCH[1]}" ) + task_ids+=("${BASH_REMATCH[1]}") body=${body#*"${BASH_REMATCH[0]}"} done @@ -25,7 +25,7 @@ teamwork::get_project_id_from_task() { fi response=$( - curl "$TEAMWORK_URI/projects/api/v1/tasks/$task_id.json" -u "$TEAMWORK_API_TOKEN"':' |\ + curl "$TEAMWORK_URI/projects/api/v1/tasks/$task_id.json" -u "$TEAMWORK_API_TOKEN"':' | jq -r '.["todo-item"]["project-id"]' ) echo "$response" @@ -44,7 +44,7 @@ teamwork::get_matching_board_column_id() { fi response=$( - curl "$TEAMWORK_URI/projects/$TEAMWORK_PROJECT_ID/boards/columns.json" -u "$TEAMWORK_API_TOKEN"':' |\ + curl "$TEAMWORK_URI/projects/$TEAMWORK_PROJECT_ID/boards/columns.json" -u "$TEAMWORK_API_TOKEN"':' | jq -r --arg column_name "$column_name" '[.columns[] | select(.name | contains($column_name))] | map(.id)[0]' ) @@ -76,15 +76,16 @@ teamwork::move_task_to_column() { fi response=$(curl -X "PUT" "$TEAMWORK_URI/tasks/$TEAMWORK_TASK_ID.json" \ - -u "$TEAMWORK_API_TOKEN"':' \ - -H 'Content-Type: application/json; charset=utf-8' \ - -d "{ \"todo-item\": { \"columnId\": $column_id } }" ) + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"todo-item\": { \"columnId\": $column_id } }") log::message "$response" } teamwork::add_comment() { local -r body=$1 + local -r notify="${2:-false}" if [ "$ENV" == "test" ]; then log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Comment: ${body//\"/}" @@ -92,9 +93,9 @@ teamwork::add_comment() { fi response=$(curl -X "POST" "$TEAMWORK_URI/tasks/$TEAMWORK_TASK_ID/comments.json" \ - -u "$TEAMWORK_API_TOKEN"':' \ - -H 'Content-Type: application/json; charset=utf-8' \ - -d "{ \"comment\": { \"body\": \"${body//\"/}\", \"notify\": true, \"content-type\": \"text\", \"isprivate\": false } }" ) + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"comment\": { \"body\": \"${body//\"/}\", \"notify\": $notify, \"content-type\": \"text\", \"isprivate\": false } }") log::message "$response" } @@ -109,14 +110,25 @@ teamwork::add_tag() { if [ "$AUTOMATIC_TAGGING" == true ]; then response=$(curl -X "PUT" "$TEAMWORK_URI/tasks/$TEAMWORK_TASK_ID/tags.json" \ - -u "$TEAMWORK_API_TOKEN"':' \ - -H 'Content-Type: application/json; charset=utf-8' \ - -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" } }" ) + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" } }") log::message "$response" fi } +teamwork::update_estimation() { + local -r estimation=$1 + + response=$(curl -X "PUT" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID.json" \ + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"todo-item\": { \"estimated-minutes\": $estimation } }") + + log::message "$response" +} + teamwork::remove_tag() { local -r tag_name=$1 @@ -127,9 +139,9 @@ teamwork::remove_tag() { if [ "$AUTOMATIC_TAGGING" == true ]; then response=$(curl -X "PUT" "$TEAMWORK_URI/tasks/$TEAMWORK_TASK_ID/tags.json" \ - -u "$TEAMWORK_API_TOKEN"':' \ - -H 'Content-Type: application/json; charset=utf-8' \ - -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }" ) + -u "$TEAMWORK_API_TOKEN"':' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }") log::message "$response" fi @@ -138,30 +150,12 @@ teamwork::remove_tag() { teamwork::pull_request_opened() { local -r pr_url=$(github::get_pr_url) local -r pr_title=$(github::get_pr_title) - local -r head_ref=$(github::get_head_ref) - local -r base_ref=$(github::get_base_ref) local -r user=$(github::get_sender_user) - local -r pr_stats=$(github::get_pr_patch_stats) - local -r pr_body=$(github::get_pr_body) - IFS=" " read -r -a pr_stats_array <<< "$pr_stats" - - teamwork::add_comment " -**$user** opened a PR: **$pr_title** -[$pr_url]($pr_url) -\`$base_ref\` ⬅️ \`$head_ref\` - ---- -${pr_body} - ---- + teamwork::add_comment "**$user** opened the [$pr_title]($pr_url) PR for this task." -🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ➕ ${pr_stats_array[2]} additions / ➖ ${pr_stats_array[3]} deletions - - " - - teamwork::add_tag "PR Open" teamwork::move_task_to_column "$BOARD_COLUMN_OPENED" + teamwork::update_estimation 15 } teamwork::pull_request_closed() { @@ -169,24 +163,19 @@ teamwork::pull_request_closed() { local -r pr_url=$(github::get_pr_url) local -r pr_title=$(github::get_pr_title) local -r pr_merged=$(github::get_pr_merged) + local -r pr_body=$(github::get_pr_body_without_task) if [ "$pr_merged" == "true" ]; then teamwork::add_comment " -**$user** merged a PR: **$pr_title** -[$pr_url]($pr_url) -" - teamwork::add_tag "PR Merged" - teamwork::remove_tag "PR Open" - teamwork::remove_tag "PR Approved" - teamwork::move_task_to_column "$BOARD_COLUMN_MERGED" +**$user** merged the [$pr_title]($pr_url) PR for this task: + +${pr_body} + " + teamwork::move_task_to_column "$BOARD_COLUMN_MERGED" + teamwork::update_estimation 0 else - teamwork::add_comment " -**$user** closed a PR without merging: **$pr_title** -[$pr_url]($pr_url) -" - teamwork::remove_tag "PR Open" - teamwork::remove_tag "PR Approved" - teamwork::move_task_to_column "$BOARD_COLUMN_CLOSED" + teamwork::add_comment "**$user** closed the [$pr_title]($pr_url) PR for this task." + teamwork::move_task_to_column "$BOARD_COLUMN_FEEDBACK" fi } @@ -195,24 +184,15 @@ teamwork::pull_request_review_submitted() { local -r pr_url=$(github::get_pr_url) local -r pr_title=$(github::get_pr_title) local -r review_state=$(github::get_review_state) - local -r comment=$(github::get_review_comment) - - # Only add a message if the PR has been approved - if [ "$review_state" == "approved" ]; then - teamwork::add_comment " -**$user** submitted a review to the PR: **$pr_title** -[$pr_url]($pr_url) - ---- -Review: **$review_state** -$comment -" - teamwork::add_tag "PR Approved" + if [ "$review_state" == "changes_requested" ]; then + teamwork::move_task_to_column "$BOARD_COLUMN_FEEDBACK" + teamwork::add_comment "**$user** requested changes to the [$pr_title]($pr_url) PR for this task." fi } teamwork::pull_request_review_dismissed() { local -r user=$(github::get_sender_user) - teamwork::add_comment "Review dismissed by $user" + teamwork::move_task_to_column "$BOARD_COLUMN_OPENED" + teamwork::add_comment "Review on the [$pr_title]($pr_url) PR for this task dismissed by **$user**." }