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
|
const fs = require('fs');
const axios = require('axios');
if (fs.existsSync("projects")) fs.rmSync("projects", { recursive: true });
fs.mkdirSync("projects");
(async () => {
console.log("Loading access token...");
const token = fs.readFileSync("token.txt").toString().trim();
console.log("Fetching projects...");
const projects = (await axios.get("https://ci.minteck.org/app/rest/projects", { headers: {"Authorization": "Bearer " + token} })).data.project;
fs.writeFileSync("projects.json", JSON.stringify(projects, null, 4));
for (const prj of projects) {
let prjData = {
id: prj.id,
name: (prj.parentProjectId !== "_Root" ? prj.parentProjectId + " " : "") + prj.name,
description: prj.description ?? null,
web: prj.webUrl,
channels: []
};
if (prj.id === "_Root") continue;
console.log("Fetching: " + prj.id + ", deploy channels");
const channels = (await axios.get("https://ci.minteck.org/app/rest/projects/id:" + prj.id, { headers: {"Authorization": "Bearer " + token} })).data.buildTypes.buildType;
for (const channel of channels) {
if (channel.name === "Quality Assurance") continue;
let chan = {
id: channel.id,
name: channel.name,
slug: channel.name.toLowerCase().replace(/[^a-z\d]/gmi, ""),
web: channel.webUrl,
builds: []
}
console.log("Fetching: " + prj.id + ", deploy channels: " + channel.id);
const builds = (await axios.get("https://ci.minteck.org/app/rest/buildTypes/id:" + channel.id + "/builds/", { headers: {"Authorization": "Bearer " + token} })).data.build;
for (const build of builds) {
if (build.status !== "SUCCESS" || build.state !== "finished") continue;
let b = {
id: build.id,
localId: build.number - 1 + 1,
date: new Date(build.finishOnAgentDate.substring(0, 4) + "-" + build.finishOnAgentDate.substring(4, 6) + "-" + build.finishOnAgentDate.substring(6, 8) + "T" + build.finishOnAgentDate.substring(9, 11) + ":" + build.finishOnAgentDate.substring(11, 13) + ":" + build.finishOnAgentDate.substring(13, 15) + "+" + build.finishOnAgentDate.substring(16, 18) + ":" + build.finishOnAgentDate.substring(18, 20)).toISOString(),
branch: build.branchName,
web: build.webUrl,
agent: null,
artifacts: []
}
console.log("Fetching: " + prj.id + ", deploy channels: " + channel.id + ", build: " + build.id + "/" + build.number);
const artifacts = (await axios.get("https://ci.minteck.org/app/rest/builds/id:" + build.id + "/artifacts/children/", { headers: {"Authorization": "Bearer " + token} })).data.file;
for (const artifact of artifacts) {
let af = {
name: artifact.name,
size: artifact.size,
download: "https://ci.minteck.org" + (artifact.content ? artifact.content.href : artifact.children.href + "/" + artifact.name)
}
b.artifacts.push(af);
}
chan.builds.push(b);
}
if (chan.builds.length > 0) {
prjData.channels.push(chan);
}
}
if (prjData.channels.length > 0) {
fs.writeFileSync("projects/" + prj.id + ".json", JSON.stringify(prjData, null, 4));
}
}
})()
|