33'use strict' ;
44
55const {
6- PRBuild, BenchmarkRun, CommitBuild, jobCache, parseJobFromURL, constants
6+ PRBuild, BenchmarkRun, CommitBuild, parseJobFromURL,
7+ constants, JobParser
8+ // , jobCache
79} = require ( '../lib/ci' ) ;
810const clipboardy = require ( 'clipboardy' ) ;
911
@@ -12,13 +14,14 @@ const {
1214} = constants ;
1315
1416const { runPromise } = require ( '../lib/run' ) ;
17+ const auth = require ( '../lib/auth' ) ;
1518const Request = require ( '../lib/request' ) ;
1619const CLI = require ( '../lib/cli' ) ;
1720const yargs = require ( 'yargs' ) ;
1821
1922// This is used for testing
2023// Default cache dir is ${ncu-source-dir}/.ncu/cache
21- jobCache . enable ( ) ;
24+ // jobCache.enable();
2225
2326// eslint-disable-next-line no-unused-vars
2427const argv = yargs
@@ -99,7 +102,8 @@ async function getResults(cli, request, job) {
99102
100103async function main ( command , argv ) {
101104 const cli = new CLI ( ) ;
102- const request = new Request ( { } ) ;
105+ const credentials = await auth ( ) ;
106+ const request = new Request ( credentials ) ;
103107 const queue = [ ] ;
104108
105109 const commandToType = {
@@ -114,31 +118,45 @@ async function main(command, argv) {
114118 queue . push ( {
115119 type : parsed . type ,
116120 jobid : parsed . jobid ,
117- markdown : argv . markdown
121+ copy : argv . copy
118122 } ) ;
119123 } else {
120- // TODO: parse CI links from PR thread
121- return yargs . showHelp ( ) ;
124+ const parser = await JobParser . fromPR ( argv . url , cli , request ) ;
125+ if ( ! parser ) { // Not a valid PR URL
126+ return yargs . showHelp ( ) ;
127+ }
128+ const ciMap = parser . parse ( ) ;
129+ for ( const [ type , ci ] of ciMap ) {
130+ queue . push ( {
131+ type : type ,
132+ jobid : ci . jobid ,
133+ copy : argv . copy
134+ } ) ;
135+ }
122136 }
123137 } else {
124138 queue . push ( {
125139 type : commandToType [ command ] ,
126140 jobid : argv . jobid ,
127- markdown : argv . markdown
141+ copy : argv . copy
128142 } ) ;
129143 }
130144
145+ let dataToCopy = '' ;
146+
131147 for ( let job of queue ) {
132148 const build = await getResults ( cli , request , job ) ;
133149 build . display ( ) ;
134150
135151 if ( argv . copy ) {
136- clipboardy . writeSync ( build . formatAsMarkdown ( ) ) ;
152+ dataToCopy += build . formatAsMarkdown ( ) ;
137153 }
154+ }
138155
156+ if ( argv . copy ) {
157+ clipboardy . writeSync ( dataToCopy ) ;
139158 cli . separator ( '' ) ;
140159 cli . log ( `Written markdown to clipboard` ) ;
141- return build ;
142160 }
143161}
144162
0 commit comments