@@ -14,6 +14,7 @@ import {
1414 type ProviderChangeRequestActivity ,
1515 type ProviderChangeRequestDetail ,
1616 type PullRequestProviderApi ,
17+ type ProviderRepositoryRef ,
1718} from "./PullRequestProvider.ts" ;
1819import type { GitHubViewerAccess , GitHubWorkflowRunApproval } from "./gitHubPullRequestJson.ts" ;
1920
@@ -198,6 +199,56 @@ export const make = Effect.gen(function* () {
198199 cause : error ,
199200 } ) ;
200201
202+ const readChecks = ( input : ProviderRepositoryRef & { readonly number : number } ) =>
203+ cli . getPullRequestDetail ( input ) . pipe (
204+ Effect . flatMap ( ( pullRequest ) =>
205+ ( pullRequest . state !== "open" || pullRequest . isCrossRepository !== true
206+ ? Effect . succeed ( {
207+ runs : [ ] as ReadonlyArray < GitHubWorkflowRunApproval > ,
208+ unavailable : false ,
209+ } )
210+ : pullRequest . headSha == null || pullRequest . headRepositoryOwner == null
211+ ? Effect . succeed ( {
212+ runs : [ ] as ReadonlyArray < GitHubWorkflowRunApproval > ,
213+ unavailable : true ,
214+ } )
215+ : cli
216+ . listWorkflowRunsRequiringApproval ( {
217+ ...input ,
218+ headSha : pullRequest . headSha ,
219+ headBranch : pullRequest . headBranch ,
220+ headRepositoryOwner : pullRequest . headRepositoryOwner ,
221+ isCrossRepository : true ,
222+ } )
223+ . pipe (
224+ Effect . matchEffect ( {
225+ onFailure : ( error ) =>
226+ error . _tag === "GitHubCliRateLimitError" ||
227+ error . _tag === "SourceControlRateLimitPausedError"
228+ ? Effect . fail ( error )
229+ : Effect . succeed ( {
230+ runs : [ ] as ReadonlyArray < GitHubWorkflowRunApproval > ,
231+ unavailable : true ,
232+ } ) ,
233+ onSuccess : ( runs ) => Effect . succeed ( { runs, unavailable : false } ) ,
234+ } ) ,
235+ )
236+ ) . pipe (
237+ Effect . map ( ( workflowApprovals ) => ( {
238+ ...pullRequest ,
239+ checks : withWorkflowApprovals (
240+ pullRequest . checks ,
241+ workflowApprovals . runs ,
242+ workflowApprovals . unavailable ,
243+ ) ,
244+ ...( workflowApprovals . unavailable
245+ ? { }
246+ : { workflowApprovalsRequired : workflowApprovals . runs . length } ) ,
247+ } ) ) ,
248+ ) ,
249+ ) ,
250+ ) ;
251+
201252 const provider : PullRequestProviderApi = {
202253 kind : "github" ,
203254 capabilities : CAPABILITIES ,
@@ -310,76 +361,37 @@ export const make = Effect.gen(function* () {
310361 getChangeRequestPreview : ( input ) =>
311362 cli . getPullRequestPreview ( input ) . pipe ( Effect . mapError ( fail ( "getChangeRequestPreview" ) ) ) ,
312363
364+ getChangeRequestChecks : ( input ) =>
365+ readChecks ( input ) . pipe (
366+ Effect . map ( ( { state, checks } ) => ( { state, checks } ) ) ,
367+ Effect . mapError ( fail ( "getChangeRequestChecks" ) ) ,
368+ ) ,
369+
313370 getChangeRequest : ( input ) =>
314- cli . getPullRequestDetail ( input ) . pipe (
315- Effect . flatMap ( ( pullRequest ) => {
316- // Fork workflows awaiting approval are absent from the normal check rollup.
317- const approvals =
318- pullRequest . state !== "open" || pullRequest . isCrossRepository !== true
319- ? Effect . succeed ( {
320- runs : [ ] as ReadonlyArray < GitHubWorkflowRunApproval > ,
321- unavailable : false ,
322- } )
323- : pullRequest . headSha == null || pullRequest . headRepositoryOwner == null
324- ? Effect . succeed ( {
325- runs : [ ] as ReadonlyArray < GitHubWorkflowRunApproval > ,
326- unavailable : true ,
327- } )
328- : cli
329- . listWorkflowRunsRequiringApproval ( {
330- ...input ,
331- headSha : pullRequest . headSha ,
332- headBranch : pullRequest . headBranch ,
333- headRepositoryOwner : pullRequest . headRepositoryOwner ,
334- isCrossRepository : true ,
335- } )
336- . pipe (
337- Effect . matchEffect ( {
338- onFailure : ( error ) =>
339- error . _tag === "GitHubCliRateLimitError" ||
340- error . _tag === "SourceControlRateLimitPausedError"
341- ? Effect . fail ( error )
342- : Effect . succeed ( {
343- runs : [ ] as ReadonlyArray < GitHubWorkflowRunApproval > ,
344- unavailable : true ,
345- } ) ,
346- onSuccess : ( runs ) => Effect . succeed ( { runs, unavailable : false } ) ,
347- } ) ,
348- ) ;
349- return approvals . pipe (
350- Effect . map ( ( workflowApprovals ) : ProviderChangeRequestDetail => ( {
351- ...pullRequest ,
352- author : withAvatar ( pullRequest . author , new Map < string , string > ( ) , input . host ) ,
353- checks : withWorkflowApprovals (
354- pullRequest . checks ,
355- workflowApprovals . runs ,
356- workflowApprovals . unavailable ,
357- ) ,
358- ...( workflowApprovals . unavailable
359- ? { }
360- : { workflowApprovalsRequired : workflowApprovals . runs . length } ) ,
361- reviewers : pullRequest . reviewRequestLogins . map ( ( login ) => ( {
362- login,
363- name : null ,
364- avatarUrl : null ,
365- } ) ) ,
366- mergeCapabilities : pullRequest . viewerAccess . mergeCapabilities ,
367- viewerPermissions : gitHubViewerPermissions ( {
368- ...pullRequest . viewerAccess ,
369- canUpdateBranch : pullRequest . comparison ?. viewerCanUpdate === true ,
370- } ) ,
371- baseComparison :
372- pullRequest . comparison === null || pullRequest . comparison . behindBy === null
373- ? "unknown"
374- : pullRequest . comparison . behindBy > 0
375- ? "behind"
376- : "up-to-date" ,
377- ...( pullRequest . comparison ?. behindBy == null
378- ? { }
379- : { behindBy : pullRequest . comparison . behindBy } ) ,
380- } ) ) ,
381- ) ;
382- } ) ,
371+ readChecks ( input ) . pipe (
372+ Effect . map ( ( pullRequest ) : ProviderChangeRequestDetail => ( {
373+ ...pullRequest ,
374+ author : withAvatar ( pullRequest . author , new Map < string , string > ( ) , input . host ) ,
375+ reviewers : pullRequest . reviewRequestLogins . map ( ( login ) => ( {
376+ login,
377+ name : null ,
378+ avatarUrl : null ,
379+ } ) ) ,
380+ mergeCapabilities : pullRequest . viewerAccess . mergeCapabilities ,
381+ viewerPermissions : gitHubViewerPermissions ( {
382+ ...pullRequest . viewerAccess ,
383+ canUpdateBranch : pullRequest . comparison ?. viewerCanUpdate === true ,
384+ } ) ,
385+ baseComparison :
386+ pullRequest . comparison === null || pullRequest . comparison . behindBy === null
387+ ? "unknown"
388+ : pullRequest . comparison . behindBy > 0
389+ ? "behind"
390+ : "up-to-date" ,
391+ ...( pullRequest . comparison ?. behindBy == null
392+ ? { }
393+ : { behindBy : pullRequest . comparison . behindBy } ) ,
394+ } ) ) ,
383395 Effect . mapError ( fail ( "getChangeRequest" ) ) ,
384396 ) ,
385397
0 commit comments