@uxf/scripts 1.5.4 → 1.6.0
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/.gitlab-ci.yml +1 -1
- 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 +66 -11
package/.gitlab-ci.yml
CHANGED
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, message: (string | undefined)}} UrlCheckResponse
|
|
11
|
+
* @typedef {{parentUrl: (string | undefined), isImg: boolean, time: number, ttl: number, url: string, status: number, message: (string | undefined), shouldIgnoreError: (boolean | undefined)}} UrlCheckResponse
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
const MAX_TTL = 3;
|
|
@@ -33,6 +34,24 @@ function isImageUrl(url) {
|
|
|
33
34
|
return new RegExp("[a-z].*(\\.jpg|\\.png|\\.webp|\\.avif|\\.gif)$", "gim").test(url);
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param url {string}
|
|
40
|
+
* @param status {number}
|
|
41
|
+
* @param e {Error}
|
|
42
|
+
* @returns {boolean}
|
|
43
|
+
*/
|
|
44
|
+
function shouldIgnoreError(url, status, e) {
|
|
45
|
+
if (status === 999 && url.startsWith("https://www.linkedin.com")) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if ((status === -1 || status === 302) && url.startsWith("https://www.facebook.com/sharer/")) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
36
55
|
/**
|
|
37
56
|
*
|
|
38
57
|
* @param errors {UrlCheckResponse[]}
|
|
@@ -127,14 +146,28 @@ async function fetchUrl(url, parentUrl = undefined, ttl = 1) {
|
|
|
127
146
|
time: Math.ceil(t1 - t0),
|
|
128
147
|
};
|
|
129
148
|
} catch (e) {
|
|
149
|
+
const status = Number.parseInt((e && e.response && e.response.status) || -1, 10);
|
|
150
|
+
|
|
151
|
+
if (shouldIgnoreError(url, status, e)) {
|
|
152
|
+
return {
|
|
153
|
+
url,
|
|
154
|
+
parentUrl,
|
|
155
|
+
isImg: isImageUrl(url),
|
|
156
|
+
ttl,
|
|
157
|
+
status,
|
|
158
|
+
shouldIgnoreError: true,
|
|
159
|
+
time: 0,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
130
162
|
return {
|
|
131
163
|
url,
|
|
132
164
|
parentUrl,
|
|
133
165
|
isImg: isImageUrl(url),
|
|
134
166
|
ttl,
|
|
135
|
-
status
|
|
167
|
+
status,
|
|
136
168
|
time: 0,
|
|
137
169
|
message: e.message,
|
|
170
|
+
shouldIgnoreError: false,
|
|
138
171
|
};
|
|
139
172
|
}
|
|
140
173
|
}
|
|
@@ -170,9 +203,11 @@ async function testSitemapUrls(urls, webUrl, sitemapUrl, skip, testNested) {
|
|
|
170
203
|
const changedUrl = webUrl ? `${webUrl}${new URL(url).pathname}` : null;
|
|
171
204
|
|
|
172
205
|
printUrlInfo(changedUrl ?? url, i, urls.length);
|
|
173
|
-
printUrlResult(await testUrl(changedUrl ?? url));
|
|
174
206
|
|
|
175
|
-
|
|
207
|
+
const result = await testUrl(changedUrl ?? url);
|
|
208
|
+
printUrlResult(result);
|
|
209
|
+
|
|
210
|
+
if (testNested && result.status === 200) {
|
|
176
211
|
await testAllNestedUrls(changedUrl ?? url, i, webUrl ?? sitemapUrl.split("/").slice(0, 3).join("/"));
|
|
177
212
|
}
|
|
178
213
|
}
|
|
@@ -248,9 +283,10 @@ function printUrlResult(result) {
|
|
|
248
283
|
/**
|
|
249
284
|
*
|
|
250
285
|
* @param errorText {string}
|
|
286
|
+
* @param title {string}
|
|
251
287
|
*/
|
|
252
|
-
function logErrors(errorText) {
|
|
253
|
-
stdout.write(
|
|
288
|
+
function logErrors(errorText, title) {
|
|
289
|
+
stdout.write(title);
|
|
254
290
|
stdout.write(`${errorText}\n\n`);
|
|
255
291
|
}
|
|
256
292
|
|
|
@@ -272,8 +308,8 @@ function convertTime(millis) {
|
|
|
272
308
|
*/
|
|
273
309
|
function logStatistics(okResults, time) {
|
|
274
310
|
const avgTime = Math.round(okResults.reduce((prev, curr) => prev + curr.time, 0) / TESTED_URLS.length);
|
|
275
|
-
const maxTime = okResults.reduce((prev, curr) => (curr.time > prev.time ? curr : prev));
|
|
276
|
-
const minTime = okResults.reduce((prev, curr) => (curr.time < prev.time ? curr : prev));
|
|
311
|
+
const maxTime = okResults.reduce((prev, curr) => (curr.time > prev.time ? curr : prev), []);
|
|
312
|
+
const minTime = okResults.reduce((prev, curr) => (curr.time < prev.time ? curr : prev), []);
|
|
277
313
|
|
|
278
314
|
stdout.write("\nSummary:\n");
|
|
279
315
|
stdout.write(createTabSpace() + `Time ${convertTime(time)}\n`);
|
|
@@ -309,6 +345,15 @@ async function sendSlackMessage(errorText, slackChannel) {
|
|
|
309
345
|
});
|
|
310
346
|
}
|
|
311
347
|
|
|
348
|
+
/**
|
|
349
|
+
* @return {Promise<void>}
|
|
350
|
+
*/
|
|
351
|
+
async function sendGoogleChatMessage(resultErrors) {
|
|
352
|
+
await GoogleChat.chatPostMessage({
|
|
353
|
+
text: "*Odkazy uvedené v sitemap.xml nejsou dostupné*\n" + resultErrors.map(r => `${r.url} ${r.status}`).join('\n')
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
312
357
|
/**
|
|
313
358
|
*
|
|
314
359
|
* @param sitemapUrl {string}
|
|
@@ -335,17 +380,27 @@ module.exports = async function run(sitemapUrl, webUrl, slackChannel, skip, test
|
|
|
335
380
|
}
|
|
336
381
|
|
|
337
382
|
const startTime = performance.now();
|
|
338
|
-
await testSitemapUrls(await Sitemap.getSitemap(sitemapUrl), webUrl, sitemapUrl, skip, testNested);
|
|
383
|
+
await testSitemapUrls((await Sitemap.getSitemap(sitemapUrl)), webUrl, sitemapUrl, skip, testNested);
|
|
339
384
|
const finishTime = performance.now();
|
|
340
385
|
|
|
341
|
-
const errors = TESTED_URLS.filter(r => r.status !== 200);
|
|
386
|
+
const errors = TESTED_URLS.filter(r => r.status !== 200 && r.shouldIgnoreError === false);
|
|
387
|
+
const ignoredErrors = TESTED_URLS.filter(r => r.status !== 200 && r.shouldIgnoreError === true);
|
|
342
388
|
const ok = TESTED_URLS.filter(r => r.status === 200);
|
|
343
389
|
|
|
344
390
|
if (errors.length > 0) {
|
|
345
391
|
const errorText = createErrorResult(errors);
|
|
346
|
-
logErrors(errorText);
|
|
392
|
+
logErrors(errorText, "\nErrors:\n");
|
|
393
|
+
const ignoredErrorText = createErrorResult(ignoredErrors);
|
|
394
|
+
logErrors(ignoredErrorText, "\nIngored errors:\n");
|
|
347
395
|
await sendSlackMessage(errorText, slackChannel);
|
|
396
|
+
await sendGoogleChatMessage(errors);
|
|
348
397
|
}
|
|
398
|
+
|
|
399
|
+
if (ignoredErrors.length > 0) {
|
|
400
|
+
const ignoredErrorText = createErrorResult(ignoredErrors);
|
|
401
|
+
logErrors(ignoredErrorText, "\nIngored errors:\n");
|
|
402
|
+
}
|
|
403
|
+
|
|
349
404
|
logStatistics(ok, Math.ceil(finishTime - startTime));
|
|
350
405
|
|
|
351
406
|
process.exit(errors.length > 0 ? 1 : 0);
|