@@ -13,6 +13,8 @@ import * as VcsProcess from "../vcs/VcsProcess.ts";
1313import * as GitHubApi from "./GitHubApi.ts" ;
1414import * as GitHubCli from "./GitHubCli.ts" ;
1515import * as GitHubCredentials from "./GitHubCredentials.ts" ;
16+ import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts" ;
17+ import { HostProcessEnvironment } from "@t3tools/shared/hostProcess" ;
1618
1719const encodeJson = Schema . encodeSync ( Schema . fromJsonString ( Schema . Unknown ) ) ;
1820
@@ -595,3 +597,110 @@ describe("GitHubCli.checkoutPullRequest", () => {
595597 assert . strictEqual ( name ( "main" , false ) , "main" ) ;
596598 } ) ;
597599} ) ;
600+
601+ it . live . each ( [
602+ "[email protected] :team/project.git" , 603+ "ssh://[email protected] /team/project.git" , 604+ "https://code.example.test/team/project.git" ,
605+ ] ) ( "keeps Enterprise operations on the selected remote: %s" , ( remoteUrl ) => {
606+ const graphql : GitHubApi . GitHubGraphQlInput [ ] = [ ] ;
607+ const rest : GitHubApi . GitHubRestInput [ ] = [ ] ;
608+ const api = {
609+ graphql : ( input : GitHubApi . GitHubGraphQlInput ) =>
610+ Effect . sync ( ( ) => {
611+ graphql . push ( input ) ;
612+ const pr = {
613+ ...node ( 42 , "feature" , "team" ) ,
614+ url : "https://code.example.test/team/project/pull/42" ,
615+ isCrossRepository : false ,
616+ headRepository : { name : "project" , nameWithOwner : "team/project" } ,
617+ } ;
618+ return encodeJson ( {
619+ data : {
620+ repository :
621+ input . operation === "getPullRequest" ? { pullRequest : pr } : { h0 : { nodes : [ pr ] } } ,
622+ } ,
623+ } ) ;
624+ } ) ,
625+ rest : ( input : GitHubApi . GitHubRestInput ) =>
626+ Effect . sync ( ( ) => {
627+ rest . push ( input ) ;
628+ return restResponse ( {
629+ full_name : "team/project" ,
630+ html_url : `https://${ input . host } /team/project` ,
631+ ssh_url : `git@${ input . host } :team/project.git` ,
632+ default_branch : "main" ,
633+ } ) ;
634+ } ) ,
635+ } ;
636+ const { layer, git } = harness ( {
637+ remotes : remotesOutput (
638+ [ "origin" , "[email protected] :team/project.git" ] , 639+ [ "enterprise" , remoteUrl ] ,
640+ ) ,
641+ api,
642+ } ) ;
643+ return Effect . gen ( function * ( ) {
644+ const provider = yield * GitHubSourceControlProvider . make ;
645+ const fs = yield * FileSystem . FileSystem ;
646+ const bodyFile = yield * fs . makeTempFileScoped ( { suffix : ".md" } ) ;
647+ yield * fs . writeFileString ( bodyFile , "Enterprise PR" ) ;
648+ const input = {
649+ cwd : "/repo" ,
650+ context : {
651+ provider : {
652+ kind : "github" as const ,
653+ name : "GitHub Self-Hosted" ,
654+ baseUrl : "https://code.example.test" ,
655+ } ,
656+ remoteName : "enterprise" ,
657+ remoteUrl,
658+ } ,
659+ } ;
660+ for ( const state of [ "open" , "closed" ] as const ) {
661+ const prs = yield * provider . listChangeRequests ( {
662+ ...input ,
663+ state,
664+ headSelector : "feature" ,
665+ } ) ;
666+ assert . strictEqual ( prs [ 0 ] ?. url , "https://code.example.test/team/project/pull/42" ) ;
667+ }
668+ yield * provider . getChangeRequest ( { ...input , reference : "42" } ) ;
669+ yield * provider . getChangeRequest ( { ...input , reference : "feature" } ) ;
670+ yield * provider . createChangeRequest ( {
671+ ...input ,
672+ baseRefName : "main" ,
673+ headSelector : "feature" ,
674+ title : "PR" ,
675+ bodyFile,
676+ } ) ;
677+ assert . strictEqual ( yield * provider . getDefaultBranch ( input ) , "main" ) ;
678+ yield * provider . checkoutChangeRequest ( { ...input , reference : "42" } ) ;
679+ yield * provider . getRepositoryCloneUrls ( { ...input , repository : "team/other" } ) ;
680+ yield * provider . getRepositoryCloneUrls ( { ...input , repository : "github.com/team/explicit" } ) ;
681+ assert . strictEqual ( graphql . length , 5 ) ;
682+ for ( const request of graphql ) {
683+ assert . strictEqual ( request . host , "code.example.test" ) ;
684+ assert . strictEqual ( request . variables ?. owner , "team" ) ;
685+ assert . strictEqual ( request . variables ?. name , "project" ) ;
686+ }
687+ assert . deepStrictEqual (
688+ rest . map ( ( { host, path } ) => [ host , path ] ) ,
689+ [
690+ [ "code.example.test" , "repos/team/project/pulls" ] ,
691+ [ "code.example.test" , "repos/team/project" ] ,
692+ [ "code.example.test" , "repos/team/other" ] ,
693+ [ "github.com" , "repos/team/explicit" ] ,
694+ ] ,
695+ ) ;
696+ assert . deepStrictEqual ( git . find ( ( [ name ] ) => name === "fetchRemoteTrackingBranch" ) ?. [ 1 ] , {
697+ cwd : "/repo" ,
698+ remoteName : "enterprise" ,
699+ remoteBranch : "feature" ,
700+ } ) ;
701+ } ) . pipe (
702+ Effect . provide ( Layer . mergeAll ( layer , NodeServices . layer , Layer . mock ( GitHubApi . GitHubApi ) ( api ) ) ) ,
703+ Effect . provideService ( HostProcessEnvironment , { GH_REPO : "github.com/wrong/repo" } ) ,
704+ Effect . scoped ,
705+ ) ;
706+ } ) ;
0 commit comments