Skip to content

Commit cdfe009

Browse files
committed
fix: check if issue_number exists before adding the comment, fallback to logs
1 parent 64edaf8 commit cdfe009

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

dist/index.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14266,36 +14266,39 @@ async function run() {
1426614266
return;
1426714267
}
1426814268

14269-
const { number: issue_number } = context.payload.pull_request;
14269+
const issue_number = context?.payload?.pull_request?.issue_number;
1427014270
const allowedToFail = core.getBooleanInput("allowed-to-fail");
1427114271
const base = JSON.parse(
1427214272
await readFile(path.join(WIKI_PATH, baseSummaryFilename), "utf8")
1427314273
);
1427414274

1427514275
const diff = coverageDiff.diff(base, head);
1427614276

14277-
let comments = await octokit.rest.issues.listComments({
14278-
...context.repo,
14279-
issue_number,
14280-
});
14281-
github;
14277+
if (issue_number) {
14278+
let comments = await octokit.rest.issues.listComments({
14279+
issue_number,
14280+
});
14281+
github;
1428214282

14283-
for (const comment of comments.data) {
14284-
if (comment.body.includes(MARKER)) {
14285-
await octokit.rest.issues.deleteComment({
14286-
...context.repo,
14287-
comment_id: comment.id,
14288-
});
14283+
for (const comment of comments.data) {
14284+
if (comment.body.includes(MARKER)) {
14285+
await octokit.rest.issues.deleteComment({
14286+
...context.repo,
14287+
comment_id: comment.id,
14288+
});
14289+
}
1428914290
}
14290-
}
1429114291

14292-
core.info("Add a comment with the diff coverage report");
14293-
await octokit.rest.issues.createComment({
14294-
...context.repo,
14295-
issue_number,
14296-
body: `${renderDiff(base, head, diff, { allowedToFail })}
14292+
core.info("Add a comment with the diff coverage report");
14293+
await octokit.rest.issues.createComment({
14294+
...context.repo,
14295+
issue_number,
14296+
body: `${renderDiff(base, head, diff, { allowedToFail })}
1429714297
${MARKER}`,
14298-
});
14298+
});
14299+
} else {
14300+
core.info(diff.results);
14301+
}
1429914302

1430014303
if (!allowedToFail && diff.regression) {
1430114304
throw new Error("The coverage is below the minimum threshold");

src/index.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,39 @@ async function run() {
7575
return;
7676
}
7777

78-
const { number: issue_number } = context.payload.pull_request;
78+
const issue_number = context?.payload?.pull_request?.issue_number;
7979
const allowedToFail = core.getBooleanInput("allowed-to-fail");
8080
const base = JSON.parse(
8181
await readFile(path.join(WIKI_PATH, baseSummaryFilename), "utf8")
8282
);
8383

8484
const diff = coverageDiff.diff(base, head);
8585

86-
let comments = await octokit.rest.issues.listComments({
87-
...context.repo,
88-
issue_number,
89-
});
90-
github;
91-
92-
for (const comment of comments.data) {
93-
if (comment.body.includes(MARKER)) {
94-
await octokit.rest.issues.deleteComment({
95-
...context.repo,
96-
comment_id: comment.id,
97-
});
86+
if (issue_number) {
87+
let comments = await octokit.rest.issues.listComments({
88+
issue_number,
89+
});
90+
github;
91+
92+
for (const comment of comments.data) {
93+
if (comment.body.includes(MARKER)) {
94+
await octokit.rest.issues.deleteComment({
95+
...context.repo,
96+
comment_id: comment.id,
97+
});
98+
}
9899
}
99-
}
100100

101-
core.info("Add a comment with the diff coverage report");
102-
await octokit.rest.issues.createComment({
103-
...context.repo,
104-
issue_number,
105-
body: `${renderDiff(base, head, diff, { allowedToFail })}
101+
core.info("Add a comment with the diff coverage report");
102+
await octokit.rest.issues.createComment({
103+
...context.repo,
104+
issue_number,
105+
body: `${renderDiff(base, head, diff, { allowedToFail })}
106106
${MARKER}`,
107-
});
107+
});
108+
} else {
109+
core.info(diff.results);
110+
}
108111

109112
if (!allowedToFail && diff.regression) {
110113
throw new Error("The coverage is below the minimum threshold");

0 commit comments

Comments
 (0)