Skip to content

Commit 6413eee

Browse files
committed
Feature: Lightweight comment
New option to add a small comment to the task only with minimal information. This should help linking pull requests with Teamwork.com tasks without polluting task's discussions.
1 parent 01c7592 commit 6413eee

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
```
5858

5959
## Usage
60-
When creating a new PR, write in the description of the PR the URL of the task. The action will automatically add a comment in the task.
60+
When creating a new PR, write in the description of the PR the URL of the task. The action will automatically add a comment in the task. Optionally, you may choose for a lightweight comment that will only include the PR URL and the user that performed the action, to enable this option set the `LIGHTWEIGHT_COMMENT` input to `true`.
6161

6262
Please note, the comment will be created in Teamwork under the account you have attached to this action. If the API key of the user you are using does not have permissions to access certain projects, the comment will not be created.
6363

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ inputs:
2828
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'
2929
required: false
3030
default: ''
31+
LIGHTWEIGHT_COMMENT:
32+
description: 'Generate tiny comments with minimal information'
33+
required: false
34+
default: 'false'
3135
runs:
3236
using: 'docker'
3337
image: 'Dockerfile'
@@ -39,3 +43,4 @@ runs:
3943
- ${{ inputs.BOARD_COLUMN_OPENED }}
4044
- ${{ inputs.BOARD_COLUMN_MERGED }}
4145
- ${{ inputs.BOARD_COLUMN_CLOSED }}
46+
- ${{ inputs.LIGHTWEIGHT_COMMENT }}

src/main.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ main() {
2020
export BOARD_COLUMN_OPENED="$5"
2121
export BOARD_COLUMN_MERGED="$6"
2222
export BOARD_COLUMN_CLOSED="$7"
23+
export LIGHTWEIGHT_COMMENT="$8"
2324

2425
env::set_environment
2526

src/teamwork.sh

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ teamwork::pull_request_opened() {
145145
local -r pr_body=$(github::get_pr_body)
146146
IFS=" " read -r -a pr_stats_array <<< "$pr_stats"
147147

148-
teamwork::add_comment "
148+
if [ "$LIGHTWEIGHT_COMMENT" == "true" ]; then
149+
teamwork::add_comment "[PR]($pr_url) opened by $user"
150+
else
151+
teamwork::add_comment "
149152
**$user** opened a PR: **$pr_title**
150153
[$pr_url]($pr_url)
151154
\`$base_ref\` ⬅️ \`$head_ref\`
@@ -158,7 +161,8 @@ ${pr_body}
158161
159162
🔢 ${pr_stats_array[0]} commits / 📝 ${pr_stats_array[1]} files updated / ➕ ${pr_stats_array[2]} additions / ➖ ${pr_stats_array[3]} deletions
160163
161-
"
164+
"
165+
fi
162166

163167
teamwork::add_tag "PR Open"
164168
teamwork::move_task_to_column "$BOARD_COLUMN_OPENED"
@@ -171,19 +175,27 @@ teamwork::pull_request_closed() {
171175
local -r pr_merged=$(github::get_pr_merged)
172176

173177
if [ "$pr_merged" == "true" ]; then
174-
teamwork::add_comment "
178+
if [ "$LIGHTWEIGHT_COMMENT" == "true" ]; then
179+
teamwork::add_comment "[PR]($pr_url) merged by $user"
180+
else
181+
teamwork::add_comment "
175182
**$user** merged a PR: **$pr_title**
176183
[$pr_url]($pr_url)
177184
"
178-
teamwork::add_tag "PR Merged"
179-
teamwork::remove_tag "PR Open"
180-
teamwork::remove_tag "PR Approved"
181-
teamwork::move_task_to_column "$BOARD_COLUMN_MERGED"
185+
fi
186+
teamwork::add_tag "PR Merged"
187+
teamwork::remove_tag "PR Open"
188+
teamwork::remove_tag "PR Approved"
189+
teamwork::move_task_to_column "$BOARD_COLUMN_MERGED"
182190
else
183-
teamwork::add_comment "
191+
if [ "$LIGHTWEIGHT_COMMENT" == "true" ]; then
192+
teamwork::add_comment "[PR]($pr_url) closed without merging by $user"
193+
else
194+
teamwork::add_comment "
184195
**$user** closed a PR without merging: **$pr_title**
185196
[$pr_url]($pr_url)
186197
"
198+
fi
187199
teamwork::remove_tag "PR Open"
188200
teamwork::remove_tag "PR Approved"
189201
teamwork::move_task_to_column "$BOARD_COLUMN_CLOSED"
@@ -199,7 +211,10 @@ teamwork::pull_request_review_submitted() {
199211

200212
# Only add a message if the PR has been approved
201213
if [ "$review_state" == "approved" ]; then
202-
teamwork::add_comment "
214+
if [ "$LIGHTWEIGHT_COMMENT" == "true" ]; then
215+
teamwork::add_comment "[PR]($pr_url) approved by $user"
216+
else
217+
teamwork::add_comment "
203218
**$user** submitted a review to the PR: **$pr_title**
204219
[$pr_url]($pr_url)
205220
@@ -208,6 +223,7 @@ teamwork::pull_request_review_submitted() {
208223
Review: **$review_state**
209224
$comment
210225
"
226+
fi
211227
teamwork::add_tag "PR Approved"
212228
fi
213229
}

0 commit comments

Comments
 (0)