| 1 | import { AuthOrchestrationReadScope, EnvironmentHttpApi } from "@t3tools/contracts"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 4 | |
| 5 | import { annotateEnvironmentRequest, requireEnvironmentScope } from "../auth/http.ts"; |
| 6 | import * as PullRequestService from "./PullRequestService.ts"; |
| 7 | |
| 8 | /** The patch is often the largest PR payload and benefits from HTTP compression and flow control. */ |
| 9 | export const layer = HttpApiBuilder.group( |
| 10 | EnvironmentHttpApi, |
| 11 | "pullRequests", |
| 12 | Effect.fnUntraced(function* (handlers) { |
| 13 | const pullRequests = yield* PullRequestService.PullRequestService; |
| 14 | return handlers.handle( |
| 15 | "diff", |
| 16 | Effect.fn("environment.pullRequests.diff")(function* (args) { |
| 17 | yield* annotateEnvironmentRequest(args.endpoint.name); |
| 18 | yield* requireEnvironmentScope(AuthOrchestrationReadScope); |
| 19 | return yield* pullRequests.diff(args.payload); |
| 20 | }), |
| 21 | ); |
| 22 | }), |
| 23 | ); |