Skip to content

Commit 2349591

Browse files
committed
chore(ci): improve error handling for non-issue numbers
1 parent 28e8fe2 commit 2349591

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

.github/scripts/label_related_issue.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,30 @@ module.exports = async ({github, context, core}) => {
1919

2020

2121
const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;
22-
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
23-
if (!isMatch) {
24-
core.setFailed(`Unable to find related issue for PR number ${PR_NUMBER}.\n\n Body details: ${PR_BODY}`);
25-
return await github.rest.issues.createComment({
22+
23+
try {
24+
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
25+
if (!isMatch) {
26+
core.setFailed(`Unable to find related issue for PR number ${PR_NUMBER}.\n\n Body details: ${PR_BODY}`);
27+
return await github.rest.issues.createComment({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
body: `${HANDLE_MAINTAINERS_TEAM} No related issues found. Please ensure '${LABEL_PENDING_RELEASE}' label is applied before releasing.`,
31+
issue_number: PR_NUMBER,
32+
});
33+
}
34+
35+
const { groups: {issue} } = isMatch
36+
37+
core.info(`Auto-labeling related issue ${issue} for release`)
38+
return await github.rest.issues.addLabels({
39+
issue_number: issue,
2640
owner: context.repo.owner,
2741
repo: context.repo.repo,
28-
body: `${HANDLE_MAINTAINERS_TEAM} No related issues found. Please ensure '${LABEL_PENDING_RELEASE}' label is applied before releasing.`,
29-
issue_number: PR_NUMBER,
30-
});
42+
labels: [LABEL_PENDING_RELEASE]
43+
})
44+
} catch (error) {
45+
core.setFailed(`Is this issue number (${issue}) valid? Perhaps a discussion?`);
46+
throw new Error(error);
3147
}
32-
33-
const { groups: {issue} } = isMatch
34-
35-
core.info(`Auto-labeling related issue ${issue} for release`)
36-
return await github.rest.issues.addLabels({
37-
issue_number: issue,
38-
owner: context.repo.owner,
39-
repo: context.repo.repo,
40-
labels: [LABEL_PENDING_RELEASE]
41-
})
4248
}

0 commit comments

Comments
 (0)