@uxf/scripts 11.13.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/bin/uxf-audit.js
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/scripts",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.21.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
|
+
"uxf-audit": "bin/uxf-audit.js",
|
|
7
8
|
"uxf-lunch": "bin/uxf-lunch.js",
|
|
8
9
|
"uxf-release": "bin/uxf-release.js",
|
|
9
10
|
"uxf-sitemap-check": "bin/uxf-sitemap-check.js",
|
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",
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const exec = require("child_process").exec;
|
|
2
|
+
|
|
3
|
+
function execute(command) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
exec(command, function (error, stdout, stderr) {
|
|
6
|
+
resolve(stdout);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function executeJson(command) {
|
|
12
|
+
return execute(command).then((output) => JSON.parse(output));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function parsePackageName(name) {
|
|
16
|
+
if (name.charAt(0) === "@") {
|
|
17
|
+
const [nameWithoutAt, version] = name.replace("@", "").split("@");
|
|
18
|
+
|
|
19
|
+
return [`@${nameWithoutAt}`, version];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return name.split("@");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getUxfPackagesInfo() {
|
|
26
|
+
return executeJson('yarn list --pattern "@uxf" --depth=1 --json').then((output) => {
|
|
27
|
+
const result = {};
|
|
28
|
+
|
|
29
|
+
output.data.trees
|
|
30
|
+
.map((info) => {
|
|
31
|
+
const [name, version] = parsePackageName(info.name);
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
version,
|
|
35
|
+
isError: info.children.length > 0,
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.forEach((item) => {
|
|
39
|
+
result[item.name] = item;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getPackageVersion(packageName) {
|
|
47
|
+
return executeJson(`yarn list ${packageName} --depth=0 --json`).then((output) => {
|
|
48
|
+
return parsePackageName(output.data.trees[0].name)[1];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getNodeVersion() {
|
|
53
|
+
return execute("node -v").then((output) => {
|
|
54
|
+
return output.replace("v", "").trim();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = async function run() {
|
|
59
|
+
console.log(
|
|
60
|
+
JSON.stringify(
|
|
61
|
+
{
|
|
62
|
+
node: await getNodeVersion(),
|
|
63
|
+
next: await getPackageVersion("next"),
|
|
64
|
+
react: await getPackageVersion("react"),
|
|
65
|
+
"react-dom": await getPackageVersion("react-dom"),
|
|
66
|
+
packages: await getUxfPackagesInfo(),
|
|
67
|
+
},
|
|
68
|
+
null,
|
|
69
|
+
" ",
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
};
|
|
@@ -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) {
|