-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.js
93 lines (82 loc) · 2.25 KB
/
adapter.js
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
const axios = require("axios");
const checkLower1_7_8 = async (
CT_BASE_URL,
projectName,
authToken,
CT_ORGANIZATION
) => {
let checkProject;
try {
checkProject = await axios.get(
`${CT_BASE_URL}/api/project?key=${projectName}`,
{
headers: {
Authorization: authToken,
"x-ct-organization": CT_ORGANIZATION,
},
}
);
} catch (error) {
if (
(error.response &&
error.response.data &&
error.response.data.code === 404) ||
error.response.data.code === 400
) {
return {
type: null,
};
} else if (error.response && error.response.data) {
throw new Error(JSON.stringify(error.response.data));
} else throw new Error(JSON.stringify(error));
}
if (checkProject.data.type !== "gitlab") {
throw new Error(
"There is a project with this name, but its type is not gitlab."
);
}
return checkProject.data;
};
const checkUpper1_7_8 = async (ctServer, repoName, authToken, orgname) => {
let checkProject;
try {
checkProject = await axios.get(`${ctServer}/api/project?key=${repoName}`, {
headers: {
Authorization: authToken,
"x-ct-organization": orgname,
},
});
} catch (error) {
if (error.response && error.response.data) {
throw new Error(JSON.stringify(error.response.data));
} else throw new Error(JSON.stringify(error));
}
if (checkProject.data && checkProject.data.length <= 0) {
return { type: null };
} else {
if (checkProject.data.type !== "gitlab") {
throw new Error(
"There is a project with this name, but its type is not gitlab."
);
}
return checkProject.data;
}
};
const compareVersions = (version1, version2) => {
if (!version2) return 1;
const parseVersion = (version) => version.split(".").map(Number);
const [major1, minor1, patch1] = parseVersion(version1);
const [major2, minor2, patch2] = parseVersion(version2);
if (major1 > major2) return 1;
if (major1 < major2) return -1;
if (minor1 > minor2) return 1;
if (minor1 < minor2) return -1;
if (patch1 > patch2) return 1;
if (patch1 < patch2) return -1;
return 1; //eq
};
module.exports = {
checkLower1_7_8,
checkUpper1_7_8,
compareVersions,
};