Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. -->

[Test Task](https://twtest.teamwork.com/#/tasks/20613952) <!-- Dummy test task to make sure the test job runs - replace with real link where necessary. -->
12 changes: 2 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
name: teamwork

on:
push:
branches: [master]
pull_request:
pull_request_review:
types: [submitted, dismissed]

jobs:
build:
runs-on: ubuntu-latest
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
29 changes: 0 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -24,29 +21,3 @@ Each directory in `tests/cases` is a test case:
`./tests/run.sh <filter>` only runs the cases whose name contains the filter.

To add a case, create its `event.json` and `inputs`, run `./tests/run.sh --update <case name>` 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
```
4 changes: 0 additions & 4 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[*]}
Expand Down
33 changes: 0 additions & 33 deletions src/teamwork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]'
}
Expand All @@ -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.
Expand Down Expand Up @@ -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"
Expand All @@ -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 } }')
Expand All @@ -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
Expand All @@ -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
Expand Down
21 changes: 0 additions & 21 deletions tests/events/pull_request_approved.json

This file was deleted.

18 changes: 0 additions & 18 deletions tests/events/pull_request_closed.json

This file was deleted.

18 changes: 0 additions & 18 deletions tests/events/pull_request_merged.json

This file was deleted.

25 changes: 0 additions & 25 deletions tests/events/pull_request_opened.json

This file was deleted.

Loading