@uxf/scripts 11.21.1 → 11.23.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 +1 -2
- package/src/GitLab.js +1 -35
- package/src/uxf-release/cli.js +6 -10
- package/src/uxf-release/index.js +100 -69
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/scripts",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.23.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"author": "",
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@commitlint/parse": "19.0.3",
|
|
30
29
|
"axios": "1.6.7",
|
|
31
30
|
"cheerio": "1.0.0-rc.12",
|
|
32
31
|
"dayjs": "1.11.10",
|
package/src/GitLab.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const { env } = require("process");
|
|
2
2
|
const { create } = require("axios");
|
|
3
3
|
const dayjs = require("dayjs");
|
|
4
|
-
const parse = import("@commitlint/parse");
|
|
5
4
|
|
|
6
5
|
const axios = create({
|
|
7
6
|
baseURL: `${env.CI_SERVER_URL}/api/v4`,
|
|
@@ -36,7 +35,6 @@ async function getAll(url, config) {
|
|
|
36
35
|
|
|
37
36
|
async function loadCommits(from) {
|
|
38
37
|
const commits = [];
|
|
39
|
-
console.log(`- start date: ${from}`);
|
|
40
38
|
|
|
41
39
|
let nextPage = "1";
|
|
42
40
|
do {
|
|
@@ -52,38 +50,7 @@ async function loadCommits(from) {
|
|
|
52
50
|
commits.push(...response.data);
|
|
53
51
|
} while (nextPage);
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
for (const commit of commits) {
|
|
57
|
-
if (commit.created_at === from) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const parsedTitle = await parse(commit.title, undefined, { issuePrefixes: ["#"] });
|
|
62
|
-
|
|
63
|
-
preparedCommits.push({
|
|
64
|
-
...commit,
|
|
65
|
-
parsedTitle: {
|
|
66
|
-
scope: parsedTitle.scope,
|
|
67
|
-
type: parsedTitle.type,
|
|
68
|
-
subject: (parsedTitle.subject || commit.title).replace(/(#[0-9]*)/g, "").trim(),
|
|
69
|
-
},
|
|
70
|
-
issueIds: parsedTitle.references.map((ref) => Number.parseInt(ref.issue)).filter((i) => !!i),
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return preparedCommits;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function loadIssues(iids) {
|
|
78
|
-
if (iids.length === 0) {
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const { data } = await axios.get(`/projects/${env.CI_PROJECT_ID}/issues`, {
|
|
83
|
-
params: { iids },
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return data;
|
|
53
|
+
return commits.filter((commit) => commit.created_at !== from);
|
|
87
54
|
}
|
|
88
55
|
|
|
89
56
|
async function getLastTag() {
|
|
@@ -143,7 +110,6 @@ function getAllProjects() {
|
|
|
143
110
|
|
|
144
111
|
module.exports = {
|
|
145
112
|
loadCommits,
|
|
146
|
-
loadIssues,
|
|
147
113
|
getLastTag,
|
|
148
114
|
createRelease,
|
|
149
115
|
getAllMergeRequests,
|
package/src/uxf-release/cli.js
CHANGED
|
@@ -2,16 +2,17 @@ const { argv, env } = require("process");
|
|
|
2
2
|
|
|
3
3
|
module.exports = async () => {
|
|
4
4
|
const cli = require("yargs")
|
|
5
|
-
.command("$0", "UXF release helper", yargs => {
|
|
5
|
+
.command("$0", "UXF release helper", (yargs) => {
|
|
6
6
|
yargs.demandCommand(0, 0).usage(`UXF release helper
|
|
7
7
|
Usage:
|
|
8
8
|
uxf-release [options]
|
|
9
9
|
|
|
10
10
|
Environment variables:
|
|
11
|
-
GITLAB_TOKEN
|
|
12
|
-
CI_SERVER_URL
|
|
13
|
-
CI_PROJECT_ID
|
|
14
|
-
SLACK_TOKEN
|
|
11
|
+
GITLAB_TOKEN - required
|
|
12
|
+
CI_SERVER_URL - required - setting by GitLab CI
|
|
13
|
+
CI_PROJECT_ID - required - setting by GitLab CI
|
|
14
|
+
SLACK_TOKEN - optional
|
|
15
|
+
GOOGLE_WEBHOOK_URL - optional`);
|
|
15
16
|
})
|
|
16
17
|
.option("m", {
|
|
17
18
|
alias: "message",
|
|
@@ -55,11 +56,6 @@ Environment variables:
|
|
|
55
56
|
env.CI_PROJECT_ID = projectId;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
if (!slackChannel) {
|
|
59
|
-
console.log("Slack channel must be set. Use parameter -s or --slack-channel");
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
59
|
if (!env.CI_SERVER_URL) {
|
|
64
60
|
console.log("GitLab url must be set. Use environment variable CI_SERVER_URL.");
|
|
65
61
|
return 1;
|
package/src/uxf-release/index.js
CHANGED
|
@@ -2,98 +2,129 @@ const GitLab = require("../GitLab");
|
|
|
2
2
|
const Slack = require("../Slack");
|
|
3
3
|
const GoogleChat = require("../GoogleChat");
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
function parseCommitMessage(commitMessage) {
|
|
6
|
+
/* fix(bo): [KLK-123] commit message */
|
|
7
|
+
const result = /^(.*)\((.*)\): \[(.*)\] (.*)/.exec(commitMessage);
|
|
8
|
+
|
|
9
|
+
if (result !== null) {
|
|
10
|
+
return {
|
|
11
|
+
type: result[1],
|
|
12
|
+
issues: result[3].replace(" ", "").split(","),
|
|
13
|
+
message: result[4],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* fix: [KLK-123] commit message */
|
|
18
|
+
const result_1 = /^(.*): \[(.*)\] (.*)/.exec(commitMessage);
|
|
19
|
+
|
|
20
|
+
if (result_1 !== null) {
|
|
21
|
+
return {
|
|
22
|
+
type: result_1[1],
|
|
23
|
+
issues: result_1[3].replace(" ", "").split(","),
|
|
24
|
+
message: result_1[4],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* [KLK-123] commit message */
|
|
29
|
+
const result_2 = /^\[(.*)\] (.*)/.exec(commitMessage);
|
|
30
|
+
|
|
31
|
+
if (result_2 !== null) {
|
|
32
|
+
return {
|
|
33
|
+
type: null,
|
|
34
|
+
issues: result_2[1].replace(" ", "").split(","),
|
|
35
|
+
message: result_2[2],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function generateSlackCommitMessage(commit) {
|
|
43
|
+
const { title, short_id, web_url, author_email } = commit;
|
|
44
|
+
|
|
45
|
+
const parsedCommit = parseCommitMessage(title);
|
|
46
|
+
|
|
47
|
+
return parsedCommit?.type
|
|
48
|
+
? `• _${parsedCommit.type.toUpperCase()}_ - ${parsedCommit.message} <${web_url}|${short_id}> (${author_email})`
|
|
49
|
+
: `• ${title} <${web_url}|${short_id}> (${author_email})`;
|
|
21
50
|
}
|
|
22
51
|
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
function generateSlackMessage(commits, messageTitle) {
|
|
53
|
+
return {
|
|
54
|
+
text: `${messageTitle}
|
|
55
|
+
|
|
56
|
+
${commits.map(generateSlackCommitMessage).join("\n")}
|
|
57
|
+
`,
|
|
58
|
+
};
|
|
27
59
|
}
|
|
28
60
|
|
|
29
|
-
function
|
|
30
|
-
|
|
61
|
+
function generateGoogleCommitMessage(commit) {
|
|
62
|
+
const { title, short_id, web_url, author_email } = commit;
|
|
63
|
+
const parsedCommit = parseCommitMessage(title);
|
|
64
|
+
|
|
65
|
+
const issues = parsedCommit?.issues.map((issue) => `<https://youtrack.uxf.dev/issue/${issue}|${issue}>`) ?? [];
|
|
31
66
|
|
|
32
|
-
issues.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.join("\n")}`;
|
|
36
|
-
});
|
|
67
|
+
const suffix = [`<${web_url}|${short_id}>`, author_email, issues.length > 0 ? issues.join(", ") : null]
|
|
68
|
+
.filter((i) => !!i)
|
|
69
|
+
.join(" | ");
|
|
37
70
|
|
|
38
|
-
if (
|
|
39
|
-
|
|
71
|
+
if (parsedCommit === null) {
|
|
72
|
+
return `* ${title} ${suffix}`;
|
|
40
73
|
}
|
|
41
74
|
|
|
42
|
-
|
|
43
|
-
}
|
|
75
|
+
if (parsedCommit.type !== null && parsedCommit.message !== null) {
|
|
76
|
+
return `* _${parsedCommit.type.toUpperCase()}_ ${parsedCommit.message} ${suffix}`;
|
|
77
|
+
}
|
|
44
78
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
issues.forEach(issue => {
|
|
48
|
-
texts.push(`*${issue.title}* <${issue.web_url}|#${issue.iid}>`);
|
|
49
|
-
issue.commits.forEach((commit) => texts.push(generateSlackCommitMessage(commit)));
|
|
50
|
-
});
|
|
51
|
-
if (commitsWithoutIssues.length > 0) {
|
|
52
|
-
texts.push(`*Commity bez issue*`);
|
|
53
|
-
commitsWithoutIssues.forEach((commit) => texts.push(generateSlackCommitMessage(commit)));
|
|
79
|
+
if (parsedCommit.message) {
|
|
80
|
+
return `* ${parsedCommit.message} ${suffix}`;
|
|
54
81
|
}
|
|
82
|
+
|
|
83
|
+
return `* ${title} ${suffix}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function generateGoogleMessage(commits, messageTitle) {
|
|
55
87
|
return {
|
|
56
|
-
text:
|
|
88
|
+
text: `${messageTitle}
|
|
89
|
+
|
|
90
|
+
${commits.map(generateGoogleCommitMessage).join("\n")}
|
|
91
|
+
`,
|
|
57
92
|
};
|
|
58
93
|
}
|
|
59
94
|
|
|
60
|
-
function
|
|
61
|
-
const { title,
|
|
95
|
+
function generateReleaseCommitMessage(commit) {
|
|
96
|
+
const { title, short_id, web_url, author_email } = commit;
|
|
62
97
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} <${web_url}|${short_id}> (${author_email})`
|
|
67
|
-
: `• ${title} <${web_url}|${short_id}> (${author_email})`;
|
|
68
|
-
}
|
|
98
|
+
const parsedCommit = parseCommitMessage(title);
|
|
99
|
+
|
|
100
|
+
const issues = parsedCommit?.issues.map((issue) => `[${issue}](https://youtrack.uxf.dev/issue/${issue})`) ?? [];
|
|
69
101
|
|
|
70
|
-
|
|
71
|
-
|
|
102
|
+
const suffix = [`[${short_id}](${web_url})`, author_email, issues.length > 0 ? issues.join(", ") : null]
|
|
103
|
+
.filter((i) => !!i)
|
|
104
|
+
.join(" | ");
|
|
72
105
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
if (parsedCommit === null) {
|
|
107
|
+
return `- ${title} ${suffix}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (parsedCommit.type !== null && parsedCommit.message !== null) {
|
|
111
|
+
return `- **${parsedCommit.type.toUpperCase()}** ${parsedCommit.message} ${suffix}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (parsedCommit.message) {
|
|
115
|
+
return `- ${parsedCommit.message} ${suffix}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return `- ${title} ${suffix}`;
|
|
76
119
|
}
|
|
77
120
|
|
|
78
121
|
module.exports = async (dryRun, channel, messageTitle) => {
|
|
79
122
|
const lastTag = await GitLab.getLastTag();
|
|
80
123
|
const commits = await GitLab.loadCommits(lastTag ? lastTag.commit.committed_date : null);
|
|
81
|
-
const issues = await GitLab.loadIssues(getIssueIdsFromCommits(commits));
|
|
82
|
-
|
|
83
|
-
addCommitsToIssues(commits, issues);
|
|
84
|
-
|
|
85
|
-
const commitsWithoutIssue = commits.filter(c => c.issueIds.length === 0);
|
|
86
124
|
|
|
87
|
-
await Slack.chatPostMessage(
|
|
88
|
-
channel,
|
|
89
|
-
{ text: generateSlackMessage(issues, commitsWithoutIssue, messageTitle) },
|
|
90
|
-
dryRun,
|
|
91
|
-
);
|
|
125
|
+
await Slack.chatPostMessage(channel, { text: generateSlackMessage(commits, messageTitle) }, dryRun);
|
|
92
126
|
|
|
93
|
-
await GoogleChat.chatPostMessage(
|
|
94
|
-
generateGoogleMessage(issues, commitsWithoutIssue, messageTitle),
|
|
95
|
-
dryRun,
|
|
96
|
-
);
|
|
127
|
+
await GoogleChat.chatPostMessage(generateGoogleMessage(commits, messageTitle), dryRun);
|
|
97
128
|
|
|
98
|
-
await GitLab.createRelease(commits.map(
|
|
129
|
+
await GitLab.createRelease(commits.map(generateReleaseCommitMessage).join("\n"), dryRun);
|
|
99
130
|
};
|