@@ -4,7 +4,10 @@ import {color} from '../Style/color';
4
4
5
5
class _GitHubUtil {
6
6
getInfo ( url : string ) : { repo : string ; issueNumber : number , user : string , repoOrg : string , repoName : string } {
7
- const urlPaths = url . split ( '/' ) . reverse ( ) ;
7
+ const urlObj = new URL ( url ) ;
8
+ const pathname = urlObj . pathname ;
9
+
10
+ const urlPaths = pathname . split ( '/' ) . reverse ( ) ;
8
11
const repoOrg = urlPaths [ 3 ] ;
9
12
const repoName = urlPaths [ 2 ] ;
10
13
const repo = `${ repoOrg } /${ repoName } ` ;
@@ -30,16 +33,22 @@ class _GitHubUtil {
30
33
isIssueUrl ( host : string , url : string ) : boolean {
31
34
if ( ! url ) return false ;
32
35
33
- let isIssue = ! ! url . match ( new RegExp ( `^https://${ host } /[\\w\\d-_.]+/[\\w\\d-_.]+/issues/\\d+$` ) ) ;
34
- let isPR = ! ! url . match ( new RegExp ( `^https://${ host } /[\\w\\d-_.]+/[\\w\\d-_.]+/pull/\\d+$` ) ) ;
36
+ const urlObj = new URL ( url ) ;
37
+ if ( urlObj . host !== host ) return false ;
38
+
39
+ const isIssue = ! ! urlObj . pathname . match ( new RegExp ( `^/[\\w\\d-_.]+/[\\w\\d-_.]+/issues/\\d+$` ) ) ;
40
+ const isPR = ! ! urlObj . pathname . match ( new RegExp ( `^/[\\w\\d-_.]+/[\\w\\d-_.]+/pull/\\d+$` ) ) ;
35
41
36
42
return isIssue || isPR ;
37
43
}
38
44
39
45
isProjectUrl ( host : string , url : string ) : boolean {
40
46
if ( ! url ) return false ;
41
47
42
- return ! ! url . match ( new RegExp ( `^https://${ host } /[\\w\\d-_.]+/[\\w\\d-_.]+/projects/\\d+$` ) ) ;
48
+ const urlObj = new URL ( url ) ;
49
+ if ( urlObj . host !== host ) return false ;
50
+
51
+ return ! ! urlObj . pathname . match ( new RegExp ( `^/[\\w\\d-_.]+/[\\w\\d-_.]+/projects/\\d+$` ) ) ;
43
52
}
44
53
45
54
getIssueTypeInfo ( issue : IssueEntity ) : { icon : IconNameType ; color : string ; label : string , state : string } {
0 commit comments