@@ -20,41 +20,44 @@ export default {
2020 // args[1] is the `orgname/repo` url fragment
2121 // args[2] is the optional branch or hash
2222
23- return (
24- fetch (
25- "https://api.github.com/repos/" +
26- args [ 1 ] +
27- "/commits?sha=" +
28- ( args [ 2 ] || "" )
29- )
30- // the link header has additional urls for paging
31- // parse the original JSON for the case where no other pages exist
32- . then ( ( res ) => Promise . all ( [ res . headers . get ( "link" ) , res . json ( ) ] ) )
33-
34- // get last page of commits
35- . then ( ( results ) => {
36- // results[0] is the link
37- // results[1] is the first page of commits
38-
39- if ( results [ 0 ] ) {
40- // the link contains two urls in the form
41- // <https://github.com/...>; rel=blah, <https://github.com/...>; rel=thelastpage
42- // split the url out of the string
43- var pageurl = results [ 0 ] . split ( "," ) [ 1 ] . split ( ";" ) [ 0 ] . slice ( 2 , - 1 ) ;
44- // fetch the last page
45- return fetch ( pageurl ) . then ( ( res ) => res . json ( ) ) ;
46- }
47-
48- // if no link, we know we're on the only page
49- return results [ 1 ] ;
50- } )
51-
52- // get the last commit and extract the url
53- . then ( ( commits ) => commits . pop ( ) . html_url )
54-
55- // navigate there
56- . then ( ( url ) => ( window . location = url ) )
57- ) ;
23+ if ( ! args || ! args [ 1 ] ) {
24+ alert ( "Vui lòng mở 1 trang repo github rồi chạy lại chức năng." ) ;
25+ return ;
26+ }
27+
28+ fetch (
29+ "https://api.github.com/repos/" +
30+ args [ 1 ] +
31+ "/commits?sha=" +
32+ ( args [ 2 ] || "" )
33+ )
34+ // the link header has additional urls for paging
35+ // parse the original JSON for the case where no other pages exist
36+ . then ( ( res ) => Promise . all ( [ res . headers . get ( "link" ) , res . json ( ) ] ) )
37+
38+ // get last page of commits
39+ . then ( ( results ) => {
40+ // results[0] is the link
41+ // results[1] is the first page of commits
42+
43+ if ( results [ 0 ] ) {
44+ // the link contains two urls in the form
45+ // <https://github.com/...>; rel=blah, <https://github.com/...>; rel=thelastpage
46+ // split the url out of the string
47+ var pageurl = results [ 0 ] . split ( "," ) [ 1 ] . split ( ";" ) [ 0 ] . slice ( 2 , - 1 ) ;
48+ // fetch the last page
49+ return fetch ( pageurl ) . then ( ( res ) => res . json ( ) ) ;
50+ }
51+
52+ // if no link, we know we're on the only page
53+ return results [ 1 ] ;
54+ } )
55+
56+ // get the last commit and extract the url
57+ . then ( ( commits ) => commits . pop ( ) . html_url )
58+
59+ // navigate there
60+ . then ( ( url ) => ( window . location = url ) ) ;
5861 } ,
5962} ;
6063
0 commit comments