@@ -2,6 +2,10 @@ name: "Robot Test Label"
22description : " When the test-robot-done label is added, posts a comment confirming the robot test status."
33
44inputs :
5+ label-test-robot-needed :
6+ description : ' Label indicating the PR needs robot testing'
7+ required : false
8+ default : ' test-robot-needed'
59 label-test-robot-done :
610 description : ' Label indicating the PR has been robot-tested'
711 required : false
@@ -15,52 +19,43 @@ runs:
1519 using : " composite"
1620 steps :
1721 - name : Comment on label added
18- shell : python3 {0}
19- env :
20- GH_TOKEN : ${{ inputs.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_DONE : ${{ inputs.label-test-robot-done }}
25- run : |
26- import os, json, sys, urllib.request, urllib.error
27-
28- token = os.environ['GH_TOKEN']
29- repo = os.environ['REPO']
30- pr = os.environ['PR_NUMBER']
31- sha = os.environ.get('COMMIT_SHA', '').strip()
32- label = os.environ['LABEL_DONE']
33-
34- headers = {
35- 'Authorization': f'Bearer {token}',
36- 'Accept': 'application/vnd.github+json',
37- 'X-GitHub-Api-Version': '2022-11-28',
38- 'Content-Type': 'application/json',
39- }
40-
41- def gh(method, path, body=None):
42- req = urllib.request.Request(
43- f'https://api.github.com{path}',
44- data=json.dumps(body).encode() if body else None,
45- headers=headers,
46- method=method,
47- )
48- try:
49- with urllib.request.urlopen(req) as r:
50- return json.loads(r.read())
51- except urllib.error.HTTPError as e:
52- print(f'GitHub API error {e.code}: {e.read().decode()}', file=sys.stderr)
53- sys.exit(1)
54-
55- labels = {l['name'] for l in gh('GET', f'/repos/{repo}/issues/{pr}/labels')}
56-
57- if label not in labels:
58- print(f'Label `{label}` not found — nothing to do.')
59- sys.exit(0)
60-
61- sha_line = f'\n**Commit:** `{sha}`' if sha else ''
62- body = (
63- f'### \u2705 Robot Test Complete\n\n'
64- f'This PR has been marked `{label}`, confirming robot testing has passed.{sha_line}'
65- )
66- gh('POST', f'/repos/{repo}/issues/{pr}/comments', {'body': body})
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