Skip to content

Commit

Permalink
Merge pull request #45 from Br3nd3n/do-not-stop-on-failed-comment
Browse files Browse the repository at this point in the history
Fix for minor issues after production testing 🔥
  • Loading branch information
willem-delbare authored Apr 5, 2024
2 parents ef53d55 + 221678b commit 1c1bbfb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
30 changes: 20 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ async function createReviewComments(secretKey, scanId) {
path: finding.file,
line: finding.end_line,
start_line: finding.start_line,
body: `${finding.title}\n${finding.description}\n**Remediation:** ${finding.remediation}\n**Details**: [View details](https://app.aikido.dev/featurebranch/scan/${scanId})`
body: `${finding.title}\n${finding.description}\n**Remediation:** ${finding.remediation}\n**Aikido Security:**: [View details](https://app.aikido.dev/featurebranch/scan/${scanId}?groupId=${findingResponse.group_id})`
}));
if (findings.length > 0) {
await (0, postReviewComment_1.postFindingsAsReviewComments)(findings);
Expand Down Expand Up @@ -485,15 +485,25 @@ const postFindingsAsReviewComments = async (findings) => {
existingFinding = comment;
}
if (typeof existingFinding === 'undefined') {
await octokit.rest.pulls.createReviewComment({
...context.repo,
pull_number: pullRequestNumber,
commit_id: finding.commit_id,
path: finding.path,
body: finding.body,
line: finding.line,
...(finding.start_line != finding.line) && { start_line: finding.start_line }
});
try {
await octokit.rest.pulls.createReviewComment({
...context.repo,
pull_number: pullRequestNumber,
commit_id: finding.commit_id,
path: finding.path,
body: finding.body,
line: finding.line,
...(finding.start_line != finding.line) && { start_line: finding.start_line }
});
}
catch (error) {
if (error instanceof Error) {
core.info(`unable to post scan status comment due to error: ${error.message}. Tried posting ${JSON.stringify(finding)}`);
}
else {
core.info(`unable to post scan status comment due to unknown error`);
}
}
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type GetScanStatusResponse =

export type GetScanFindingsResponse =
{
group_id: number,
start_commit_id?: string,
end_commit_id: string,
introduced_sast_issues: [
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async function createReviewComments(secretKey: string, scanId: number): Promise<
path: finding.file,
line: finding.end_line,
start_line: finding.start_line,
body: `${finding.title}\n${finding.description}\n**Remediation:** ${finding.remediation}\n**Details**: [View details](https://app.aikido.dev/featurebranch/scan/${scanId})`
body: `${finding.title}\n${finding.description}\n**Remediation:** ${finding.remediation}\n**Aikido Security:**: [View details](https://app.aikido.dev/featurebranch/scan/${scanId}?groupId=${findingResponse.group_id})`
}
))

Expand Down
27 changes: 18 additions & 9 deletions src/postReviewComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,24 @@ export const postFindingsAsReviewComments = async (findings: TFinding[]): Promis
}

if (typeof existingFinding === 'undefined') {
await octokit.rest.pulls.createReviewComment({
...context.repo,
pull_number: pullRequestNumber,
commit_id: finding.commit_id,
path: finding.path,
body: finding.body,
line: finding.line,
...(finding.start_line != finding.line) && { start_line: finding.start_line }
});
try {
await octokit.rest.pulls.createReviewComment({
...context.repo,
pull_number: pullRequestNumber,
commit_id: finding.commit_id,
path: finding.path,
body: finding.body,
line: finding.line,
...(finding.start_line != finding.line) && { start_line: finding.start_line }
});
} catch (error) {
if (error instanceof Error) {
core.info(`unable to post scan status comment due to error: ${error.message}. Tried posting ${JSON.stringify(finding)}`);
} else {
core.info(`unable to post scan status comment due to unknown error`);
}
}

}
}
};

0 comments on commit 1c1bbfb

Please sign in to comment.