@uxf/scripts 1.5.3 → 1.5.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/Makefile +1 -1
- package/package.json +1 -1
- package/src/GoogleChat.js +20 -0
- package/src/uxf-release/index.js +21 -0
- package/src/uxf-sitemap-check/index.js +24 -14
package/Makefile
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
uxf-release:
|
|
2
|
-
CI_SERVER_URL=https://gitlab.uxf.cz GITLAB_TOKEN= SLACK_TOKEN=xoxb- ./bin/uxf-release.js --slack-channel=C01NQK3LY9Z --project-id=156 --message=":beer: Kalkulator.cz"
|
|
2
|
+
CI_SERVER_URL=https://gitlab.uxf.cz GITLAB_TOKEN= SLACK_TOKEN=xoxb- GOOGLE_WEBHOOK_URL="https://chat.googleapis.com/v1/spaces/AAAAREmdmUk/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=Id5HWMI4jMIp2JZx0kK4eJCiKmLUjUJuxpZtpqGqjfY%3D" ./bin/uxf-release.js --slack-channel=C01NQK3LY9Z --project-id=156 --message=":beer-mug: Kalkulator.cz"
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { env } = require("process");
|
|
2
|
+
const { create } = require("axios");
|
|
3
|
+
|
|
4
|
+
const axios = create({});
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @see https://developers.google.com/chat/api/reference/rest/v1/cards-v1
|
|
8
|
+
* @returns {Promise<void>}
|
|
9
|
+
*/
|
|
10
|
+
async function chatPostMessage(data, dryRun) {
|
|
11
|
+
if (env.GOOGLE_WEBHOOK_URL && !dryRun) {
|
|
12
|
+
await axios.post(env.GOOGLE_WEBHOOK_URL, { ...data });
|
|
13
|
+
} else {
|
|
14
|
+
process.stdout.write("GOOGLE CHAT: chat.postMessage - skipped");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
chatPostMessage,
|
|
20
|
+
};
|
package/src/uxf-release/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const GitLab = require("../GitLab");
|
|
2
2
|
const Slack = require("../Slack");
|
|
3
|
+
const GoogleChat = require("../GoogleChat");
|
|
3
4
|
|
|
4
5
|
function addCommitsToIssues(commits, issues) {
|
|
5
6
|
issues.forEach(issue => {
|
|
@@ -41,6 +42,21 @@ function generateSlackMessage(issues, commitsWithoutIssues, messageTitle) {
|
|
|
41
42
|
return message;
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
function generateGoogleMessage(issues, commitsWithoutIssues, messageTitle) {
|
|
46
|
+
const texts = [messageTitle];
|
|
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)));
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
text: texts.join('\n')
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
function generateSlackCommitMessage(commit) {
|
|
45
61
|
const { title, parsedTitle, short_id, web_url, author_email } = commit;
|
|
46
62
|
|
|
@@ -74,5 +90,10 @@ module.exports = async (dryRun, channel, messageTitle) => {
|
|
|
74
90
|
dryRun,
|
|
75
91
|
);
|
|
76
92
|
|
|
93
|
+
await GoogleChat.chatPostMessage(
|
|
94
|
+
generateGoogleMessage(issues, commitsWithoutIssue, messageTitle),
|
|
95
|
+
dryRun,
|
|
96
|
+
);
|
|
97
|
+
|
|
77
98
|
await GitLab.createRelease(commits.map(generateCommitMessage).join("\n"), dryRun);
|
|
78
99
|
};
|
|
@@ -4,10 +4,11 @@ const { performance } = require("perf_hooks");
|
|
|
4
4
|
const { env, stdout } = require("process");
|
|
5
5
|
const { axios } = require("../Sitemap");
|
|
6
6
|
const cheerio = require("cheerio");
|
|
7
|
+
const GoogleChat = require("../GoogleChat");
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
*
|
|
10
|
-
* @typedef {{parentUrl: (string | undefined), isImg: boolean, time: number, ttl: number, url: string, status: number}} UrlCheckResponse
|
|
11
|
+
* @typedef {{parentUrl: (string | undefined), isImg: boolean, time: number, ttl: number, url: string, status: number, message: (string | undefined)}} UrlCheckResponse
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
const MAX_TTL = 3;
|
|
@@ -39,7 +40,7 @@ function isImageUrl(url) {
|
|
|
39
40
|
* @return {string}
|
|
40
41
|
*/
|
|
41
42
|
function createErrorList(errors) {
|
|
42
|
-
return errors.map(err => `${createTabSpace(3)}${err.url}${createTabSpace()}${err.status}`).join("\n");
|
|
43
|
+
return errors.map(err => `${createTabSpace(3)}${err.url}${createTabSpace()}${err.status}${err.message ? ` – ${err.message}` : ""}`).join("\n");
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -114,8 +115,8 @@ async function fetchUrl(url, parentUrl = undefined, ttl = 1) {
|
|
|
114
115
|
const { status } = await Sitemap.axios.get(url);
|
|
115
116
|
const t1 = performance.now();
|
|
116
117
|
|
|
117
|
-
if (status !== 200) {
|
|
118
|
-
|
|
118
|
+
if (status !== 200 && ttl < MAX_TTL) {
|
|
119
|
+
return await fetchUrl(url, parentUrl, ttl + 1);
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
return {
|
|
@@ -127,17 +128,14 @@ async function fetchUrl(url, parentUrl = undefined, ttl = 1) {
|
|
|
127
128
|
time: Math.ceil(t1 - t0),
|
|
128
129
|
};
|
|
129
130
|
} catch (e) {
|
|
130
|
-
if (ttl < MAX_TTL) {
|
|
131
|
-
return fetchUrl(url, parentUrl, ttl + 1);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
131
|
return {
|
|
135
132
|
url,
|
|
136
133
|
parentUrl,
|
|
137
134
|
isImg: isImageUrl(url),
|
|
138
135
|
ttl,
|
|
139
|
-
status: Number.parseInt((e && e.response && e.response.status) ||
|
|
136
|
+
status: Number.parseInt((e && e.response && e.response.status) || -1, 10),
|
|
140
137
|
time: 0,
|
|
138
|
+
message: e.message,
|
|
141
139
|
};
|
|
142
140
|
}
|
|
143
141
|
}
|
|
@@ -173,9 +171,11 @@ async function testSitemapUrls(urls, webUrl, sitemapUrl, skip, testNested) {
|
|
|
173
171
|
const changedUrl = webUrl ? `${webUrl}${new URL(url).pathname}` : null;
|
|
174
172
|
|
|
175
173
|
printUrlInfo(changedUrl ?? url, i, urls.length);
|
|
176
|
-
printUrlResult(await testUrl(changedUrl ?? url));
|
|
177
174
|
|
|
178
|
-
|
|
175
|
+
const result = await testUrl(changedUrl ?? url);
|
|
176
|
+
printUrlResult(result);
|
|
177
|
+
|
|
178
|
+
if (testNested && result.status === 200) {
|
|
179
179
|
await testAllNestedUrls(changedUrl ?? url, i, webUrl ?? sitemapUrl.split("/").slice(0, 3).join("/"));
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -244,8 +244,8 @@ function printUrlInfo(url, urlIndex, allUrlsCount, prefix = "") {
|
|
|
244
244
|
* @param result {UrlCheckResponse}
|
|
245
245
|
*/
|
|
246
246
|
function printUrlResult(result) {
|
|
247
|
-
const { ttl, status, time } = result;
|
|
248
|
-
stdout.write(`${createTabSpace()}${status} (${time}ms) ttl=${ttl} ${status === 200 ? "✅ " : "❌ "}\n`);
|
|
247
|
+
const { ttl, status, time, message } = result;
|
|
248
|
+
stdout.write(`${createTabSpace()}${status}${message ? " – " + message : ""} (${time}ms) ttl=${ttl} ${status === 200 ? "✅ " : "❌ "}\n`);
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
/**
|
|
@@ -312,6 +312,15 @@ async function sendSlackMessage(errorText, slackChannel) {
|
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
/**
|
|
316
|
+
* @return {Promise<void>}
|
|
317
|
+
*/
|
|
318
|
+
async function sendGoogleChatMessage(resultErrors) {
|
|
319
|
+
await GoogleChat.chatPostMessage({
|
|
320
|
+
text: "*Odkazy uvedené v sitemap.xml nejsou dostupné*\n" + resultErrors.map(r => `${r.url} ${r.status}`).join('\n')
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
315
324
|
/**
|
|
316
325
|
*
|
|
317
326
|
* @param sitemapUrl {string}
|
|
@@ -338,7 +347,7 @@ module.exports = async function run(sitemapUrl, webUrl, slackChannel, skip, test
|
|
|
338
347
|
}
|
|
339
348
|
|
|
340
349
|
const startTime = performance.now();
|
|
341
|
-
await testSitemapUrls(await Sitemap.getSitemap(sitemapUrl), webUrl, sitemapUrl, skip, testNested);
|
|
350
|
+
await testSitemapUrls((await Sitemap.getSitemap(sitemapUrl)), webUrl, sitemapUrl, skip, testNested);
|
|
342
351
|
const finishTime = performance.now();
|
|
343
352
|
|
|
344
353
|
const errors = TESTED_URLS.filter(r => r.status !== 200);
|
|
@@ -348,6 +357,7 @@ module.exports = async function run(sitemapUrl, webUrl, slackChannel, skip, test
|
|
|
348
357
|
const errorText = createErrorResult(errors);
|
|
349
358
|
logErrors(errorText);
|
|
350
359
|
await sendSlackMessage(errorText, slackChannel);
|
|
360
|
+
await sendGoogleChatMessage(errors);
|
|
351
361
|
}
|
|
352
362
|
logStatistics(ok, Math.ceil(finishTime - startTime));
|
|
353
363
|
|