Skip to content

Commit 012338d

Browse files
authored
External Link Checker: Open in new tab (#3517)
1 parent 3921168 commit 012338d

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

tests/external-links.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ async function updateGithubIssue(urlResults) {
269269

270270
try {
271271
const lines = body.split(/\r?\n/); // support both \n and \r\n newline types
272-
const firstContentLine = lines.findIndex(line => line.startsWith(`|`)) + 2;
272+
const firstContentLine = lines.indexOf(`<table>`) + 2;
273273
lines.splice(0, firstContentLine); // delete first lines which only hold general data
274274
for (const line of lines) {
275-
const [, url, lastResults] = line.match(/^\| (.*) <td nowrap>(.*)<\/td>$/);
275+
const [, lastResults, url] = line.match(/<tr><td nowrap>(.*?)<\/td><td><a href="(.*?)"/);
276276

277277
linkData[url] = lastResults.split(`&nbsp;`).map(item => {
278278
if (item === `:heavy_check_mark:`) {
@@ -358,34 +358,41 @@ async function updateGithubIssue(urlResults) {
358358
return linkData;
359359
}
360360

361+
/**
362+
* @param {LinkStatus} status The status to get the linked emoji for.
363+
* @returns {string} An emoji, wrapped in a link to the failed job if applicable.
364+
*/
365+
function getStatusEmojiLink(status) {
366+
if (!status.failed) {
367+
return `:heavy_check_mark:`;
368+
}
369+
370+
const message = status.message.replaceAll(`\n`, ` `).replaceAll(`"`, `&quot;`);
371+
const emoji = getFailedEmoji(status.message);
372+
return `<a href="${status.jobUrl}" title="${message}">${emoji}</a>`;
373+
}
374+
361375
/**
362376
* @param {LinkData} linkData The new link data from which to create the issue body.
363377
* @returns {string} The new issue body (in Markdown and HTML) from the given link data.
364378
*/
365379
function getBodyFromLinkData(linkData) {
366380
const scriptName = import.meta.url.split(`/`).slice(-2).join(`/`);
381+
const rows = Object.entries(linkData).map(([url, statuses]) => {
382+
const statusIcons = statuses.map(status => getStatusEmojiLink(status)).join(`&nbsp;`);
383+
const link = `<a href="${url}" target="_blank">${url}</a>`;
384+
return `<tr><td nowrap>${statusIcons}</td><td>${link}</td></tr>`;
385+
});
367386
const lines = [
368387
`*Auto-generated content by \`${scriptName}\`.*`,
369388
``,
370389
`**Last updated:** ${new Date().toISOString()}`,
371390
``,
372-
`| URL <th nowrap>today … 6 days ago</th>`,
373-
`|--------------------------------------|`,
374-
...Object.entries(linkData).map(([url, statuses]) => {
375-
const statusIcons = statuses.map(status => {
376-
if (!status.failed) {
377-
return `:heavy_check_mark:`;
378-
}
379-
380-
const message = status.message.replaceAll(`\n`, ` `).replaceAll(`"`, `&quot;`);
381-
const emoji = getFailedEmoji(status.message);
382-
return `<a href="${status.jobUrl}" title="${message}">${emoji}</a>`;
383-
}).join(`&nbsp;`);
384-
385-
return `| ${url} <td nowrap>${statusIcons}</td>`;
386-
}),
391+
`<table>`,
392+
`<tr><th nowrap>today … 6 days ago</th><th>URL</th></tr>`,
393+
...rows,
394+
`</table>`,
387395
];
388-
389396
return lines.join(`\n`);
390397
}
391398

0 commit comments

Comments
 (0)