@@ -318,6 +318,54 @@ describe("GitHubSourceControlProvider repository resolution", () => {
318318 } ) . pipe ( Effect . provide ( layer ) ) ;
319319 } ) ;
320320
321+ it . effect (
322+ "reads GitHub subdomain remotes through github.com and preserves enterprise ports" ,
323+ ( ) =>
324+ Effect . gen ( function * ( ) {
325+ for ( const [ remote , host , apiHost ] of [
326+ [ "ssh://[email protected] :443/acme/web.git" , "ssh.github.com" , "github.com" ] , 327+ [ "[email protected] :acme/web.git" , "work.github.com" , "github.com" ] , 328+ [
329+ "https://github.example.com:8443/acme/web.git" ,
330+ "github.example.com:8443" ,
331+ "github.example.com:8443" ,
332+ ] ,
333+ ] as const ) {
334+ const requests : string [ ] = [ ] ;
335+ const { layer } = harness ( {
336+ remotes : remotesOutput ( [ "origin" , remote ] ) ,
337+ api : {
338+ rest : ( input ) =>
339+ Effect . sync ( ( ) => {
340+ requests . push ( `${ input . host } ${ input . path } ` ) ;
341+ return restResponse ( {
342+ full_name : "acme/web" ,
343+ html_url : `https://${ apiHost } /acme/web` ,
344+ ssh_url : `git@${ apiHost } :acme/web.git` ,
345+ default_branch : "trunk" ,
346+ } ) ;
347+ } ) ,
348+ } ,
349+ } ) ;
350+ yield * Effect . gen ( function * ( ) {
351+ const gh = yield * GitHubSourceControlProvider . make ;
352+ assert . strictEqual ( yield * gh . getDefaultBranch ( { cwd : "/repo" } ) , "trunk" ) ;
353+ assert . strictEqual (
354+ yield * gh . getDefaultBranch ( {
355+ cwd : "/repo" ,
356+ context : { ...githubContext ( host ) , remoteUrl : remote } ,
357+ } ) ,
358+ "trunk" ,
359+ ) ;
360+ assert . deepStrictEqual ( requests , [
361+ `${ apiHost } repos/acme/web` ,
362+ `${ apiHost } repos/acme/web` ,
363+ ] ) ;
364+ } ) . pipe ( Effect . provide ( layer ) , Effect . provideService ( HostProcess . Environment , { } ) ) ;
365+ }
366+ } ) ,
367+ ) ;
368+
321369 it . effect ( "reads a GH_REPO owner/name behind a github.com subdomain through github.com" , ( ) => {
322370 const hosts : string [ ] = [ ] ;
323371 const { layer } = harness ( {
@@ -337,11 +385,54 @@ describe("GitHubSourceControlProvider repository resolution", () => {
337385 } ) ;
338386 return Effect . gen ( function * ( ) {
339387 const gh = yield * GitHubSourceControlProvider . make ;
340- yield * gh . getDefaultBranch ( { cwd : "/repo" , context : githubContext ( "work.github.com" ) } ) ;
341- assert . deepStrictEqual ( hosts , [ "github.com repos/chosen/repo" ] ) ;
388+ assert . strictEqual (
389+ yield * gh . getDefaultBranch ( { cwd : "/repo" , context : githubContext ( "work.github.com" ) } ) ,
390+ "main" ,
391+ ) ;
392+ assert . strictEqual ( yield * gh . getDefaultBranch ( { cwd : "/repo" } ) , "main" ) ;
393+ assert . deepStrictEqual ( hosts , [
394+ "github.com repos/chosen/repo" ,
395+ "github.com repos/chosen/repo" ,
396+ ] ) ;
342397 } ) . pipe (
343398 Effect . provide ( layer ) ,
344- Effect . provideService ( HostProcess . Environment , { GH_REPO : "chosen/repo" } ) ,
399+ Effect . provideService ( HostProcess . Environment , {
400+ GH_REPO : "chosen/repo" ,
401+ GH_HOST : "ssh.github.com" ,
402+ } ) ,
403+ ) ;
404+ } ) ;
405+
406+ it . effect ( "uses github.com for a GH_HOST alias when cloning without a checkout remote" , ( ) => {
407+ const requests : string [ ] = [ ] ;
408+ const { layer } = harness ( {
409+ remotes : "" ,
410+ api : {
411+ rest : ( input ) =>
412+ Effect . sync ( ( ) => {
413+ requests . push ( `${ input . host } ${ input . path } ` ) ;
414+ return restResponse ( {
415+ full_name : "chosen/repo" ,
416+ html_url : "https://github.com/chosen/repo" ,
417+ ssh_url :
"[email protected] :chosen/repo.git" , 418+ } ) ;
419+ } ) ,
420+ } ,
421+ } ) ;
422+ return Effect . gen ( function * ( ) {
423+ const gh = yield * GitHubSourceControlProvider . make ;
424+ assert . deepStrictEqual (
425+ yield * gh . getRepositoryCloneUrls ( { cwd : "/repo" , repository : "chosen/repo" } ) ,
426+ {
427+ nameWithOwner : "chosen/repo" ,
428+ url : "https://github.com/chosen/repo" ,
429+ sshUrl :
"[email protected] :chosen/repo.git" , 430+ } ,
431+ ) ;
432+ assert . deepStrictEqual ( requests , [ "github.com repos/chosen/repo" ] ) ;
433+ } ) . pipe (
434+ Effect . provide ( layer ) ,
435+ Effect . provideService ( HostProcess . Environment , { GH_HOST : "work.github.com" } ) ,
345436 ) ;
346437 } ) ;
347438
@@ -683,6 +774,50 @@ describe("GitHubSourceControlProvider writes", () => {
683774 } ) . pipe ( Effect . provide ( layer ) ) ;
684775 } ) ;
685776
777+ it . effect ( "creates repositories on the API host named by GH_HOST" , ( ) =>
778+ Effect . gen ( function * ( ) {
779+ for ( const [ host , apiHost ] of [
780+ [ "work.github.com" , "github.com" ] ,
781+ [ "github.example.com:8443" , "github.example.com:8443" ] ,
782+ ] ) {
783+ const requests : string [ ] = [ ] ;
784+ const { layer } = harness ( {
785+ remotes : "" ,
786+ api : {
787+ rest : ( input ) =>
788+ Effect . sync ( ( ) => {
789+ requests . push ( `${ input . host } ${ input . method ?? "GET" } ${ input . path } ` ) ;
790+ return input . path === "user"
791+ ? restResponse ( { login : "me" } )
792+ : restResponse ( {
793+ full_name : "acme/new" ,
794+ html_url : `https://${ apiHost } /acme/new` ,
795+ ssh_url : `git@${ apiHost } :acme/new.git` ,
796+ } ) ;
797+ } ) ,
798+ } ,
799+ } ) ;
800+ yield * Effect . gen ( function * ( ) {
801+ const gh = yield * GitHubSourceControlProvider . make ;
802+ yield * gh . createRepository ( {
803+ cwd : "/repo" ,
804+ repository : "acme/new" ,
805+ visibility : "private" ,
806+ } ) ;
807+ yield * gh . createRepository ( { cwd : "/repo" , repository : "new" , visibility : "private" } ) ;
808+ assert . deepStrictEqual ( requests , [
809+ `${ apiHost } GET user` ,
810+ `${ apiHost } POST orgs/acme/repos` ,
811+ `${ apiHost } POST user/repos` ,
812+ ] ) ;
813+ } ) . pipe (
814+ Effect . provide ( layer ) ,
815+ Effect . provideService ( HostProcess . Environment , { GH_HOST : host } ) ,
816+ ) ;
817+ }
818+ } ) ,
819+ ) ;
820+
686821 it . effect ( "looks up a bare repository name under the signed-in account on that host" , ( ) => {
687822 const requests : Array < string > = [ ] ;
688823 return Effect . gen ( function * ( ) {
0 commit comments