Skip to content

Commit 1b1f819

Browse files
wip
1 parent 8d60b1e commit 1b1f819

3 files changed

Lines changed: 80 additions & 9 deletions

File tree

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
# General: "robot-tested" should be the default value of an input.
2-
# 1. It should check if "robot-tested" label is present.
3-
# 2. If present, it should add a comment saying "PR is marked as robot-tested.". it should also include the commit sha, (only if available), it was marked for.
4-
# 3.
1+
name: "Test Label"
2+
description: "Checks if the robot-tested label is present on the PR and adds a confirming comment."
3+
4+
inputs:
5+
label-robot-tested:
6+
description: 'Label name indicating the PR has been robot-tested'
7+
required: false
8+
default: 'robot-tested'
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Check robot-tested label and add comment
14+
shell: bash
15+
env:
16+
GH_TOKEN: ${{ github.token }}
17+
PR_NUMBER: ${{ github.event.pull_request.number }}
18+
REPO: ${{ github.repository }}
19+
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
20+
LABEL_ROBOT_TESTED: ${{ inputs.label-robot-tested }}
21+
run: |
22+
LABELS=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels --jq '.labels[].name')
23+
24+
if echo "$LABELS" | grep -qx "$LABEL_ROBOT_TESTED"; then
25+
if [ -n "$COMMIT_SHA" ]; then
26+
COMMENT="PR is marked as \`${LABEL_ROBOT_TESTED}\`. (commit: \`${COMMIT_SHA}\`)"
27+
else
28+
COMMENT="PR is marked as \`${LABEL_ROBOT_TESTED}\`."
29+
fi
30+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$COMMENT"
31+
fi
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
1-
# General: "needs-robot-testing" and "robot-tested" should be the default values of two inputs.
2-
# 1. It should check if "needs-robot-testing" label is present.
3-
# 2. It should check if "robot-tested" label is present.
4-
# 3. If present, it should remove the label.
5-
# 4. If removed, it should add a comment saying the label is removed and also include the commit sha, (only if available), it was removed for. If "needs-robot-testing" was not present, it should also include a warning that the label was removed without "needs-robot-testing" being present.
1+
name: "Test Unlabel"
2+
description: "Removes the robot-tested label from the PR if present and adds a comment."
3+
4+
inputs:
5+
label-robot-test-needed:
6+
description: 'Label name indicating the PR needs robot testing'
7+
required: false
8+
default: 'needs-robot-testing'
9+
label-robot-tested:
10+
description: 'Label name indicating the PR has been robot-tested'
11+
required: false
12+
default: 'robot-tested'
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Remove robot-tested label and add comment
18+
shell: bash
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
PR_NUMBER: ${{ github.event.pull_request.number }}
22+
REPO: ${{ github.repository }}
23+
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
24+
LABEL_ROBOT_TESTED: ${{ inputs.label-robot-tested }}
25+
LABEL_ROBOT_TEST_NEEDED: ${{ inputs.label-robot-test-needed }}
26+
run: |
27+
LABELS=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels --jq '.labels[].name')
28+
29+
NEEDS_TESTING=false
30+
if echo "$LABELS" | grep -qx "$LABEL_ROBOT_TEST_NEEDED"; then
31+
NEEDS_TESTING=true
32+
fi
33+
34+
if echo "$LABELS" | grep -qx "$LABEL_ROBOT_TESTED"; then
35+
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$LABEL_ROBOT_TESTED"
36+
37+
if [ -n "$COMMIT_SHA" ]; then
38+
COMMENT="Label \`${LABEL_ROBOT_TESTED}\` has been removed. (commit: \`${COMMIT_SHA}\`)"
39+
else
40+
COMMENT="Label \`${LABEL_ROBOT_TESTED}\` has been removed."
41+
fi
42+
43+
if [ "$NEEDS_TESTING" = "false" ]; then
44+
COMMENT="${COMMENT}\n\n> [!WARNING]\n> Label \`${LABEL_ROBOT_TESTED}\` was removed without \`${LABEL_ROBOT_TEST_NEEDED}\` being present."
45+
fi
46+
47+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$(printf "%b" "$COMMENT")"
48+
fi

.github/workflows/pull-request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ concurrency:
1111
permissions:
1212
contents: read
1313
packages: write
14+
pull-requests: write
1415

1516
env:
1617
LABEL_ROBOT_TEST_NEEDED: needs-robot-testing

0 commit comments

Comments
 (0)