-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircleCi.ts
100 lines (90 loc) · 2.08 KB
/
CircleCi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import axios from 'axios';
const URL_PREFIX = 'https://circleci.com/api/v1.1';
// Rough shape, can be refined
export interface ShallowBuild {
committer_date: string;
body: string;
usage_queued_at: string;
reponame: string;
build_url: string;
parallel: number;
branch: string;
username: string;
author_date: string;
why: string;
user: {
is_user: boolean;
login: string;
avatar_url: string;
name: string;
vcs_type: string;
id: number;
};
vcs_revision: string;
workflows: {
job_name: string;
job_id: string;
workflow_id: string;
workspace_id: string;
upstream_job_ids: string[];
upstream_concurrency_map: {};
workflow_name: string;
};
vcs_tag: string | null;
pull_requests: [];
build_num: number;
committer_email: string;
status: string;
committer_name: string;
subject: string;
dont_build: null;
lifecycle: string;
fleet: string;
stop_time: string;
build_time_millis: number;
start_time: string;
platform: string;
outcome: string;
vcs_url: string;
author_name: string;
queued_at: string;
author_email: string;
}
export interface Artifact {
path: string;
node_index: number;
url: string;
}
export interface CircleCiOptions {
vcsType: 'github' | 'bitbucket';
username: string;
project: string;
}
/**
* Very rough CircleCI API wrapper
*/
export default class CircleCi {
constructor(private readonly options: CircleCiOptions) {}
private get optionsUrl() {
return `${this.options.vcsType}/${this.options.username}/${this.options.project}`;
}
async getBuilds(): Promise<ShallowBuild[]> {
const response = await axios.get<ShallowBuild[]>(
`${URL_PREFIX}/project/${this.optionsUrl}`,
{
params: {
shallow: true,
filter: 'completed',
limit: 100,
},
},
);
return response.data;
}
async getArtifacts(buildNumber: number): Promise<Artifact[]> {
const response = await axios.get<Artifact[]>(
`${URL_PREFIX}/project/${this.optionsUrl}/${buildNumber}/artifacts`,
);
return response.data;
}
}