Skip to content

Commit 99b312b

Browse files
[core] Enhance debugging and author validation in status label handler (#303)
Signed-off-by: Michel Engelen <[email protected]> Co-authored-by: Jose C Quintas Jr <[email protected]>
1 parent 4ce3670 commit 99b312b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

.github/workflows/scripts/issues/statusLabelHandler.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ module.exports = async ({ core, context, github }) => {
1212
const repo = context.repo.repo;
1313
const issueNumber = context.issue.number;
1414

15+
core.debug(`>>> Context: ${JSON.stringify(context)}`);
16+
1517
const issue = await github.rest.issues.get({
1618
owner,
1719
repo,
1820
issue_number: issueNumber,
1921
});
2022

21-
const issueAuthor = issue.data.user.login;
22-
const commentAuthor = context.payload.comment.user.login;
23+
core.debug(`>>> Issue data: ${JSON.stringify(issue.data)}`);
24+
25+
const issueAuthor = issue.data.user?.login;
26+
core.info(`>>> Issue author: ${issueAuthor}`);
27+
28+
// there is no comment when the issue gets closed, so we just assign null and continue with the action
29+
const commentAuthor = context.payload.comment?.user.login;
30+
core.info(`>>> Comment author: ${commentAuthor}`);
2331

2432
// return early if the author of the comment is not the same as the author of the issue
2533
if (issueAuthor !== commentAuthor) {
@@ -28,6 +36,7 @@ module.exports = async ({ core, context, github }) => {
2836
}
2937

3038
const labels = issue.data.labels.map((label) => label.name);
39+
core.debug(`>>> Issue labels: ${JSON.stringify(labels)}`);
3140

3241
const maintainerLabel = 'status: waiting for maintainer';
3342
const authorLabel = 'status: waiting for author';
@@ -48,9 +57,13 @@ module.exports = async ({ core, context, github }) => {
4857
const purgedLabels = labels.filter(
4958
(label) => label !== maintainerLabel && label !== authorLabel,
5059
);
60+
core.info(`>>> Purged labels: ${JSON.stringify(purgedLabels)}`);
61+
5162
// check if the issue is closed or gets closed with this event
5263
const issueIsOrGetsClosed =
5364
context.payload.action === 'closed' || issue.data.state === 'closed';
65+
core.info(`>>> Issue is or gets closed: ${issueIsOrGetsClosed}`);
66+
5467
// add maintainerLabel when issue is not/won't be closed
5568
const labelsForUpdate = issueIsOrGetsClosed ? purgedLabels : [...purgedLabels, maintainerLabel];
5669

0 commit comments

Comments
 (0)