@@ -41,7 +41,10 @@ export const GitHubRepositoryScope = Context.Reference<ReadonlyArray<string> | n
4141const isRecord = ( value : unknown ) : value is Record < string , unknown > =>
4242 typeof value === "object" && value !== null ;
4343
44- function repositoriesOf ( input : unknown ) : ReadonlyArray < string > | null {
44+ function repositoriesOf (
45+ input : unknown ,
46+ checkoutTarget : string | null ,
47+ ) : ReadonlyArray < string > | null {
4548 if ( ! isRecord ( input ) ) return null ;
4649 if ( typeof input . repository === "string" ) return [ input . repository ] ;
4750 // Batched reads name several repositories, or change requests that each name one.
@@ -53,7 +56,9 @@ function repositoriesOf(input: unknown): ReadonlyArray<string> | null {
5356 isRecord ( entry ) && typeof entry . repository === "string" ? [ entry . repository ] : [ ] ,
5457 ) ;
5558 }
56- // A checkout names its repository through the remote it pushes to.
59+ // A checkout names its repository through the remote it pushes to, unless the provider
60+ // targets another one for every checkout.
61+ if ( isRecord ( input . context ) && checkoutTarget !== null ) return [ checkoutTarget ] ;
5762 const remote =
5863 isRecord ( input . context ) && typeof input . context . remoteUrl === "string"
5964 ? repositoryPathFromRemoteUrl ( input . context . remoteUrl )
@@ -65,15 +70,21 @@ function repositoriesOf(input: unknown): ReadonlyArray<string> | null {
6570 * Every method whose first argument names its repositories (`repository`, `repositories`,
6671 * `changeRequests`, or a checkout `context`) runs in their scope.
6772 */
68- export function scopeMethodsToRepository < T extends object > ( methods : T ) : T {
73+ export function scopeMethodsToRepository < T extends object > (
74+ methods : T ,
75+ options ?: {
76+ /** `owner/name` a checkout's calls go to instead of its remote, as `GH_REPO` sets. */
77+ readonly checkoutTarget ?: string | null ;
78+ } ,
79+ ) : T {
6980 const scoped : Record < string , unknown > = { } ;
7081 for ( const [ key , value ] of Object . entries ( methods ) ) {
7182 scoped [ key ] =
7283 typeof value !== "function"
7384 ? value
7485 : ( ...args : Array < unknown > ) => {
7586 const result : unknown = Reflect . apply ( value , methods , args ) ;
76- const repositories = repositoriesOf ( args [ 0 ] ) ;
87+ const repositories = repositoriesOf ( args [ 0 ] , options ?. checkoutTarget ?? null ) ;
7788 if ( repositories === null || ! Effect . isEffect ( result ) ) return result ;
7889 // @effect -diagnostics-next-line anyUnknownInErrorContext:off - forwards each method's own effect, whose channels `T` keeps.
7990 return Effect . provideService ( result , GitHubRepositoryScope , repositories ) ;
0 commit comments