@uxf/scripts 11.32.0 → 11.41.5
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/README.md +20 -1
- package/bin/uxf-push-notifier.js +8 -0
- package/package.json +37 -36
- package/src/uxf-audit/index.js +52 -11
- package/src/uxf-push-notifier/cli.js +30 -0
- package/src/uxf-push-notifier/index.js +61 -0
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ Options:
|
|
|
32
32
|
set environment variable `GITLAB_TOKEN` in GitLab CI configuration and create `.gitlab-ci.yml`
|
|
33
33
|
|
|
34
34
|
```yaml
|
|
35
|
+
# .gitlab-ci.yml
|
|
35
36
|
stages:
|
|
36
37
|
- release
|
|
37
38
|
|
|
@@ -44,6 +45,24 @@ release:
|
|
|
44
45
|
# ... deploy project ...
|
|
45
46
|
- uxf-release
|
|
46
47
|
```
|
|
48
|
+
|
|
49
|
+
## uxf-push-notifier
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
stages:
|
|
53
|
+
- notify
|
|
54
|
+
|
|
55
|
+
notify-push:
|
|
56
|
+
image: node:20
|
|
57
|
+
stage: notify
|
|
58
|
+
except: [schedules]
|
|
59
|
+
only:
|
|
60
|
+
- develop # default branch
|
|
61
|
+
script:
|
|
62
|
+
- yarn global add @uxf/scripts # uxf scripts are installed in uxf docker images by default
|
|
63
|
+
- uxf-push-notifier --google-chat-webhook-url=$GOOGLE_CHAT_WEBHOOK
|
|
64
|
+
```
|
|
65
|
+
|
|
47
66
|
## uxf-lunch
|
|
48
67
|
|
|
49
68
|
```bash
|
|
@@ -60,4 +79,4 @@ Options
|
|
|
60
79
|
|
|
61
80
|
Options:
|
|
62
81
|
--version Show version number
|
|
63
|
-
```
|
|
82
|
+
```
|
package/package.json
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
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
|
-
}
|
|
2
|
+
"name": "@uxf/scripts",
|
|
3
|
+
"version": "11.41.5",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"uxf-audit": "bin/uxf-audit.js",
|
|
8
|
+
"uxf-lunch": "bin/uxf-lunch.js",
|
|
9
|
+
"uxf-push-notifier": "bin/uxf-push-notifier.js",
|
|
10
|
+
"uxf-release": "bin/uxf-release.js",
|
|
11
|
+
"uxf-sitemap-check": "bin/uxf-sitemap-check.js",
|
|
12
|
+
"uxf-sitemap-meta-export": "bin/uxf-sitemap-meta-export.js",
|
|
13
|
+
"uxf-i18n-namespaces-gen": "bin/uxf-i18n-namespaces-gen.js",
|
|
14
|
+
"uxf-unused": "bin/uxf-unused.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "",
|
|
18
|
+
"typecheck": "",
|
|
19
|
+
"test": "./node_modules/.bin/eslint ./bin",
|
|
20
|
+
"run:mr-notifier": "GOOGLE_WEBHOOK_URL=<<TODO>> GITLAB_TOKEN=<<TODO>> CI_SERVER_URL=https://gitlab.uxf.cz node ./bin/uxf-merge-requests-notifier.js"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git"
|
|
27
|
+
},
|
|
28
|
+
"author": "",
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"axios": "1.7.5",
|
|
32
|
+
"cheerio": "1.0.0",
|
|
33
|
+
"dayjs": "1.11.13",
|
|
34
|
+
"fast-glob": "3.3.2",
|
|
35
|
+
"madge": "8.0.0",
|
|
36
|
+
"yargs": "17.7.2"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/uxf-audit/index.js
CHANGED
|
@@ -9,24 +9,51 @@ function execute(command) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function executeJson(command) {
|
|
12
|
-
return execute(command).then((output) =>
|
|
12
|
+
return execute(command).then((output) =>
|
|
13
|
+
output
|
|
14
|
+
.split("\n")
|
|
15
|
+
.filter((s) => s !== "")
|
|
16
|
+
.map(JSON.parse),
|
|
17
|
+
);
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
function parsePackageName(name) {
|
|
16
21
|
if (name.charAt(0) === "@") {
|
|
17
22
|
const [nameWithoutAt, version] = name.replace("@", "").split("@");
|
|
18
23
|
|
|
19
|
-
return [`@${nameWithoutAt}`, version];
|
|
24
|
+
return [`@${nameWithoutAt}`, version.replace(/^npm:/, "")];
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
const [nameWithoutAt, version] = name.split("@");
|
|
28
|
+
return [nameWithoutAt, version.replace(/^npm:/, "")];
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
function getUxfPackagesInfo() {
|
|
31
|
+
function getUxfPackagesInfo(yarnVersion) {
|
|
32
|
+
if (yarnVersion > 1) {
|
|
33
|
+
return executeJson('yarn info "@uxf/*" --json').then((output) => {
|
|
34
|
+
const result = {};
|
|
35
|
+
|
|
36
|
+
output
|
|
37
|
+
.map((info) => {
|
|
38
|
+
const [name, version] = parsePackageName(info.value);
|
|
39
|
+
return {
|
|
40
|
+
name,
|
|
41
|
+
version,
|
|
42
|
+
isError: false, // TODO
|
|
43
|
+
};
|
|
44
|
+
})
|
|
45
|
+
.forEach((item) => {
|
|
46
|
+
result[item.name] = item;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
26
53
|
return executeJson('yarn list --pattern "@uxf" --depth=1 --json').then((output) => {
|
|
27
54
|
const result = {};
|
|
28
55
|
|
|
29
|
-
output.data.trees
|
|
56
|
+
output[0].data.trees
|
|
30
57
|
.map((info) => {
|
|
31
58
|
const [name, version] = parsePackageName(info.name);
|
|
32
59
|
return {
|
|
@@ -43,9 +70,13 @@ function getUxfPackagesInfo() {
|
|
|
43
70
|
});
|
|
44
71
|
}
|
|
45
72
|
|
|
46
|
-
function getPackageVersion(packageName) {
|
|
73
|
+
function getPackageVersion(packageName, yarnVersion) {
|
|
74
|
+
if (yarnVersion > 1) {
|
|
75
|
+
return executeJson(`yarn info ${packageName} --json`).then((output) => parsePackageName(output[0].value)[1]);
|
|
76
|
+
}
|
|
77
|
+
|
|
47
78
|
return executeJson(`yarn list ${packageName} --depth=0 --json`).then((output) => {
|
|
48
|
-
return parsePackageName(output.data.trees[0].name)[1];
|
|
79
|
+
return parsePackageName(output[0].data.trees[0].name)[1];
|
|
49
80
|
});
|
|
50
81
|
}
|
|
51
82
|
|
|
@@ -55,15 +86,25 @@ function getNodeVersion() {
|
|
|
55
86
|
});
|
|
56
87
|
}
|
|
57
88
|
|
|
89
|
+
function getYarnVersion() {
|
|
90
|
+
return execute("yarn -v").then((output) => {
|
|
91
|
+
return output.trim();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
58
95
|
module.exports = async function run() {
|
|
96
|
+
const yarn = await getYarnVersion();
|
|
97
|
+
const yarnVersion = Number(yarn.replace(/\..*/, ""));
|
|
98
|
+
|
|
59
99
|
console.log(
|
|
60
100
|
JSON.stringify(
|
|
61
101
|
{
|
|
62
102
|
node: await getNodeVersion(),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
103
|
+
yarn,
|
|
104
|
+
next: await getPackageVersion("next", yarnVersion),
|
|
105
|
+
react: await getPackageVersion("react", yarnVersion),
|
|
106
|
+
"react-dom": await getPackageVersion("react-dom", yarnVersion),
|
|
107
|
+
packages: await getUxfPackagesInfo(yarnVersion),
|
|
67
108
|
},
|
|
68
109
|
null,
|
|
69
110
|
" ",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { argv, env } = require("process");
|
|
2
|
+
|
|
3
|
+
module.exports = async () => {
|
|
4
|
+
const cli = require("yargs")
|
|
5
|
+
.command("$0", "UXF push notifier", (yargs) => {
|
|
6
|
+
yargs.demandCommand(0, 0).usage(`Usage:
|
|
7
|
+
uxf-push-notifier [options]
|
|
8
|
+
|
|
9
|
+
Environment variables:
|
|
10
|
+
GITLAB_TOKEN - required
|
|
11
|
+
`);
|
|
12
|
+
})
|
|
13
|
+
.option("g", { alias: "google-chat-webhook-url", group: "Options" })
|
|
14
|
+
.option("h", { alias: "help", group: "Options" })
|
|
15
|
+
.strict(false)
|
|
16
|
+
.exitProcess(false);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const { help, g: googleChatWebhookUrl } = cli.parse(argv.slice(2));
|
|
20
|
+
|
|
21
|
+
if (Boolean(help)) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await require("./index")(googleChatWebhookUrl);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error(e);
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const { create } = require("axios");
|
|
2
|
+
const process = require("process");
|
|
3
|
+
|
|
4
|
+
const { GITLAB_TOKEN, CI_SERVER_URL, CI_COMMIT_SHA, CI_COMMIT_BEFORE_SHA, CI_PROJECT_ID, CI_COMMIT_REF_NAME } =
|
|
5
|
+
process.env;
|
|
6
|
+
|
|
7
|
+
const gitlabAxios = create({
|
|
8
|
+
baseURL: `${CI_SERVER_URL}/api/v4`,
|
|
9
|
+
headers: {
|
|
10
|
+
Authorization: `Bearer ${GITLAB_TOKEN}`,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const googleChatAxios = create({});
|
|
15
|
+
|
|
16
|
+
function findCurrentlyMergedMergeRequest() {
|
|
17
|
+
return gitlabAxios
|
|
18
|
+
.get(
|
|
19
|
+
`/projects/${CI_PROJECT_ID}/merge_requests?state=merged&target_branch=${CI_COMMIT_REF_NAME}&order_by=updated_at&sort=desc`,
|
|
20
|
+
)
|
|
21
|
+
.then((response) => (response.data?.[0]?.sha === CI_COMMIT_SHA ? response.data[0] : null));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getApprovalUserNames(iid) {
|
|
25
|
+
return gitlabAxios
|
|
26
|
+
.get(`/projects/${CI_PROJECT_ID}/merge_requests/${iid}/approvals`)
|
|
27
|
+
.then((response) => response.data.approved_by.map((item) => item.user.name));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getPushedCommits() {
|
|
31
|
+
return gitlabAxios
|
|
32
|
+
.get(`/projects/${CI_PROJECT_ID}/repository/compare?from=${CI_COMMIT_BEFORE_SHA}&to=${CI_COMMIT_SHA}`)
|
|
33
|
+
.then((response) => response.data.commits);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = async function (googleChatWebhookUrl) {
|
|
37
|
+
const mr = await findCurrentlyMergedMergeRequest();
|
|
38
|
+
|
|
39
|
+
if (mr !== null) {
|
|
40
|
+
const approvalUserNames = await getApprovalUserNames(mr.iid);
|
|
41
|
+
|
|
42
|
+
const isApproved = !!approvalUserNames.find((name) => name !== mr.author.name);
|
|
43
|
+
|
|
44
|
+
const text = `${isApproved ? "✅" : "❗"} Merge request byl zamergován
|
|
45
|
+
<${mr.web_url}|${mr.title}>
|
|
46
|
+
Autor: ${mr.author.name}
|
|
47
|
+
Schválil: ${isApproved ? approvalUserNames.join(", ") : "*bez schválení*"}
|
|
48
|
+
Zamergoval: ${mr.merged_by.name}`;
|
|
49
|
+
|
|
50
|
+
await googleChatAxios.post(googleChatWebhookUrl, { text });
|
|
51
|
+
} else {
|
|
52
|
+
const commits = (await getPushedCommits()).map(
|
|
53
|
+
(commit) => `${commit.author_name} - <${commit.web_url}|${commit.title}>`,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
await googleChatAxios.post(googleChatWebhookUrl, {
|
|
57
|
+
text: `❗ Bylo pushnuto do developu.
|
|
58
|
+
${commits.join("\n")}`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|