Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25254,6 +25254,16 @@ async function postCommentFromArtifact() {
);
info(`Posting comment to PR #${result.pr_number}`);
const octokit = getOctokit(token);
if (result.has_warnings === false) {
const existingCommentId = await findExistingComment(
octokit,
result.pr_number
);
if (!existingCommentId) {
info("No dependency warnings found. Skipping comment creation.");
return;
}
}
await upsertComment(octokit, result.pr_number, result.body);
}
async function analyzeAndComment() {
Expand Down Expand Up @@ -25449,7 +25459,11 @@ ${report}`;
await fs4.mkdir(tmpDir, { recursive: true });
await fs4.writeFile(
outputPath,
JSON.stringify({ pr_number: prNumber, body: commentBody })
JSON.stringify({
pr_number: prNumber,
body: commentBody,
has_warnings: messages.length > 0
})
);
setOutput("artifact-path", outputPath);
info(`Wrote artifact to ${outputPath}`);
Expand Down
19 changes: 18 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {findExistingComment, upsertComment, writeJobSummary} from './github.js';
interface ArtifactResult {
pr_number: number;
body: string;
// Missing in artifacts written by older versions, which always commented.
has_warnings?: boolean;
}

async function postCommentFromArtifact(): Promise<void> {
Expand All @@ -55,6 +57,17 @@ async function postCommentFromArtifact(): Promise<void> {
core.info(`Posting comment to PR #${result.pr_number}`);

const octokit = github.getOctokit(token);
if (result.has_warnings === false) {
const existingCommentId = await findExistingComment(
octokit,
result.pr_number
);
if (!existingCommentId) {
core.info('No dependency warnings found. Skipping comment creation.');
return;
}
}

await upsertComment(octokit, result.pr_number, result.body);
}

Expand Down Expand Up @@ -287,7 +300,11 @@ async function analyzeAndComment(): Promise<void> {
await fs.mkdir(tmpDir, {recursive: true});
await fs.writeFile(
outputPath,
JSON.stringify({pr_number: prNumber, body: commentBody})
JSON.stringify({
pr_number: prNumber,
body: commentBody,
has_warnings: messages.length > 0
} satisfies ArtifactResult)
);

core.setOutput('artifact-path', outputPath);
Expand Down