Skip to content

Commit d19b64f

Browse files
szymon-czaprackisjanc
authored andcommitted
ci: No fail verdicts on remove workflow
Organization permission in this repo do not allow token to remove labels. We will keep the workflow knowing that running it produces errors but we omit them.
1 parent 68c77f7 commit d19b64f

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

.github/workflows/remove_ci_label.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,44 @@ jobs:
3434
with:
3535
script: |
3636
const label = 'needs-ci-approval';
37+
const pr = context.payload.pull_request;
38+
if (!pr) {
39+
core.info('No pull_request in event payload. Skipping.');
40+
return;
41+
}
42+
const issue_number = pr.number;
3743
38-
// List current labels on the PR
39-
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
40-
...context.repo,
41-
issue_number: context.issue.number,
42-
});
44+
// List current labels on the PR (use PR number from payload)
45+
let labels = [];
46+
try {
47+
const res = await github.rest.issues.listLabelsOnIssue({
48+
...context.repo,
49+
issue_number,
50+
});
51+
labels = res.data || [];
52+
} catch (e) {
53+
core.info(`Could not list labels on PR #${issue_number}: ${e.status || ''} ${e.message}. Skipping.`);
54+
return;
55+
}
4356
4457
const hasLabel = labels.some(l => l.name === label);
4558
if (!hasLabel) {
4659
core.info(`'${label}' not present — nothing to do.`);
4760
return;
4861
}
4962
50-
// Remove the label if present
63+
// Remove if label is present
5164
try {
5265
await github.rest.issues.removeLabel({
5366
...context.repo,
54-
issue_number: context.issue.number,
67+
issue_number,
5568
name: label,
5669
});
57-
core.info(`Removed '${label}' from PR #${context.issue.number}.`);
70+
core.info(`Removed '${label}' from PR #${issue_number}.`);
5871
} catch (e) {
5972
if (e.status === 404) {
6073
core.info(`'${label}' already gone.`);
6174
} else {
62-
throw e;
75+
core.info(`Failed to remove '${label}' on PR #${issue_number}: ${e.status || ''} ${e.message}. Skipping.`);
6376
}
6477
}

0 commit comments

Comments
 (0)