({
owner,
repository,
prNumber,
githubId,
}: {
owner: string;
repository: string;
prNumber: number;
githubId: string;
})
| 244 | * This prevents creating duplicate security comments on subsequent pushes |
| 245 | */ |
| 246 | export const hasExistingSecurityComment = async ({ |
| 247 | owner, |
| 248 | repository, |
| 249 | prNumber, |
| 250 | githubId, |
| 251 | }: { |
| 252 | owner: string; |
| 253 | repository: string; |
| 254 | prNumber: number; |
| 255 | githubId: string; |
| 256 | }): Promise<boolean> => { |
| 257 | try { |
| 258 | const github = await findGithubById(githubId); |
| 259 | const octokit = authGithub(github); |
| 260 | |
| 261 | // Get all comments for this PR |
| 262 | const { data: comments } = await octokit.rest.issues.listComments({ |
| 263 | owner, |
| 264 | repo: repository, |
| 265 | issue_number: prNumber, |
| 266 | }); |
| 267 | |
| 268 | // Check if any comment contains our security notification marker |
| 269 | const securityCommentExists = comments.some((comment) => |
| 270 | comment.body?.includes( |
| 271 | "🚨 Preview Deployment Blocked - Security Protection", |
| 272 | ), |
| 273 | ); |
| 274 | |
| 275 | return securityCommentExists; |
| 276 | } catch (error) { |
| 277 | console.error( |
| 278 | `❌ Failed to check existing comments on PR #${prNumber}:`, |
| 279 | error, |
| 280 | ); |
| 281 | // If we can't check, assume no comment exists to avoid blocking functionality |
| 282 | return false; |
| 283 | } |
| 284 | }; |
| 285 | |
| 286 | /** |
| 287 | * Create a security notification comment on a GitHub PR |
no test coverage detected