@uxf/scripts 11.14.0 → 11.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/GitLab.js
CHANGED
|
@@ -121,11 +121,14 @@ function getSingleMergeRequestChanges(projectId, mr_iid) {
|
|
|
121
121
|
return axios.get(`/projects/${projectId}/merge_requests/${mr_iid}/changes`).then((r) => r.data);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
/**
|
|
125
|
+
* @param {boolean} includeWip
|
|
126
|
+
*/
|
|
127
|
+
function getAllMergeRequests(includeWip) {
|
|
125
128
|
return getAll("/merge_requests", {
|
|
126
129
|
params: {
|
|
127
130
|
approwed: "no",
|
|
128
|
-
wip: "no",
|
|
131
|
+
wip: includeWip ? undefined : "no",
|
|
129
132
|
sort: "asc",
|
|
130
133
|
scope: "all",
|
|
131
134
|
state: "opened",
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
const { argv, env } = require("process");
|
|
2
2
|
|
|
3
|
+
const AVAILABLE_VARIANTS = ["CR", "STALE"];
|
|
4
|
+
|
|
3
5
|
module.exports = async () => {
|
|
4
6
|
const cli = require("yargs")
|
|
5
7
|
.command("$0", "UXF merge requests notifier", (yargs) => {
|
|
6
8
|
yargs.demandCommand(0, 0).usage(`Usage:
|
|
7
9
|
uxf-merge-requests-notifier [options]
|
|
8
|
-
|
|
10
|
+
|
|
9
11
|
Environment variables:
|
|
12
|
+
VARIANT - optional - CR (default), STALE
|
|
10
13
|
GITLAB_TOKEN - required
|
|
11
14
|
GOOGLE_WEBHOOK_URL - required
|
|
12
15
|
CI_SERVER_URL - required - setting by GitLab CI`);
|
|
@@ -32,7 +35,14 @@ Environment variables:
|
|
|
32
35
|
return 1;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
const variant = env.VARIANT?.toUpperCase() ?? "CR";
|
|
39
|
+
|
|
40
|
+
if (!AVAILABLE_VARIANTS.includes(variant)) {
|
|
41
|
+
console.log(`Unknown "${variant}" variant. Available variants are ${AVAILABLE_VARIANTS.join(", ")}.`);
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await require("./index")(variant);
|
|
36
46
|
} catch (e) {
|
|
37
47
|
console.error(e);
|
|
38
48
|
return 1;
|
|
@@ -10,41 +10,59 @@ function inflect(value, word1, word2, word3) {
|
|
|
10
10
|
return `${value} ${value === 1 ? word1 : value <= 4 ? word2 : word3}`;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
function mapMergeRequests(mrs, projects) {
|
|
14
|
+
return mrs.map((mr) => ({
|
|
15
|
+
id: mr.id,
|
|
16
|
+
iid: mr.iid,
|
|
17
|
+
reviewers: mr.reviewers ?? [],
|
|
18
|
+
project: projects.find((project) => project.id === mr.project_id),
|
|
19
|
+
title: mr.title,
|
|
20
|
+
author: mr.author,
|
|
21
|
+
createdAt: mr.created_at,
|
|
22
|
+
updatedAt: mr.updated_at,
|
|
23
|
+
webUrl: mr.web_url,
|
|
24
|
+
state: mr.state.toUpperCase(),
|
|
25
|
+
targetBranch: mr.target_branch,
|
|
26
|
+
sourceBranch: mr.source_branch,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getChatPostMessage(resultsCount, variant) {
|
|
31
|
+
switch (variant) {
|
|
32
|
+
case "CR":
|
|
33
|
+
return `🔥🔥🔥 ${inflect(resultsCount, "MR čekající na code review", "MR čekající na code review", "MR čekajících na code review",)}`;
|
|
34
|
+
case "STALE":
|
|
35
|
+
return `❗❗❗ ${inflect(resultsCount, "MR starší než měsíc", "MR starší než měsíc", "MR starších než měsíc")}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param variant
|
|
41
|
+
*/
|
|
42
|
+
module.exports = async function run(variant) {
|
|
14
43
|
const projects = await GitLab.getAllProjects();
|
|
15
|
-
const allMergeRequests = await GitLab.getAllMergeRequests();
|
|
44
|
+
const allMergeRequests = await GitLab.getAllMergeRequests(variant === "STALE");
|
|
16
45
|
|
|
17
|
-
|
|
18
|
-
.map((mr) => ({
|
|
19
|
-
id: mr.id,
|
|
20
|
-
iid: mr.iid,
|
|
21
|
-
reviewers: mr.reviewers ?? [],
|
|
22
|
-
project: projects.find((project) => project.id === mr.project_id),
|
|
23
|
-
title: mr.title,
|
|
24
|
-
author: mr.author,
|
|
25
|
-
createdAt: mr.created_at,
|
|
26
|
-
updatedAt: mr.updated_at,
|
|
27
|
-
webUrl: mr.web_url,
|
|
28
|
-
state: mr.state.toUpperCase(),
|
|
29
|
-
targetBranch: mr.target_branch,
|
|
30
|
-
sourceBranch: mr.source_branch,
|
|
31
|
-
}))
|
|
32
|
-
.filter((mr) => mr.reviewers.length === 0)
|
|
46
|
+
let result = mapMergeRequests(allMergeRequests, projects)
|
|
33
47
|
.filter((mr) => mr.sourceBranch !== "develop" || mr.targetBranch !== "master")
|
|
34
48
|
.filter((mr) => !mr.project.archived);
|
|
35
49
|
|
|
50
|
+
switch (variant) {
|
|
51
|
+
case "CR":
|
|
52
|
+
result = result.filter((mr) => mr.reviewers.length === 0);
|
|
53
|
+
break;
|
|
54
|
+
case "STALE":
|
|
55
|
+
result = result.filter(mr => dayjs().diff(mr.updatedAt, "days") > 30);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
|
|
36
59
|
if (result.length === 0) {
|
|
37
|
-
console.log("No merge requests
|
|
60
|
+
console.log("No merge requests.");
|
|
38
61
|
return;
|
|
39
62
|
}
|
|
40
63
|
|
|
41
64
|
await GoogleChat.chatPostMessage({
|
|
42
|
-
text:
|
|
43
|
-
result.length,
|
|
44
|
-
"MR čekající na code review",
|
|
45
|
-
"MR čekající na code review",
|
|
46
|
-
"MR čekajících na code review",
|
|
47
|
-
)}`,
|
|
65
|
+
text: getChatPostMessage(result.length, variant),
|
|
48
66
|
});
|
|
49
67
|
|
|
50
68
|
for (const mr of result) {
|