Skip to content

Commit 8ca9e61

Browse files
wip
1 parent a60f67e commit 8ca9e61

3 files changed

Lines changed: 61 additions & 82 deletions

File tree

.github/actions/test-robot-check/action.yml

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,34 @@ runs:
2525
script: |
2626
const labelNeeded = '${{ inputs.label-test-robot-needed }}';
2727
const labelDone = '${{ inputs.label-test-robot-done }}';
28-
const pr = context.payload.pull_request.number;
29-
const sha = context.payload.pull_request.head.sha;
28+
const { number: pr, head: { sha } } = context.payload.pull_request;
29+
const repo = context.repo;
3030
31-
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
32-
...context.repo,
33-
issue_number: pr,
34-
});
35-
const labelNames = new Set(currentLabels.map(l => l.name));
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+
};
3638
37-
if (!labelNames.has(labelNeeded)) {
39+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ ...repo, issue_number: pr });
40+
const has = new Set(labels.map(l => l.name));
41+
42+
if (!has.has(labelNeeded)) {
3843
core.info(`\`${labelNeeded}\` not present — no robot testing required.`);
3944
return;
4045
}
4146
42-
if (labelNames.has(labelDone)) {
47+
if (has.has(labelDone)) {
4348
core.info(`\`${labelDone}\` present — robot testing confirmed.`);
4449
return;
4550
}
4651
4752
const shaLine = sha ? `\n\n**Commit:** \`${sha}\`` : '';
48-
try {
49-
await github.rest.issues.createComment({
50-
...context.repo,
51-
issue_number: pr,
52-
body:
53-
`### ❌ Robot Testing Required\n\n` +
54-
`\`${labelNeeded}\` is present but \`${labelDone}\` has not been added — this PR cannot be merged until robot testing is complete.${shaLine}\n\n` +
55-
`> [!IMPORTANT]\n` +
56-
`> Add \`${labelDone}\` once robot testing is complete.`,
57-
});
58-
} catch (err) {
59-
core.warning(`Could not post comment: ${err.message}`);
60-
}
53+
await postComment(
54+
`### ❌ Robot Testing Required\n\n` +
55+
`\`${labelNeeded}\` is present but \`${labelDone}\` has not been added — this PR cannot be merged until robot testing is complete.${shaLine}\n\n` +
56+
`> [!IMPORTANT]\n> Add \`${labelDone}\` once robot testing is complete.`
57+
);
6158
core.setFailed(`\`${labelNeeded}\` is present but \`${labelDone}\` has not been added — robot testing must be completed before merging.`);

.github/actions/test-robot-label/action.yml

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,37 @@ runs:
2525
script: |
2626
const labelDone = '${{ inputs.label-test-robot-done }}';
2727
const labelNeeded = '${{ inputs.label-test-robot-needed }}';
28-
const pr = context.payload.pull_request.number;
29-
const sha = context.payload.pull_request.head.sha;
28+
const { number: pr, head: { sha } } = context.payload.pull_request;
29+
const repo = context.repo;
3030
31-
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
32-
...context.repo,
33-
issue_number: pr,
34-
});
35-
const labelNames = new Set(currentLabels.map(l => l.name));
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+
};
3638
39+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ ...repo, issue_number: pr });
40+
const has = new Set(labels.map(l => l.name));
3741
const shaLine = sha ? `\n\n**Commit:** \`${sha}\`` : '';
3842
39-
if (!labelNames.has(labelDone)) {
40-
if (labelNames.has(labelNeeded)) {
43+
if (!has.has(labelDone)) {
44+
if (has.has(labelNeeded)) {
4145
core.warning(`\`${labelDone}\` not found — \`${labelNeeded}\` is present but testing is not confirmed.`);
42-
try {
43-
await github.rest.issues.createComment({
44-
...context.repo,
45-
issue_number: pr,
46-
body:
47-
`### ⚠️ Robot Testing Incomplete\n\n` +
48-
`\`${labelNeeded}\` is present but \`${labelDone}\` has not been added yet.${shaLine}\n\n` +
49-
`> [!WARNING]\n` +
50-
`> Add \`${labelDone}\` once robot testing is complete.`,
51-
});
52-
} catch (err) {
53-
core.warning(`Could not post comment: ${err.message}`);
54-
}
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+
);
5551
} else {
5652
core.info(`\`${labelDone}\` not present — nothing to do.`);
5753
}
5854
return;
5955
}
6056
6157
core.info(`\`${labelDone}\` found — posting confirmation comment.`);
62-
try {
63-
await github.rest.issues.createComment({
64-
...context.repo,
65-
issue_number: pr,
66-
body:
67-
`### ✅ Robot Test Complete\n\n` +
68-
`\`${labelDone}\` has been added — robot testing has been confirmed for this PR.${shaLine}`,
69-
});
70-
} catch (err) {
71-
core.warning(`Could not post comment: ${err.message}`);
72-
}
58+
await postComment(
59+
`### ✅ Robot Test Complete\n\n` +
60+
`\`${labelDone}\` has been added — robot testing has been confirmed for this PR.${shaLine}`
61+
);

.github/actions/test-robot-unlabel/action.yml

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,34 @@ runs:
2525
script: |
2626
const labelDone = '${{ inputs.label-test-robot-done }}';
2727
const labelNeeded = '${{ inputs.label-test-robot-needed }}';
28-
const pr = context.payload.pull_request.number;
29-
const sha = context.payload.pull_request.head.sha;
28+
const { number: pr, head: { sha } } = context.payload.pull_request;
29+
const repo = context.repo;
3030
31-
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
32-
...context.repo,
33-
issue_number: pr,
34-
});
35-
const labelNames = new Set(currentLabels.map(l => l.name));
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+
};
3638
37-
if (!labelNames.has(labelDone)) {
39+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ ...repo, issue_number: pr });
40+
const has = new Set(labels.map(l => l.name));
41+
42+
if (!has.has(labelDone)) {
3843
core.info(`\`${labelDone}\` not present — nothing to do.`);
3944
return;
4045
}
4146
42-
await github.rest.issues.removeLabel({
43-
...context.repo,
44-
issue_number: pr,
45-
name: labelDone,
46-
});
47+
await github.rest.issues.removeLabel({ ...repo, issue_number: pr, name: labelDone });
4748
core.info(`\`${labelDone}\` removed.`);
4849
4950
const shaLine = sha ? `\n\n**Commit:** \`${sha}\`` : '';
50-
const warning = !labelNames.has(labelNeeded)
51-
? `\n\n> [!WARNING]\n` +
52-
`> \`${labelDone}\` was removed but \`${labelNeeded}\` was not present — this PR may not be queued for robot testing.`
51+
const warning = !has.has(labelNeeded)
52+
? `\n\n> [!WARNING]\n> \`${labelDone}\` was removed but \`${labelNeeded}\` was not present — this PR may not be queued for robot testing.`
5353
: '';
5454
55-
try {
56-
await github.rest.issues.createComment({
57-
...context.repo,
58-
issue_number: pr,
59-
body:
60-
`### 🔄 Robot Test Label Removed\n\n` +
61-
`New commits were pushed — \`${labelDone}\` has been removed and robot testing must be repeated.${shaLine}${warning}`,
62-
});
63-
} catch (err) {
64-
core.warning(`Could not post comment: ${err.message}`);
65-
}
55+
await postComment(
56+
`### 🔄 Robot Test Label Removed\n\n` +
57+
`New commits were pushed — \`${labelDone}\` has been removed and robot testing must be repeated.${shaLine}${warning}`
58+
);

0 commit comments

Comments
 (0)