| 1 | import type { GitRunStackedActionInput, GitRunStackedActionResult } from "@t3tools/contracts"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | |
| 4 | import * as OrchestratorV2 from "../orchestration-v2/Orchestrator.ts"; |
| 5 | import * as ProjectStore from "../orchestration-v2/ProjectStore.ts"; |
| 6 | import * as PullRequestService from "../pullRequest/PullRequestService.ts"; |
| 7 | |
| 8 | export const refreshPushedPullRequests = Effect.fn("refreshPushedPullRequests")( |
| 9 | function* ( |
| 10 | input: Pick<GitRunStackedActionInput, "cwd" | "threadId" | "projectId">, |
| 11 | result: Pick<GitRunStackedActionResult, "push">, |
| 12 | ) { |
| 13 | if (result.push.status !== "pushed") return; |
| 14 | const pullRequests = yield* PullRequestService.PullRequestService; |
| 15 | if (input.threadId !== undefined) { |
| 16 | const engine = yield* OrchestratorV2.OrchestratorV2; |
| 17 | const thread = yield* engine.getThreadShell(input.threadId); |
| 18 | if (thread !== null) { |
| 19 | yield* pullRequests.refreshAfterTurn(thread.projectId); |
| 20 | return; |
| 21 | } |
| 22 | } |
| 23 | if (input.projectId !== undefined) { |
| 24 | yield* pullRequests.refreshAfterTurn(input.projectId); |
| 25 | return; |
| 26 | } |
| 27 | const projects = yield* (yield* ProjectStore.ProjectStoreV2).listShells(); |
| 28 | yield* Effect.forEach( |
| 29 | projects.filter((project) => project.workspaceRoot === input.cwd), |
| 30 | (project) => pullRequests.refreshAfterTurn(project.id), |
| 31 | { discard: true }, |
| 32 | ); |
| 33 | }, |
| 34 | Effect.ignore({ log: true }), |
| 35 | ); |