|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import fetch from 'node-fetch'; |
| 10 | +import {fetchActiveReleaseTrains} from '../../release/versioning/index'; |
10 | 11 |
|
11 | | -import {bold, green, info, red} from '../../utils/console'; |
| 12 | +import {bold, debug, info} from '../../utils/console'; |
12 | 13 | import {GitClient} from '../../utils/git'; |
13 | 14 |
|
14 | 15 |
|
15 | 16 | /** The results of checking the status of CI. */ |
16 | 17 | interface StatusCheckResult { |
17 | | - status: 'success'|'failed'|'canceled'|'infrastructure_fail'|'timedout'|'failed'|'no_tests'; |
18 | | - timestamp: Date; |
19 | | - buildUrl: string; |
| 18 | + status: 'success'|'failed'; |
20 | 19 | } |
21 | 20 |
|
22 | 21 | /** Retrieve and log status of CI for the project. */ |
23 | 22 | export async function printCiStatus(git: GitClient) { |
| 23 | + const releaseTrains = await fetchActiveReleaseTrains({api: git.github, ...git.remoteConfig}); |
| 24 | + |
24 | 25 | info.group(bold(`CI`)); |
25 | | - // TODO(josephperrott): Expand list of branches checked to all active branches. |
26 | | - await printStatus(git, 'master'); |
| 26 | + for (const [trainName, train] of Object.entries(releaseTrains)) { |
| 27 | + if (train === null) { |
| 28 | + debug(`No active release train for ${trainName}`); |
| 29 | + continue; |
| 30 | + } |
| 31 | + const status = await getStatusOfBranch(git, train.branchName); |
| 32 | + await printStatus(`${trainName.padEnd(6)} (${train.branchName})`, status); |
| 33 | + } |
27 | 34 | info.groupEnd(); |
28 | 35 | info(); |
29 | 36 | } |
30 | 37 |
|
31 | 38 | /** Log the status of CI for a given branch to the console. */ |
32 | | -async function printStatus(git: GitClient, branch: string) { |
33 | | - const result = await getStatusOfBranch(git, branch); |
34 | | - const branchName = branch.padEnd(10); |
35 | | - if (result === null) { |
| 39 | +async function printStatus(label: string, status: StatusCheckResult|null) { |
| 40 | + const branchName = label.padEnd(16); |
| 41 | + if (status === null) { |
36 | 42 | info(`${branchName} was not found on CircleCI`); |
37 | | - } else if (result.status === 'success') { |
| 43 | + } else if (status.status === 'success') { |
38 | 44 | info(`${branchName} ✅`); |
39 | 45 | } else { |
40 | | - info(`${branchName} ❌ (Ran at: ${result.timestamp.toLocaleString()})`); |
| 46 | + info(`${branchName} ❌`); |
41 | 47 | } |
42 | 48 | } |
43 | 49 |
|
44 | 50 | /** Get the CI status of a given branch from CircleCI. */ |
45 | 51 | async function getStatusOfBranch(git: GitClient, branch: string): Promise<StatusCheckResult|null> { |
46 | 52 | const {owner, name} = git.remoteConfig; |
47 | | - const url = `https://circleci.com/api/v1.1/project/gh/${owner}/${name}/tree/${ |
48 | | - branch}?limit=1&filter=completed&shallow=true`; |
49 | | - const result = (await fetch(url).then(result => result.json()))?.[0]; |
| 53 | + const url = `https://circleci.com/gh/${owner}/${name}/tree/${branch}.svg?style=shield`; |
| 54 | + const result = await fetch(url).then(result => result.text()); |
50 | 55 |
|
51 | | - if (result) { |
| 56 | + if (result && !result.includes('no builds')) { |
52 | 57 | return { |
53 | | - status: result.outcome, |
54 | | - timestamp: new Date(result.stop_time), |
55 | | - buildUrl: result.build_url |
| 58 | + status: result.includes('passing') ? 'success' : 'failed', |
56 | 59 | }; |
57 | 60 | } |
58 | 61 | return null; |
|
0 commit comments