Skip to content

Commit 976bef4

Browse files
committed
fixup! fixup! fixup! ncu-ci: initial implementation
1 parent e8da1fd commit 976bef4

File tree

5 files changed

+733
-735
lines changed

5 files changed

+733
-735
lines changed

bin/ncu-ci

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
'use strict';
44

55
const {
6-
PRBuild, BenchmarkRun, CommitBuild, jobCache, parseJobFromURL
7-
} = require('../components/jenkins');
6+
PRBuild, BenchmarkRun, CommitBuild, jobCache, parseJobFromURL, constants
7+
} = require('../lib/ci');
8+
9+
const {
10+
PR, COMMIT, BENCHMARK
11+
} = constants;
12+
813
const { runPromise } = require('../lib/run');
914
const Request = require('../lib/request');
1015
const CLI = require('../lib/cli');
11-
const { parsePRFromURL } = require('../lib/links');
1216
const yargs = require('yargs');
1317

1418
// This is used for testing
@@ -77,21 +81,18 @@ const argv = yargs
7781
async function getResults(cli, request, job) {
7882
let build;
7983
const { type, jobid, markdown } = job;
80-
switch (type) {
81-
case 'pr':
82-
build = new PRBuild(cli, request, jobid);
83-
await build.getResults();
84-
break;
85-
case 'commit':
86-
build = new CommitBuild(cli, request, jobid);
87-
await build.getResults();
88-
break;
89-
case 'benchmark':
90-
build = new BenchmarkRun(cli, request, jobid);
91-
await build.getResults();
92-
break;
93-
default:
94-
throw new Error('Unknown CI type!');
84+
if (type === PR) {
85+
build = new PRBuild(cli, request, jobid);
86+
await build.getResults();
87+
} else if (type === COMMIT) {
88+
build = new CommitBuild(cli, request, jobid);
89+
await build.getResults();
90+
} else if (type === BENCHMARK) {
91+
build = new BenchmarkRun(cli, request, jobid);
92+
await build.getResults();
93+
} else {
94+
yargs.showHelp();
95+
return;
9596
}
9697

9798
build.display();
@@ -107,25 +108,29 @@ async function main(command, argv) {
107108
const request = new Request({});
108109
const queue = [];
109110

111+
const commandToType = {
112+
'commit': COMMIT,
113+
'pr': PR,
114+
'benchmark': BENCHMARK
115+
};
116+
110117
if (command === 'url') {
111118
let parsed = parseJobFromURL(argv.url);
112119
if (parsed) {
113120
queue.push({
114-
type: parsed.command,
121+
type: parsed.type,
115122
jobid: parsed.jobid,
116123
markdown: argv.markdown
117124
});
118125
} else {
119-
parsed = parsePRFromURL(argv.url);
120-
if (parsed) {
121-
// Get OP and comments from the PR
122-
// const ciMap = new JobParser(thread).parse();
123-
}
126+
// TODO: parse CI links from PR thread
127+
return yargs.showHelp();
124128
}
125129
} else {
126130
queue.push({
127-
type: command,
128-
argv: argv
131+
type: commandToType[command],
132+
jobid: argv.jobid,
133+
markdown: argv.markdown
129134
});
130135
}
131136

0 commit comments

Comments
 (0)