|
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 test-robot-done label from the PR if present and adds a comment." |
| 3 | + |
| 4 | +inputs: |
| 5 | + label-test-robot-needed: |
| 6 | + description: 'Label name indicating the PR needs robot testing' |
| 7 | + required: false |
| 8 | + default: 'test-robot-needed' |
| 9 | + label-test-robot-done: |
| 10 | + description: 'Label name indicating the PR has been test-robot-done' |
| 11 | + required: false |
| 12 | + default: 'test-robot-done' |
| 13 | + |
| 14 | +runs: |
| 15 | + using: "composite" |
| 16 | + steps: |
| 17 | + - name: Remove test-robot-done 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-test-robot-done }} |
| 25 | + LABEL_ROBOT_TEST_NEEDED: ${{ inputs.label-test-robot-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 |
0 commit comments