From ec26ade5a851c31161cccfcbc374d6783c259d52 Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Mon, 15 Jul 2024 12:14:03 -0400 Subject: [PATCH 1/2] Add support for moving tasks to board columns based on the pr state - Adds moving the task to a column when the review is approved - Adds moving the task to a column when changes are requested through the review - Adds a changes requested tag when using the automatic tagging --- .gitignore | 1 + action.yml | 10 +++++++++ src/main.sh | 6 ++++-- src/teamwork.sh | 13 ++++++++++++ .../pull_request_changes_requested.json | 21 +++++++++++++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 tests/events/pull_request_changes_requested.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9f11b755 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/action.yml b/action.yml index f704b08a..33a1659a 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,14 @@ inputs: 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: '' + BOARD_COLUMN_APPROVED: + description: 'The case-sensitive column name of the column you would like the task to be moved to once the PR has been approved' + required: false + default: '' + BOARD_COLUMN_CHANGES_REQUESTED: + description: 'The case-sensitive column name of the column you would like the task to be moved to once the PR has changes requested' + required: false + default: '' 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 @@ -37,5 +45,7 @@ runs: - ${{ inputs.TEAMWORK_API_TOKEN }} - ${{ inputs.AUTOMATIC_TAGGING }} - ${{ inputs.BOARD_COLUMN_OPENED }} + - ${{ inputs.BOARD_COLUMN_APPROVED }} + - ${{ inputs.BOARD_COLUMN_CHANGES_REQUESTED }} - ${{ inputs.BOARD_COLUMN_MERGED }} - ${{ inputs.BOARD_COLUMN_CLOSED }} diff --git a/src/main.sh b/src/main.sh index cf553262..b04df883 100644 --- a/src/main.sh +++ b/src/main.sh @@ -18,8 +18,10 @@ main() { 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 BOARD_COLUMN_APPROVED="$6" + export BOARD_COLUMN_CHANGES_REQUESTED="$7" + export BOARD_COLUMN_MERGED="$8" + export BOARD_COLUMN_CLOSED="$9" env::set_environment diff --git a/src/teamwork.sh b/src/teamwork.sh index b3c5e687..10081b72 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -209,6 +209,19 @@ Review: **$review_state** $comment " teamwork::add_tag "PR Approved" + teamwork::move_task_to_column "$BOARD_COLUMN_APPROVED" + elif [ "$review_state" == "changes_requested" ]; then + teamwork::add_comment " +**$user** requested changes to the PR: **$pr_title** +[$pr_url]($pr_url) + +--- + +Review: **$review_state** +$comment +" + teamwork::add_tag "PR Changes Requested" + teamwork::move_task_to_column "$BOARD_COLUMN_CHANGES_REQUESTED" fi } diff --git a/tests/events/pull_request_changes_requested.json b/tests/events/pull_request_changes_requested.json new file mode 100644 index 00000000..c17b124d --- /dev/null +++ b/tests/events/pull_request_changes_requested.json @@ -0,0 +1,21 @@ +{ + "action": "submitted", + "number": 1, + "pull_request": { + "body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456", + "head": { + "repo": { + "full_name": "teamwork/github-sync" + } + }, + "html_url": "https://github.com/teamwork/github-sync/pull/2", + "title": "This is an example of a title for the PR." + }, + "review": { + "state": "changes_requested", + "body": "This is the comment of the review." + }, + "sender": { + "login": "username" + } +} From f934e2814c8ffd1efc99f99731218a23eb914e46 Mon Sep 17 00:00:00 2001 From: Michael Deck Date: Mon, 15 Jul 2024 14:00:24 -0400 Subject: [PATCH 2/2] Update test and readme --- .github/workflows/test.yml | 3 ++- README.md | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bab5c6c..2cf0c85f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TEAMWORK_URI: "localhost" TEAMWORK_API_TOKEN: "test_api_token" - AUTOMATIC_TAGGING: true BOARD_COLUMN_OPENED: "PR Open" + BOARD_COLUMN_APPROVED: 'PR Approved' + BOARD_COLUMN_CHANGES_REQUESTED: 'Changes Requested' BOARD_COLUMN_MERGED: "Ready to Test" BOARD_COLUMN_CLOSED: "Rejected" diff --git a/README.md b/README.md index 3c54c77b..96e6a151 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ jobs: TEAMWORK_API_TOKEN: ${{ secrets.TEAMWORK_API_TOKEN }} AUTOMATIC_TAGGING: false BOARD_COLUMN_OPENED: 'PR Open' + BOARD_COLUMN_APPROVED: 'PR Approved' + BOARD_COLUMN_CHANGES_REQUESTED: 'Changes Requested' BOARD_COLUMN_MERGED: 'Ready to Test' BOARD_COLUMN_CLOSED: 'Rejected' env: @@ -73,6 +75,8 @@ Tags are added automatically on the task if you are have the option `AUTOMATIC_T You may also specify columns you'd like the task to be moved to on every stage of the PR: - `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_APPROVED`: The case-sensitive column name of the column you'd like the task to be moved to once the PR has been approved +- `BOARD_COLUMN_CHANGES_REQUESTED`: The case-sensitive column name of the column you'd like the task to be moved to once the PR has changes requested - `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