( runtime: PRRuntime, ref: GhPRRef, prNodeId: string, filePaths: string[], viewed: boolean, )
| 602 | * Throws only if ALL mutations fail. |
| 603 | */ |
| 604 | export async function markGhFilesViewed( |
| 605 | runtime: PRRuntime, |
| 606 | ref: GhPRRef, |
| 607 | prNodeId: string, |
| 608 | filePaths: string[], |
| 609 | viewed: boolean, |
| 610 | ): Promise<void> { |
| 611 | if (filePaths.length === 0) return; |
| 612 | |
| 613 | const mutationName = viewed ? "markFileAsViewed" : "unmarkFileAsViewed"; |
| 614 | const mutation = ` |
| 615 | mutation($id: ID!, $path: String!) { |
| 616 | ${mutationName}(input: { pullRequestId: $id, path: $path }) { |
| 617 | clientMutationId |
| 618 | } |
| 619 | } |
| 620 | `; |
| 621 | |
| 622 | const results = await Promise.allSettled( |
| 623 | filePaths.map((path) => |
| 624 | runtime.runCommandWithInput |
| 625 | ? runtime.runCommand("gh", hostnameArgs(ref.host, [ |
| 626 | "api", "graphql", |
| 627 | "-f", `query=${mutation}`, |
| 628 | "-F", `id=${prNodeId}`, |
| 629 | "-F", `path=${path}`, |
| 630 | ])) |
| 631 | : Promise.reject(new Error("Runtime does not support commands")), |
| 632 | ), |
| 633 | ); |
| 634 | |
| 635 | const failures = results.filter((r): r is PromiseRejectedResult => r.status === "rejected"); |
| 636 | if (failures.length === filePaths.length) { |
| 637 | throw new Error( |
| 638 | `Failed to ${mutationName} all files: ${failures[0].reason}`, |
| 639 | ); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | // --- Submit PR Review --- |
| 644 |
no test coverage detected