From 27efa5b41ad15743dc33d0079a52a7c5d3335e06 Mon Sep 17 00:00:00 2001 From: Marc Izquierdo Date: Tue, 20 Oct 2026 19:58:58 +0200 Subject: [PATCH] Remove the test mode With the tests running the real code against a mock Teamwork API, the "skip the request in test mode" branches only kept CI from exercising the code. Remove them, along with the uses: ./ CI step that relied on them, the old event fixtures and act instructions, and the dummy task link in the PR template. Co-Authored-By: Claude Opus 5.5 --- .github/PULL_REQUEST_TEMPLATE.md | 2 -- .github/workflows/test.yml | 12 ++------- CONTRIBUTING.md | 29 ---------------------- src/main.sh | 4 --- src/misc.sh | 8 ------ src/teamwork.sh | 33 ------------------------- tests/events/pull_request_approved.json | 21 ---------------- tests/events/pull_request_closed.json | 18 -------------- tests/events/pull_request_merged.json | 18 -------------- tests/events/pull_request_opened.json | 25 ------------------- 10 files changed, 2 insertions(+), 168 deletions(-) delete mode 100644 tests/events/pull_request_approved.json delete mode 100644 tests/events/pull_request_closed.json delete mode 100644 tests/events/pull_request_merged.json delete mode 100644 tests/events/pull_request_opened.json diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 9ab77a04..b9d1bb8b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1 @@ - -[Test Task](https://twtest.teamwork.com/#/tasks/20613952) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 368dd45d..0228a287 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,9 +1,9 @@ name: teamwork on: + push: + branches: [master] pull_request: - pull_request_review: - types: [submitted, dismissed] jobs: build: @@ -11,13 +11,5 @@ jobs: name: Ensure this project runs steps: - uses: actions/checkout@v5 - - uses: ./ - with: - TEAMWORK_URI: "localhost" - TEAMWORK_API_TOKEN: "test_api_token" - AUTOMATIC_TAGGING: true - WORKFLOW_STAGE_OPENED: "PR Open" - WORKFLOW_STAGE_MERGED: "Ready to Test" - WORKFLOW_STAGE_CLOSED: "Rejected" - name: Run the tests against a mock Teamwork API run: ./tests/run.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aca161b8..18c132e5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,11 +1,8 @@ # Contributing -## Getting started - ## Setup local environment * [Install Docker](https://docs.docker.com/get-docker/) -* [Install act tool](https://github.com/nektos/act) ## Running the tests @@ -24,29 +21,3 @@ Each directory in `tests/cases` is a test case: `./tests/run.sh ` only runs the cases whose name contains the filter. To add a case, create its `event.json` and `inputs`, run `./tests/run.sh --update ` to record its `expected` file, and check that file is right before committing it. The mock's data (which tasks exist, their projects and the workflow stages) is at the top of `tests/mock-teamwork.py`. - -## Usage - -Simulate a new pull request - -``` -act pull_request -e tests/events/pull_request_opened.json -``` - -Simulate a pull request has been approved - -``` -act pull_request_review -e tests/events/pull_request_approved.json -``` - -Simulate a pull request has been merged - -``` -act pull_request -e tests/events/pull_request_merged.json -``` - -Simulate a pull request has been closed without merging - -``` -act pull_request -e tests/events/pull_request_closed.json -``` diff --git a/src/main.sh b/src/main.sh index e1db5e0d..0cc5af6f 100644 --- a/src/main.sh +++ b/src/main.sh @@ -35,8 +35,6 @@ main() { : "${WORKFLOW_STAGE_MERGED:=$BOARD_COLUMN_MERGED}" : "${WORKFLOW_STAGE_CLOSED:=$BOARD_COLUMN_CLOSED}" - 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" ) @@ -62,8 +60,6 @@ main() { handler=teamwork::pull_request_review_submitted elif [ "$event" == "pull_request_review" ] && [ "$action" == "dismissed" ]; then handler=teamwork::pull_request_review_dismissed - elif [ "$ENV" == "test" ]; then # always run pull_request_opened at the very least when in test - handler=teamwork::pull_request_opened else log::message "Operation not allowed" exit 0 diff --git a/src/misc.sh b/src/misc.sh index fe935ea9..33ea2037 100644 --- a/src/misc.sh +++ b/src/misc.sh @@ -9,14 +9,6 @@ log::message() { echo "$@" } -env::set_environment() { - if [ "$TEAMWORK_URI" == "localhost" ] && [ "$TEAMWORK_API_TOKEN" == "test_api_token" ]; then - export ENV="test" - else - export ENV="prod" - fi -} - utils::in_array() { ARRAY=$2 for e in ${ARRAY[*]} diff --git a/src/teamwork.sh b/src/teamwork.sh index 260c43f8..9b421cd4 100644 --- a/src/teamwork.sh +++ b/src/teamwork.sh @@ -12,9 +12,6 @@ teamwork::get_task_id_from_body() { host=${host#*://} host=${host%%[/?#]*} host=${host//./[.]} - if [ "$ENV" == "test" ]; then - host='[a-z0-9.-]+' # test events link to placeholder sites - fi local -r pat="(^|[^a-z0-9.-])${host}(/[^][()<>[:space:]]*)?[/#]tasks/([0-9]+)" while [[ $body =~ $pat ]]; do @@ -55,11 +52,6 @@ teamwork::request_failed() { teamwork::get_project_id_from_task() { local -r task_id=$1 - if [ "$ENV" == "test" ]; then - echo "$task_id" - return - fi - teamwork::request GET "/projects/api/v1/tasks/$task_id.json" |\ jq -r '.["todo-item"]["project-id"]' } @@ -76,11 +68,6 @@ teamwork::get_workflow_stage() { return fi - if [ "$ENV" == "test" ]; then - echo "$TEAMWORK_PROJECT_ID $TEAMWORK_PROJECT_ID" - return - fi - # A single call scoped to the project sideloads every stage across the # project's workflow(s); each stage carries its parent workflow id, which the # move endpoint also needs. @@ -110,11 +97,6 @@ teamwork::move_task_to_stage() { local workflow_id stage_id read -r workflow_id stage_id <<< "$stage" - if [ "$ENV" == "test" ]; then - log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Project ID: $TEAMWORK_PROJECT_ID - Workflow ID: $workflow_id - Stage ID: $stage_id" - return - fi - if ! response=$(teamwork::request PATCH "/projects/api/v3/tasks/$TEAMWORK_TASK_ID/workflows/$workflow_id.json" \ "{ \"stageId\": $stage_id, \"positionAfterTask\": -1 }"); then teamwork::request_failed "Failed to move task $TEAMWORK_TASK_ID to the '$stage_name' workflow stage: $response" @@ -127,11 +109,6 @@ teamwork::move_task_to_stage() { teamwork::add_comment() { local -r body=$1 - if [ "$ENV" == "test" ]; then - log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Comment: $body" - return - fi - # jq escapes the body (quotes, backslashes, newlines...) into valid JSON local -r payload=$(jq -n --arg body "$body" \ '{ comment: { body: $body, notify: true, "content-type": "text", isprivate: false } }') @@ -147,11 +124,6 @@ teamwork::add_comment() { teamwork::add_tag() { local -r tag_name=$1 - if [ "$ENV" == "test" ]; then - log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Tag Added: ${tag_name//\"/}" - return - fi - if [ "$AUTOMATIC_TAGGING" == true ]; then if ! response=$(teamwork::request PUT "/tasks/$TEAMWORK_TASK_ID/tags.json" \ "{ \"tags\": { \"content\": \"${tag_name//\"/}\" } }"); then @@ -166,11 +138,6 @@ teamwork::add_tag() { teamwork::remove_tag() { local -r tag_name=$1 - if [ "$ENV" == "test" ]; then - log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Tag Removed: ${tag_name//\"/}" - return - fi - if [ "$AUTOMATIC_TAGGING" == true ]; then if ! response=$(teamwork::request PUT "/tasks/$TEAMWORK_TASK_ID/tags.json" \ "{ \"tags\": { \"content\": \"${tag_name//\"/}\" },\"removeProvidedTags\":\"true\" }"); then diff --git a/tests/events/pull_request_approved.json b/tests/events/pull_request_approved.json deleted file mode 100644 index 2ea240ce..00000000 --- a/tests/events/pull_request_approved.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "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": "approved", - "body": "This is the comment of the review." - }, - "sender": { - "login": "username" - } -} \ No newline at end of file diff --git a/tests/events/pull_request_closed.json b/tests/events/pull_request_closed.json deleted file mode 100644 index 4e6ee486..00000000 --- a/tests/events/pull_request_closed.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "action": "closed", - "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/1", - "title": "This is an example of a title for the PR.", - "merged": false - }, - "sender": { - "login": "username" - } -} \ No newline at end of file diff --git a/tests/events/pull_request_merged.json b/tests/events/pull_request_merged.json deleted file mode 100644 index d3b3998b..00000000 --- a/tests/events/pull_request_merged.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "action": "closed", - "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/1", - "title": "This is an example of a title for the PR.", - "merged": true - }, - "sender": { - "login": "username" - } -} \ No newline at end of file diff --git a/tests/events/pull_request_opened.json b/tests/events/pull_request_opened.json deleted file mode 100644 index 88e64a11..00000000 --- a/tests/events/pull_request_opened.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "action": "opened", - "number": 1, - "pull_request": { - "body": "# Test heading \n This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456", - "head": { - "ref": "pr-branch", - "repo": { - "full_name": "teamwork/github-sync" - } - }, - "base": { - "ref": "main" - }, - "html_url": "https://github.com/teamwork/github-sync/pull/1", - "title": "This is an example of a title for the PR.", - "commits": 1, - "additions": 2, - "deletions": 3, - "changed_files": 4 - }, - "sender": { - "login": "username" - } -}