@@ -798,6 +798,8 @@ namespace pxt.github {
798798
799799 export async function repoAsync ( id : string , config : pxt . PackagesConfig ) : Promise < GitRepo > {
800800 const rid = parseRepoId ( id ) ;
801+ if ( ! rid )
802+ return undefined ;
801803 const status = repoStatus ( rid , config ) ;
802804 if ( status == GitRepoStatus . Banned )
803805 return undefined ;
@@ -857,49 +859,47 @@ namespace pxt.github {
857859 . catch ( err => [ ] ) ; // offline
858860 }
859861
860- export function parseRepoUrl ( url : string ) : { repo : string ; tag ?: string ; path ?: string ; } {
862+ function parseRepoUrl ( url : string ) : { repo : string ; tag ?: string ; path ?: string ; } {
861863 if ( ! url ) return undefined ;
862-
863- let m = / ^ ( ( h t t p s : \/ \/ ) ? g i t h u b .c o m \/ ) ? ( [ ^ / ] + \/ [ ^ / # ] + ) \/ ? ( # ( \w + ) ) ? $ / i. exec ( url . trim ( ) ) ;
864- if ( ! m ) return undefined ;
865-
866- let r : { repo : string ; tag ?: string ; path ?: string ; } = {
867- repo : m ? m [ 3 ] . toLowerCase ( ) : null ,
868- tag : m ? m [ 5 ] : null
864+ url = url . trim ( )
865+ // match github.com urls
866+ let m = / ^ ( ( h t t p s : \/ \/ ) ? g i t h u b .c o m \/ ) ? ( [ ^ / ] + \/ [ ^ / # ] + ) \/ ? ( # ( \w + ) ) ? $ / i. exec ( url ) ;
867+ if ( m ) {
868+ const r : { repo : string ; tag ?: string ; path ?: string ; } = {
869+ repo : m ? m [ 3 ] . toLowerCase ( ) : null ,
870+ tag : m ? m [ 5 ] : null
871+ }
872+ r . path = r . repo + ( r . tag ? '#' + r . tag : '' ) ;
873+ return r ;
869874 }
870- r . path = r . repo + ( r . tag ? '#' + r . tag : '' ) ;
871- return r ;
875+ return undefined ;
872876 }
873877
874878 // parse https://github.com/[company]/[project](/filepath)(#tag)
875879 export function parseRepoId ( repo : string ) : ParsedRepo {
876880 if ( ! repo ) return undefined ;
881+ repo = repo . trim ( ) ;
882+
883+ // convert github pages into github repo
884+ const mgh = / ^ h t t p s : \/ \/ ( [ ^ . / # ] + ) \. g i t h u b \. i o \/ ( [ ^ / # ] + ) \/ ? $ / i. exec ( repo ) ;
885+ if ( mgh )
886+ repo = `github:${ mgh [ 1 ] } /${ mgh [ 2 ] } ` ;
877887
878888 repo = repo . replace ( / ^ g i t h u b : / i, "" )
879889 repo = repo . replace ( / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ / i, "" )
880890 repo = repo . replace ( / \. g i t \b / i, "" )
881891
882- let m = / ( [ ^ # ] + ) ( # ( .* ) ) ? / . exec ( repo )
883- const nameAndFile = m ? m [ 1 ] : null ;
884- const tag = m ? m [ 3 ] : null ;
885- let owner : string ;
886- let project : string ;
887- let fullName : string ;
888- let fileName : string ;
889- if ( m ) {
890- const parts = nameAndFile . split ( '/' ) ;
891- owner = parts [ 0 ] ;
892- project = parts [ 1 ] ;
893- fullName = `${ owner } /${ project } ` ;
894- if ( parts . length > 2 )
895- fileName = parts . slice ( 2 ) . join ( '/' ) ;
896- } else {
897- fullName = repo . toLowerCase ( ) ;
898- }
892+ const m = / ^ ( [ ^ # \/ : ] + ) \/ ( [ ^ # \/ : ] + ) ( \/ ( [ ^ # ] + ) ) ? ( # ( [ ^ \/ : ] * ) ) ? $ / . exec ( repo ) ;
893+ if ( ! m )
894+ return undefined ;
895+ const owner = m [ 1 ] ;
896+ const project = m [ 2 ] ;
897+ const fileName = m [ 4 ] ;
898+ const tag = m [ 6 ] ;
899899 return {
900900 owner,
901901 project,
902- fullName,
902+ fullName : ` ${ owner } / ${ project } ` ,
903903 tag,
904904 fileName
905905 }
@@ -923,6 +923,7 @@ namespace pxt.github {
923923
924924 export function normalizeRepoId ( id : string ) {
925925 const gid = parseRepoId ( id ) ;
926+ if ( ! gid ) return undefined ;
926927 gid . tag = gid . tag || "master" ;
927928 return stringifyRepo ( gid ) ;
928929 }
@@ -946,7 +947,7 @@ namespace pxt.github {
946947 if ( targetVersion && config . releases && config . releases [ "v" + targetVersion . major ] ) {
947948 const release = config . releases [ "v" + targetVersion . major ]
948949 . map ( repo => pxt . github . parseRepoId ( repo ) )
949- . filter ( repo => repo . fullName . toLowerCase ( ) == parsed . fullName . toLowerCase ( ) )
950+ . filter ( repo => repo && repo . fullName . toLowerCase ( ) == parsed . fullName . toLowerCase ( ) )
950951 [ 0 ] ;
951952 if ( release ) {
952953 // this repo is frozen to a particular tag for this target
0 commit comments