@@ -127,6 +127,21 @@ export async function configureOpenerTrustedDomainsHandler(
127127 return [ ] ;
128128}
129129
130+ // Exported for testing.
131+ export function extractGitHubRemotesFromGitConfig ( gitConfig : string ) : string [ ] {
132+ const domains = new Set < string > ( ) ;
133+ let match : RegExpExecArray | null ;
134+
135+ const RemoteMatcher = / ^ \s * u r l \s * = \s * (?: g i t @ | h t t p s : \/ \/ ) g i t h u b \. c o m (?: : | \/ ) ( \S * ) \s * $ / mg;
136+ while ( match = RemoteMatcher . exec ( gitConfig ) ) {
137+ const repo = match [ 1 ] . replace ( / \. g i t $ / , '' ) ;
138+ if ( repo ) {
139+ domains . add ( `https://github.com/${ repo } /` ) ;
140+ }
141+ }
142+ return [ ...domains ] ;
143+ }
144+
130145async function getRemotes ( fileService : IFileService , textFileService : ITextFileService , contextService : IWorkspaceContextService ) : Promise < string [ ] > {
131146 const workspaceUris = contextService . getWorkspace ( ) . folders . map ( folder => folder . uri ) ;
132147 const domains = await Promise . all < string [ ] > ( workspaceUris . map ( async workspaceUri => {
@@ -136,18 +151,8 @@ async function getRemotes(fileService: IFileService, textFileService: ITextFileS
136151 if ( ! exists ) {
137152 return [ ] ;
138153 }
139- const content = ( await ( textFileService . read ( uri , { acceptTextOnly : true } ) . catch ( ( ) => ( { value : '' } ) ) ) ) . value ;
140- const domains = new Set < string > ( ) ;
141- let match : RegExpExecArray | null ;
142-
143- const RemoteMatcher = / ^ \s * u r l \s * = \s * (?: g i t @ | h t t p s : \/ \/ ) g i t h u b \. c o m (?: : | \/ ) ( \S * ) (?: \. g i t ) ? \s * $ / mg;
144- while ( match = RemoteMatcher . exec ( content ) ) {
145- const repo = match [ 1 ] ;
146- if ( repo ) {
147- domains . add ( `https://github.com/${ repo } /` ) ;
148- }
149- }
150- return [ ...domains ] ;
154+ const gitConfig = ( await ( textFileService . read ( uri , { acceptTextOnly : true } ) . catch ( ( ) => ( { value : '' } ) ) ) ) . value ;
155+ return extractGitHubRemotesFromGitConfig ( gitConfig ) ;
151156 } ) ) ;
152157
153158 const set = domains . reduce ( ( set , list ) => list . reduce ( ( set , item ) => set . add ( item ) , set ) , new Set < string > ( ) ) ;
0 commit comments