|
1 | 1 | import type { H3Event } from "h3"; |
2 | 2 | import type { components as OctokitComponents } from "@octokit/openapi-types"; |
3 | 3 | import type { Comment, PackageManager } from "@pkg-pr-new/utils"; |
| 4 | +import type { WorkflowData } from "../types"; |
4 | 5 | import { isPullRequest, isWhitelisted } from "@pkg-pr-new/utils"; |
5 | 6 | import { randomUUID } from "uncrypto"; |
6 | 7 | import { setItemStream, useTemplatesBucket } from "../utils/bucket"; |
@@ -231,7 +232,10 @@ export default eventHandler(async (event) => { |
231 | 232 | checkRunUrl = html_url!; |
232 | 233 | } |
233 | 234 |
|
234 | | - if (isPullRequest(workflowData.ref)) { |
| 235 | + if ( |
| 236 | + isPullRequest(workflowData.ref) && |
| 237 | + (await getPullRequestState(installation, workflowData)) === "open" |
| 238 | + ) { |
235 | 239 | let prevComment: OctokitComponents["schemas"]["issue-comment"]; |
236 | 240 |
|
237 | 241 | await installation.paginate( |
@@ -330,6 +334,25 @@ export default eventHandler(async (event) => { |
330 | 334 | }; |
331 | 335 | }); |
332 | 336 |
|
| 337 | +async function getPullRequestState( |
| 338 | + installation: Awaited<ReturnType<typeof useOctokitInstallation>>, |
| 339 | + workflowData: WorkflowData, |
| 340 | +) { |
| 341 | + try { |
| 342 | + const { data: pr } = await installation.request( |
| 343 | + "GET /repos/{owner}/{repo}/pulls/{pull_number}", |
| 344 | + { |
| 345 | + owner: workflowData.owner, |
| 346 | + repo: workflowData.repo, |
| 347 | + pull_number: Number(workflowData.ref), |
| 348 | + }, |
| 349 | + ); |
| 350 | + return pr.state; |
| 351 | + } catch (error) { |
| 352 | + return null; |
| 353 | + } |
| 354 | +} |
| 355 | + |
333 | 356 | async function iterateAndDelete( |
334 | 357 | event: H3Event, |
335 | 358 | base: string, |
|
0 commit comments