({
owner,
repository,
prNumber,
prAuthor,
permission,
githubId,
}: {
owner: string;
repository: string;
prNumber: number;
prAuthor: string;
permission: string | null;
githubId: string;
})
| 287 | * Create a security notification comment on a GitHub PR |
| 288 | */ |
| 289 | export const createSecurityBlockedComment = async ({ |
| 290 | owner, |
| 291 | repository, |
| 292 | prNumber, |
| 293 | prAuthor, |
| 294 | permission, |
| 295 | githubId, |
| 296 | }: { |
| 297 | owner: string; |
| 298 | repository: string; |
| 299 | prNumber: number; |
| 300 | prAuthor: string; |
| 301 | permission: string | null; |
| 302 | githubId: string; |
| 303 | }) => { |
| 304 | try { |
| 305 | // Check if a security comment already exists to prevent duplicates |
| 306 | const commentExists = await hasExistingSecurityComment({ |
| 307 | owner, |
| 308 | repository, |
| 309 | prNumber, |
| 310 | githubId, |
| 311 | }); |
| 312 | |
| 313 | if (commentExists) { |
| 314 | console.log( |
| 315 | `ℹ️ Security notification comment already exists on PR #${prNumber}, skipping duplicate`, |
| 316 | ); |
| 317 | return null; |
| 318 | } |
| 319 | |
| 320 | const github = await findGithubById(githubId); |
| 321 | const octokit = authGithub(github); |
| 322 | |
| 323 | const securityMessage = getSecurityBlockedMessage( |
| 324 | prAuthor, |
| 325 | repository, |
| 326 | permission, |
| 327 | ); |
| 328 | |
| 329 | const issue = await octokit.rest.issues.createComment({ |
| 330 | owner, |
| 331 | repo: repository, |
| 332 | issue_number: prNumber, |
| 333 | body: securityMessage, |
| 334 | }); |
| 335 | |
| 336 | console.log( |
| 337 | `✅ Security notification comment created on PR #${prNumber}: ${issue.data.html_url}`, |
| 338 | ); |
| 339 | return issue.data; |
| 340 | } catch (error) { |
| 341 | console.error( |
| 342 | `❌ Failed to create security comment on PR #${prNumber}:`, |
| 343 | error, |
| 344 | ); |
| 345 | // Don't throw error - security comment is nice-to-have, not critical |
| 346 | return null; |
no test coverage detected