Skip to content

Commit 25df49a

Browse files
committed
Chore: Remove excessive error checks for github.rest.issues methods
1 parent 4c080fc commit 25df49a

File tree

1 file changed

+43
-55
lines changed

1 file changed

+43
-55
lines changed

.github/workflows/status-label.yml

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,30 @@ jobs:
3535
}
3636
console.log(`PR Number: ${prNumber}`);
3737
38-
// Remove all labels starting with 'status:' from the PR
38+
// Remove all labels starting with 'status:' from the PR, except 'status:review'
3939
const prLabels = context.payload.pull_request.labels || [];
40+
let alreadyInReview = false;
4041
for (const label of prLabels) {
41-
if (label.name.startsWith('status:')) {
42+
if (label.name === 'status:review') {
43+
alreadyInReview = true;
44+
} else if (label.name.startsWith('status:')) {
4245
await github.rest.issues.removeLabel({
43-
owner: context.repo.owner,
44-
repo: context.repo.repo,
45-
issue_number: prNumber,
46-
name: label.name
47-
}).catch(() => console.log(`Label ${label.name} not found on PR`));
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
issue_number: prNumber,
49+
name: label.name
50+
});
4851
}
4952
}
5053
51-
// Add 'status:review' label to the PR
52-
if (github?.rest?.issues?.addLabels) {
54+
// Add 'status:review' label to the PR if not already present
55+
if (!alreadyInReview) {
5356
await github.rest.issues.addLabels({
5457
owner: context.repo.owner,
5558
repo: context.repo.repo,
5659
issue_number: prNumber,
5760
labels: ['status:review']
5861
});
59-
console.log('Added status:review label to PR');
60-
} else {
61-
console.log('Error: github.rest.issues.addLabels is not available');
6262
}
6363
6464
// Process linked issues
@@ -82,22 +82,18 @@ jobs:
8282
repo: context.repo.repo,
8383
issue_number: issueNumber,
8484
name: label.name
85-
}).catch(() => console.log(`Label ${label.name} not found on issue ${issueNumber}`));
85+
});
8686
}
8787
}
8888
8989
// Add 'status:review' label to the linked issue
90-
if (github?.rest?.issues?.addLabels) {
91-
await github.rest.issues.addLabels({
92-
owner: context.repo.owner,
93-
repo: context.repo.repo,
94-
issue_number: issueNumber,
95-
labels: ['status:review']
96-
});
97-
console.log(`Added status:review label to issue: ${issueNumber}`);
98-
} else {
99-
console.log('Error: github.rest.issues.addLabels is not available');
100-
}
90+
await github.rest.issues.addLabels({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
issue_number: issueNumber,
94+
labels: ['status:review']
95+
});
96+
console.log(`Added status:review label to issue: ${issueNumber}`);
10197
}
10298
10399
- name: Set PR and linked issues to done
@@ -113,44 +109,36 @@ jobs:
113109
return;
114110
}
115111
console.log(`PR Number: ${prNumber}`);
116-
if (github?.rest?.issues?.removeLabel && github?.rest?.issues?.addLabels) {
112+
await github.rest.issues.removeLabel({
113+
owner: context.repo.owner,
114+
repo: context.repo.repo,
115+
issue_number: prNumber,
116+
name: 'status:review'
117+
}).catch(() => console.log('status:review label not found on PR'));
118+
await github.rest.issues.addLabels({
119+
owner: context.repo.owner,
120+
repo: context.repo.repo,
121+
issue_number: prNumber,
122+
labels: ['status:done']
123+
});
124+
console.log('Added status:done label to PR');
125+
126+
const linkedIssues = context.payload.pull_request.body?.match(/(?:Fixes|Closes) #\d+/g) || [];
127+
console.log(`Linked Issues: ${linkedIssues}`);
128+
for (const issueRef of linkedIssues) {
129+
const issueNumber = parseInt(issueRef.split('#')[1]);
130+
console.log(`Processing linked issue: ${issueNumber}`);
117131
await github.rest.issues.removeLabel({
118132
owner: context.repo.owner,
119133
repo: context.repo.repo,
120-
issue_number: prNumber,
134+
issue_number: issueNumber,
121135
name: 'status:review'
122-
}).catch(() => console.log('status:review label not found on PR'));
136+
}).catch(() => console.log('status:review label not found on issue'));
123137
await github.rest.issues.addLabels({
124138
owner: context.repo.owner,
125139
repo: context.repo.repo,
126-
issue_number: prNumber,
140+
issue_number: issueNumber,
127141
labels: ['status:done']
128142
});
129-
console.log('Added status:done label to PR');
130-
} else {
131-
console.log('Error: github.rest.issues.removeLabel or github.rest.issues.addLabels is not available');
132-
}
133-
134-
const linkedIssues = context.payload.pull_request.body?.match(/(?:Fixes|Closes) #\d+/g) || [];
135-
console.log(`Linked Issues: ${linkedIssues}`);
136-
for (const issueRef of linkedIssues) {
137-
const issueNumber = parseInt(issueRef.split('#')[1]);
138-
console.log(`Processing linked issue: ${issueNumber}`);
139-
if (github?.rest?.issues?.removeLabel && github?.rest?.issues?.addLabels) {
140-
await github.rest.issues.removeLabel({
141-
owner: context.repo.owner,
142-
repo: context.repo.repo,
143-
issue_number: issueNumber,
144-
name: 'status:review'
145-
}).catch(() => console.log('status:review label not found on issue'));
146-
await github.rest.issues.addLabels({
147-
owner: context.repo.owner,
148-
repo: context.repo.repo,
149-
issue_number: issueNumber,
150-
labels: ['status:done']
151-
});
152-
console.log(`Added status:done label to issue: ${issueNumber}`);
153-
} else {
154-
console.log('Error: github.rest.issues.removeLabel or github.rest.issues.addLabels is not available');
155-
}
143+
console.log(`Added status:done label to issue: ${issueNumber}`);
156144
}

0 commit comments

Comments
 (0)