File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ describe("parseGitHubURL", () => {
7575 expect ( parseGitHubURL ( "http://github.com/owner/repo" ) ) . toBe ( "owner/repo" ) ;
7676 } ) ;
7777
78+ it ( "parses URLs without protocol" , ( ) => {
79+ expect ( parseGitHubURL ( "github.com/owner/repo" ) ) . toBe ( "owner/repo" ) ;
80+ } ) ;
81+
7882 it ( "handles repos with dots in name" , ( ) => {
7983 expect ( parseGitHubURL ( "owner/repo.name" ) ) . toBe ( "owner/repo.name" ) ;
8084 } ) ;
Original file line number Diff line number Diff line change 44 * @returns {string | null } The parsed repository name or null if the URL is invalid.
55 */
66export const parseGitHubURL = ( input : string ) : string | null => {
7+ // If the input looks like a github.com URL but is missing a protocol,
8+ // prepend https:// so URL parsing succeeds.
9+ const normalized = / ^ (?: w w w \. ) ? g i t h u b \. c o m \/ / . test ( input )
10+ ? `https://${ input . replace ( / ^ h t t p s ? : \/ \/ / , "" ) } `
11+ : input ;
12+
713 try {
8- const url = new URL ( input ) ;
14+ const url = new URL ( normalized ) ;
915 if ( url . hostname === "github.com" || url . hostname === "www.github.com" ) {
1016 const pathSegments = url . pathname . split ( "/" ) . filter ( Boolean ) ;
1117 if ( pathSegments . length >= 2 ) {
You can’t perform that action at this time.
0 commit comments