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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## Setup local environment

* [Install Docker](https://docs.docker.com/get-docker/)
* Install bash 4 or later, curl, jq and python3

## Running the tests

The tests run the action's Docker image against a mock Teamwork API (`tests/mock-teamwork.py`) and check what it sends:
The tests run the action against a mock Teamwork API (`tests/mock-teamwork.py`) and check what it sends:

```
./tests/run.sh
Expand Down
8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Create the next environment vars in your repository:
**Please Note:** The Teamwork account associated with this API key is the account which these comments will be created under. If this user does not have permission to access a task's project, that task will be skipped and the workflow run will be marked as failed.

### Installation
The action runs on any runner with bash 4 or later, curl and jq. GitHub-hosted Ubuntu runners have them.

Create a new file `/.github/workflows/teamwork.yml` with the following:

```yaml
Expand Down
32 changes: 15 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,18 @@ inputs:
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
# Secrets stay out of args, which show up in the runner's process list. The
# Teamwork token is read from its INPUT_TEAMWORK_API_TOKEN env var instead,
# and the empty slots keep the other args in place.
args:
- ''
- ${{ inputs.TEAMWORK_URI }}
- ''
- ${{ inputs.AUTOMATIC_TAGGING }}
- ${{ inputs.WORKFLOW_STAGE_OPENED }}
- ${{ inputs.WORKFLOW_STAGE_MERGED }}
- ${{ inputs.WORKFLOW_STAGE_CLOSED }}
- ${{ inputs.LIGHTWEIGHT_COMMENT }}
- ${{ inputs.BOARD_COLUMN_OPENED }}
- ${{ inputs.BOARD_COLUMN_MERGED }}
- ${{ inputs.BOARD_COLUMN_CLOSED }}
using: 'composite'
steps:
- shell: bash
run: bash "$GITHUB_ACTION_PATH/entrypoint.sh"
env:
INPUT_TEAMWORK_URI: ${{ inputs.TEAMWORK_URI }}
INPUT_TEAMWORK_API_TOKEN: ${{ inputs.TEAMWORK_API_TOKEN }}
INPUT_AUTOMATIC_TAGGING: ${{ inputs.AUTOMATIC_TAGGING }}
INPUT_WORKFLOW_STAGE_OPENED: ${{ inputs.WORKFLOW_STAGE_OPENED }}
INPUT_WORKFLOW_STAGE_MERGED: ${{ inputs.WORKFLOW_STAGE_MERGED }}
INPUT_WORKFLOW_STAGE_CLOSED: ${{ inputs.WORKFLOW_STAGE_CLOSED }}
INPUT_LIGHTWEIGHT_COMMENT: ${{ inputs.LIGHTWEIGHT_COMMENT }}
INPUT_BOARD_COLUMN_OPENED: ${{ inputs.BOARD_COLUMN_OPENED }}
INPUT_BOARD_COLUMN_MERGED: ${{ inputs.BOARD_COLUMN_MERGED }}
INPUT_BOARD_COLUMN_CLOSED: ${{ inputs.BOARD_COLUMN_CLOSED }}
6 changes: 1 addition & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ set -euo pipefail

PROJECT_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

if [ "$PROJECT_HOME" == "/" ]; then
PROJECT_HOME=""
fi

export PROJECT_HOME

# shellcheck disable=SC1090
source "$PROJECT_HOME/src/main.sh"

main "$@"
main

exit $?
7 changes: 7 additions & 0 deletions src/ensure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ ensure::env_variable_exist() {
exit 1
fi
}

ensure::command_exist() {
if ! command -v "$1" >/dev/null 2>&1; then
log::error "The command $1 is required. Install it on the runner."
exit 1
fi
}
4 changes: 2 additions & 2 deletions src/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ github::get_action() {

github::get_pr_body() {
jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" |\
awk '/^[[:space:]]*(```|~~~)/ { fenced = !fenced } !fenced { sub(/^#{1,3} /, "#### ") } { print }'
awk '/^[[:space:]]*(```|~~~)/ { fenced = !fenced } !fenced { sub(/^##?#? /, "#### ") } { print }'
}

github::get_head_ref() {
Expand All @@ -26,7 +26,7 @@ github::get_pr_url() {
}

github::get_pr_title() {
jq --raw-output '.pull_request.title | trim' "$GITHUB_EVENT_PATH"
jq --raw-output '.pull_request.title | sub("^\\s+"; "") | sub("\\s+$"; "")' "$GITHUB_EVENT_PATH"
}

github::get_pr_patch_stats() {
Expand Down
28 changes: 14 additions & 14 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ source "$PROJECT_HOME/src/teamwork.sh"
main() {
log::message "Running the process..."

# Ensure env vars and args exist
# Ensure env vars and tools exist
ensure::env_variable_exist "GITHUB_REPOSITORY"
ensure::env_variable_exist "GITHUB_EVENT_PATH"
ensure::env_variable_exist "GITHUB_EVENT_NAME"

# $1 used to be GITHUB_TOKEN, which was never needed. The Teamwork token comes
# from the env var GitHub creates for the input, so it isn't on the command
# line; $3 is the fallback for running the image by hand.
export TEAMWORK_URI="$2"
export TEAMWORK_API_TOKEN="${INPUT_TEAMWORK_API_TOKEN:-$3}"
export AUTOMATIC_TAGGING="$4"
export WORKFLOW_STAGE_OPENED="$5"
export WORKFLOW_STAGE_MERGED="$6"
export WORKFLOW_STAGE_CLOSED="$7"
export LIGHTWEIGHT_COMMENT="$8"
ensure::command_exist "curl"
ensure::command_exist "jq"

export TEAMWORK_URI="${INPUT_TEAMWORK_URI:-}"
export TEAMWORK_API_TOKEN="${INPUT_TEAMWORK_API_TOKEN:-}"
export AUTOMATIC_TAGGING="${INPUT_AUTOMATIC_TAGGING:-}"
export WORKFLOW_STAGE_OPENED="${INPUT_WORKFLOW_STAGE_OPENED:-}"
export WORKFLOW_STAGE_MERGED="${INPUT_WORKFLOW_STAGE_MERGED:-}"
export WORKFLOW_STAGE_CLOSED="${INPUT_WORKFLOW_STAGE_CLOSED:-}"
export LIGHTWEIGHT_COMMENT="${INPUT_LIGHTWEIGHT_COMMENT:-}"
# BOARD_COLUMN_* are deprecated aliases kept for backwards compatibility.
export BOARD_COLUMN_OPENED="${9:-}"
export BOARD_COLUMN_MERGED="${10:-}"
export BOARD_COLUMN_CLOSED="${11:-}"
export BOARD_COLUMN_OPENED="${INPUT_BOARD_COLUMN_OPENED:-}"
export BOARD_COLUMN_MERGED="${INPUT_BOARD_COLUMN_MERGED:-}"
export BOARD_COLUMN_CLOSED="${INPUT_BOARD_COLUMN_CLOSED:-}"

# Fall back to the deprecated BOARD_COLUMN_* inputs when their WORKFLOW_STAGE_*
# replacements are not set.
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/bearer-token/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/closed-merged-lightweight/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/closed-merged/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/closed-unmerged-lightweight/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/closed-unmerged/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/comment-fails/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1003",
"body": "Task: http://localhost:8080/app/tasks/1003",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/deprecated-board-column-closed/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/deprecated-board-column/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/ignored-project/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Tasks: http://teamwork:8080/app/tasks/1001 and http://teamwork:8080/app/tasks/1002",
"body": "Tasks: http://localhost:8080/app/tasks/1001 and http://localhost:8080/app/tasks/1002",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/opened-lightweight/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Handle \"null\" in C:\\temp",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/opened/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add \"OAuth\" login",
"body": "## Summary\r\nAdds OAuth login for http://teamwork:8080/app/tasks/1001\r\n\r\n```sh\r\n# configure the \"client\" secret\r\nexport CONFIG_DIR=C:\\Users\\dev\\config\r\n```",
"body": "## Summary\r\nAdds OAuth login for http://localhost:8080/app/tasks/1001\r\n\r\n```sh\r\n# configure the \"client\" secret\r\nexport CONFIG_DIR=C:\\Users\\dev\\config\r\n```",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/opened/expected
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ POST /tasks/1001/comments.json -> 201
| ---
|
| #### Summary␍
| Adds OAuth login for http://teamwork:8080/app/tasks/1001␍
| Adds OAuth login for http://localhost:8080/app/tasks/1001␍
| ␍
| ```sh␍
| # configure the "client" secret␍
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/review-approved-lightweight/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/review-approved-no-body/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/review-approved/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/review-commented/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/review-dismissed/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/stage-not-found/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/tagging-disabled/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/task-links/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Linked twice: [http://teamwork:8080/app/tasks/1001](http://teamwork:8080/app/tasks/1001)\nUpper case, old route: HTTP://TEAMWORK:8080/#/tasks/1002\nAgain: http://teamwork:8080/#tasks/1001\nNot task links: subtasks/5, https://github.com/acme/webapp/blob/main/scripts/tasks/2024_cleanup.py\nAnother Teamwork site: https://acme.teamwork.com/app/tasks/1003\nLook-alike host: http://evil-teamwork:8080/app/tasks/1003",
"body": "Linked twice: [http://localhost:8080/app/tasks/1001](http://localhost:8080/app/tasks/1001)\nUpper case, old route: HTTP://LOCALHOST:8080/#/tasks/1002\nAgain: http://localhost:8080/#tasks/1001\nNot task links: subtasks/5, https://github.com/acme/webapp/blob/main/scripts/tasks/2024_cleanup.py\nAnother Teamwork site: https://acme.teamwork.com/app/tasks/1003\nLook-alike host: http://evil-localhost:8080/app/tasks/1003",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/task-not-found/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Tasks: http://teamwork:8080/app/tasks/9999 and http://teamwork:8080/app/tasks/1001",
"body": "Tasks: http://localhost:8080/app/tasks/9999 and http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/unsupported-event/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/wrong-bearer-token/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/wrong-token/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pull_request": {
"number": 42,
"title": "Add OAuth login",
"body": "Task: http://teamwork:8080/app/tasks/1001",
"body": "Task: http://localhost:8080/app/tasks/1001",
"html_url": "https://github.com/acme/webapp/pull/42",
"head": {
"ref": "feature/oauth",
Expand Down
Loading