|
| 1 | +name: "Robot Test Label" |
| 2 | +description: "When the test-robot-done label is added, posts a comment confirming the robot test status." |
| 3 | + |
| 4 | +inputs: |
| 5 | + label-test-robot-needed: |
| 6 | + description: 'Label indicating the PR needs robot testing' |
| 7 | + required: false |
| 8 | + default: 'test-robot-needed' |
| 9 | + label-test-robot-done: |
| 10 | + description: 'Label indicating the PR has been robot-tested' |
| 11 | + required: false |
| 12 | + default: 'test-robot-done' |
| 13 | + token: |
| 14 | + description: 'GitHub token or PAT used to post comments (defaults to github.token)' |
| 15 | + required: false |
| 16 | + default: '' |
| 17 | + |
| 18 | +runs: |
| 19 | + using: "composite" |
| 20 | + steps: |
| 21 | + - name: Comment on label added |
| 22 | + uses: actions/github-script@v7 |
| 23 | + with: |
| 24 | + github-token: ${{ inputs.token || github.token }} |
| 25 | + script: | |
| 26 | + const labelDone = '${{ inputs.label-test-robot-done }}'; |
| 27 | + const labelNeeded = '${{ inputs.label-test-robot-needed }}'; |
| 28 | + const { number: pr, head: { sha } } = context.payload.pull_request; |
| 29 | + const repo = context.repo; |
| 30 | +
|
| 31 | + const postComment = async (body) => { |
| 32 | + try { |
| 33 | + await github.rest.issues.createComment({ ...repo, issue_number: pr, body }); |
| 34 | + } catch (err) { |
| 35 | + core.warning(`Could not post comment: ${err.message}`); |
| 36 | + } |
| 37 | + }; |
| 38 | +
|
| 39 | + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ ...repo, issue_number: pr }); |
| 40 | + const has = new Set(labels.map(l => l.name)); |
| 41 | + const shaLine = sha ? `\n\n**Commit:** \`${sha}\`` : ''; |
| 42 | +
|
| 43 | + if (!has.has(labelDone)) { |
| 44 | + if (has.has(labelNeeded)) { |
| 45 | + core.warning(`\`${labelDone}\` not found — \`${labelNeeded}\` is present but testing is not confirmed.`); |
| 46 | + await postComment( |
| 47 | + `### ⚠️ Robot Testing Incomplete\n\n` + |
| 48 | + `\`${labelNeeded}\` is present but \`${labelDone}\` has not been added yet.${shaLine}\n\n` + |
| 49 | + `> [!WARNING]\n> Add \`${labelDone}\` once robot testing is complete.` |
| 50 | + ); |
| 51 | + } else { |
| 52 | + core.info(`\`${labelDone}\` not present — nothing to do.`); |
| 53 | + } |
| 54 | + return; |
| 55 | + } |
| 56 | +
|
| 57 | + core.info(`\`${labelDone}\` found — posting confirmation comment.`); |
| 58 | + await postComment( |
| 59 | + `### ✅ Robot Test Complete\n\n` + |
| 60 | + `\`${labelDone}\` has been added — robot testing has been confirmed for this PR.${shaLine}` |
| 61 | + ); |
0 commit comments