@@ -20,31 +20,59 @@ var __importStar = (this && this.__importStar) || function (mod) {
2020} ;
2121Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2222const rest_1 = require ( "@octokit/rest" ) ;
23- const node_fetch_1 = __importStar ( require ( "node-fetch" ) ) ;
24- run ( ) ;
25- async function run ( ) {
26- const o = new rest_1 . Octokit ( { auth : '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' } ) ;
27- // const { data } = await o.request("/user");
28- // console.log(data)
29- const sha = 'fd3d6b191cf773f68ca6dfc57bc52e28513fd8d1' ;
30- // const q = `repo:shiftcode/sc-commons next`
31- // const q = `hash:${sha} repo:shiftcode/sc-commons rev:@*refs/heads/* type:diff`
32- // const q = `repo:shiftcode/sc-commons@${sha} type:diff`
33- // const q = `hash:${sha} rev:@*refs/heads/*`
34- const q = `hash:${ sha } repo:shiftcode/sc-commons rev:@refs/heads/#102-fix-peer-deps-version type:diff` ;
35- console . info ( `q: ${ q } ` ) ;
23+ const https = __importStar ( require ( "https" ) ) ;
24+ const token = process . env . GH_TOKEN ;
25+ console . log ( token ) ;
26+ const sha = 'fd3d6b191cf773f68ca6dfc57bc52e28513fd8d1' ;
27+ runWithOctokit ( )
28+ . then ( ( ) => runOther ( ) ) ;
29+ async function runWithOctokit ( ) {
30+ console . log ( `### execution with octokit client` ) ;
31+ const o = new rest_1 . Octokit ( { auth : token } ) ;
32+ const { data } = await o . request ( '/user' ) ;
33+ console . log ( `current user: ${ data . login } ` ) ;
34+ // query try out
35+ /*
36+ const q = `repo:shiftcode/sc-commons next`
37+ const q = `hash:${sha} repo:shiftcode/sc-commons rev:@*refs/heads/* type:diff`
38+ const q = `repo:shiftcode/sc-commons@${sha} type:diff`
39+ const q = `hash:${sha} rev:@*refs/heads/*`
40+ */
41+ const q = `hash:${ sha } repo:shiftcode/sc-commons rev:@refs/heads/#102-fix-peer-deps-version` ;
42+ console . info ( `execute with search query: ${ q } ` ) ;
3643 const response = await o . rest . search . commits ( { q } ) ;
37- console . log ( response ) ;
44+ // seems like octokit will only return commits from default branch
45+ console . log ( `found ${ response . data . total_count } commits for sha ${ sha } ` ) ;
3846 for ( const { commit } of response . data . items ) {
3947 console . log ( `----------------- ${ commit . url } -----------------` ) ;
4048 console . log ( commit . message ) ;
4149 console . log ( '-------------------------------------------------' ) ;
4250 }
43- const headers = new node_fetch_1 . Headers ( ) ;
44- headers . set ( 'Authorization' , 'token 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' ) ;
45- const response2 = await ( 0 , node_fetch_1 . default ) ( `https://api.github.com/repos/shiftcode/sc-commons/git/commits/${ sha } ` , {
46- headers
51+ }
52+ async function runOther ( ) {
53+ console . log ( `### execution with plain http request` ) ;
54+ const url = `https://api.github.com/repos/shiftcode/sc-commons/git/commits/${ sha } ` ;
55+ console . log ( url ) ;
56+ const commit = ( await fetch ( url ) ) ; /* and others */
57+ console . log ( `----------------- ${ commit . url } -----------------` ) ;
58+ console . log ( commit . message ) ;
59+ console . log ( '-------------------------------------------------' ) ;
60+ }
61+ async function fetch ( url ) {
62+ return new Promise ( ( resolve ) => {
63+ https . get ( url , {
64+ headers : {
65+ Authorization : `token ${ token } ` ,
66+ 'User-Agent' : 'Github Skip Action' ,
67+ } ,
68+ } , res => {
69+ let data = '' ;
70+ res . on ( 'data' , chunk => {
71+ data += chunk ;
72+ } ) ;
73+ res . on ( 'end' , ( ) => {
74+ resolve ( JSON . parse ( data ) ) ;
75+ } ) ;
76+ } ) ;
4777 } ) ;
48- console . log ( response2 . status ) ;
49- console . log ( await response2 . json ( ) ) ;
5078}
0 commit comments