@@ -70,17 +70,34 @@ function pickPrimaryRemote(
7070 return remoteName && remoteUrl ? { remoteName, remoteUrl } : null ;
7171}
7272
73+ function repositoryPathOf ( canonicalKey : string ) : string {
74+ return canonicalKey . split ( "/" ) . slice ( 1 ) . join ( "/" ) ;
75+ }
76+
77+ function buildRepositoryOrigin (
78+ originUrl : string | undefined ,
79+ canonicalKey : string ,
80+ ) : RepositoryIdentity [ "origin" ] {
81+ if ( ! originUrl ) return undefined ;
82+ const originKey = normalizeGitRemoteUrl ( originUrl ) ;
83+ if ( originKey === canonicalKey ) return undefined ;
84+ const displayName = repositoryPathOf ( originKey ) ;
85+ return { canonicalKey : originKey , ...( displayName ? { displayName } : { } ) } ;
86+ }
87+
7388function buildRepositoryIdentity ( input : {
7489 readonly remoteName : string ;
7590 readonly remoteUrl : string ;
91+ readonly originUrl : string | undefined ;
7692 readonly rootPath : string ;
7793} ) : RepositoryIdentity {
7894 const canonicalKey = normalizeGitRemoteUrl ( input . remoteUrl ) ;
7995 const sourceControlProvider = detectSourceControlProviderFromGitRemoteUrl ( input . remoteUrl ) ;
80- const repositoryPath = canonicalKey . split ( "/" ) . slice ( 1 ) . join ( "/" ) ;
96+ const repositoryPath = repositoryPathOf ( canonicalKey ) ;
8197 const repositoryPathSegments = repositoryPath . split ( "/" ) . filter ( ( segment ) => segment . length > 0 ) ;
8298 const [ owner ] = repositoryPathSegments ;
8399 const repositoryName = repositoryPathSegments . at ( - 1 ) ;
100+ const origin = buildRepositoryOrigin ( input . originUrl , canonicalKey ) ;
84101
85102 return {
86103 canonicalKey,
@@ -94,6 +111,7 @@ function buildRepositoryIdentity(input: {
94111 ...( sourceControlProvider ? { provider : sourceControlProvider . kind } : { } ) ,
95112 ...( owner ? { owner } : { } ) ,
96113 ...( repositoryName ? { name : repositoryName } : { } ) ,
114+ ...( origin ? { origin } : { } ) ,
97115 } ;
98116}
99117
@@ -136,8 +154,11 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
136154 return null ;
137155 }
138156
139- const remote = pickPrimaryRemote ( parseRemoteFetchUrls ( remoteResult . value . stdout ) ) ;
140- return remote ? buildRepositoryIdentity ( { ...remote , rootPath : cacheKey } ) : null ;
157+ const remotes = parseRemoteFetchUrls ( remoteResult . value . stdout ) ;
158+ const remote = pickPrimaryRemote ( remotes ) ;
159+ return remote
160+ ? buildRepositoryIdentity ( { ...remote , originUrl : remotes . get ( "origin" ) , rootPath : cacheKey } )
161+ : null ;
141162} ) ;
142163
143164export const make = Effect . fn ( "RepositoryIdentityResolver.make" ) ( function * (
0 commit comments