Skip to content

Commit 6d66e1f

Browse files
authored
fix: add pr state check for commenting (#399)
1 parent 3a92583 commit 6d66e1f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/app/server/routes/publish.post.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { H3Event } from "h3";
22
import type { components as OctokitComponents } from "@octokit/openapi-types";
33
import type { Comment, PackageManager } from "@pkg-pr-new/utils";
4+
import type { WorkflowData } from "../types";
45
import { isPullRequest, isWhitelisted } from "@pkg-pr-new/utils";
56
import { randomUUID } from "uncrypto";
67
import { setItemStream, useTemplatesBucket } from "../utils/bucket";
@@ -231,7 +232,10 @@ export default eventHandler(async (event) => {
231232
checkRunUrl = html_url!;
232233
}
233234

234-
if (isPullRequest(workflowData.ref)) {
235+
if (
236+
isPullRequest(workflowData.ref) &&
237+
(await getPullRequestState(installation, workflowData)) === "open"
238+
) {
235239
let prevComment: OctokitComponents["schemas"]["issue-comment"];
236240

237241
await installation.paginate(
@@ -330,6 +334,25 @@ export default eventHandler(async (event) => {
330334
};
331335
});
332336

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+
333356
async function iterateAndDelete(
334357
event: H3Event,
335358
base: string,

0 commit comments

Comments
 (0)