import { graphql, GraphqlResponseError } from "/workspace/node_modules/.bun/@octokit+graphql@9.0.5/node_modules/@octokit/graphql/dist-bundle/index.js"; import { readPullRequestDetail } from "/workspace/packages/shared/src/pull-request-detail/pull-request-detail.ts"; const base = await import(process.argv[2]); const input = { owner: "ParadevAI", repo: "Paradev", pullNumber: 9656 }; const gh = graphql.defaults({ headers: { authorization: `token ${process.env.GH_TOKEN}` } }); const queries: string[] = []; const live = { graphql: (q: string, v: any) => { queries.push(q.includes("isMergeQueueEnabled") ? "gated" : q.includes("squashMergeAllowed") ? "main" : "page"); return gh(q, v); }, requestedReviewers: async () => ({ users: [], teams: [] }) }; console.log("== 1. Live GitHub, PR head, normal token =="); const d = await readPullRequestDetail(live as any, input); console.log("queries sent:", queries.join(", ")); console.log(JSON.stringify({ title: d.pullRequest.title, mergeability: { ...d.mergeability }, capabilities: d.capabilities }, null, 1)); // GitHub's shape for an App user token missing Administration + Merge queues function appTokenClient() { return { graphql: async (q: string, v: any) => { if (q.includes("isMergeQueueEnabled")) { const errs = ["isMergeQueueEnabled","mergeQueueEntry","branchProtectionRule"].map((f) => ({ type: "FORBIDDEN", path: ["repository","pullRequest",f], message: "Resource not accessible by integration" })); throw new GraphqlResponseError({ method: "POST", url: "/graphql" } as any, {} as any, { data: { repository: { pullRequest: null } }, errors: errs } as any); } return gh(q, v); }, requestedReviewers: async () => ({ users: [], teams: [] }) }; } console.log("\n== 2. PR head, simulated App token (3 FORBIDDEN on gated fields) =="); const r = await readPullRequestDetail(appTokenClient() as any, input); console.log(JSON.stringify({ title: r.pullRequest.title, requiredApprovals: r.mergeability.requiredApprovals, queue: r.mergeability.queue, queueEnabled: r.mergeability.queueEnabled, merge: r.capabilities.merge }, null, 1)); console.log("\n== 3. Base (main) code, same simulated refusal on its single query =="); const baseClient = { graphql: async (q: string, v: any) => { if (q.includes("isMergeQueueEnabled")) { const errs = ["isMergeQueueEnabled","mergeQueueEntry","branchProtectionRule"].map((f) => ({ type: "FORBIDDEN", path: ["repository","pullRequest",f], message: "Resource not accessible by integration" })); throw new GraphqlResponseError({ method: "POST", url: "/graphql" } as any, {} as any, { data: { repository: { pullRequest: null } }, errors: errs } as any); } return gh(q, v); }, requestedReviewers: async () => ({ users: [], teams: [] }) }; try { await base.readPullRequestDetail(baseClient, input); console.log("no error"); } catch (e: any) { console.log("threw:", e.name, "-", e.message.split("\n")[0], "| error types:", e.errors?.map((x: any) => x.type).join(",")); } console.log("\n== 4. PR head, gated read fails with a non-FORBIDDEN error =="); try { await readPullRequestDetail({ graphql: async (q: string, v: any) => { if (q.includes("isMergeQueueEnabled")) throw new GraphqlResponseError({ method:"POST", url:"/graphql" } as any, {} as any, { data: null, errors: [{ type: "RATE_LIMITED", message: "API rate limit exceeded" }] } as any); return gh(q, v); }, requestedReviewers: async () => ({ users: [], teams: [] }) } as any, input); console.log("no error"); } catch (e: any) { console.log("threw:", e.name, "| types:", e.errors?.map((x: any) => x.type).join(",")); }