mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 10:38:03 +08:00
chore: fix route test github actions (#14923)
* chore: fix route test actions * chore: bump unified
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
const unified = require('unified');
|
||||
const parse = require('remark-parse');
|
||||
const got = require('got');
|
||||
import { unified } from 'unified';
|
||||
import remarkParse from 'remark-parse';
|
||||
|
||||
// @TODO maybe we could use label or some other better ways to distinguish bug/feature issues
|
||||
const matchTitle = ['路由地址', 'Routes'];
|
||||
const maintainerURL = 'https://raw.githubusercontent.com/DIYgod/RSSHub/gh-pages/build/maintainer.json';
|
||||
const maintainerURL = 'https://raw.githubusercontent.com/DIYgod/RSSHub/gh-pages/build/maintainers.json';
|
||||
const successTag = 'Bug Ping: Pinged';
|
||||
const parseFailTag = 'Bug Ping: Parsing Failed';
|
||||
const failTag = 'Bug Ping: Not Found';
|
||||
@@ -15,7 +14,7 @@ const route = 'Route';
|
||||
const dndUsernames = new Set([]);
|
||||
|
||||
async function parseBodyRoutes(body, core) {
|
||||
const ast = await unified().use(parse).parse(body);
|
||||
const ast = await unified().use(remarkParse).parse(body);
|
||||
|
||||
// Is this a bug report?
|
||||
const title = ast.children[0].children[0].value.trim();
|
||||
@@ -44,10 +43,8 @@ async function parseBodyRoutes(body, core) {
|
||||
}
|
||||
|
||||
async function getMaintainersByRoutes(routes, core) {
|
||||
// TODO: change me when https://github.com/actions/github-script is run on node20
|
||||
// const response = await fetch(maintainerURL);
|
||||
// const maintainers = await response.json();
|
||||
const maintainers = await got(maintainerURL).json();
|
||||
const response = await fetch(maintainerURL);
|
||||
const maintainers = await response.json();
|
||||
|
||||
return routes.map((e) => {
|
||||
const m = maintainers[e];
|
||||
@@ -59,9 +56,9 @@ async function getMaintainersByRoutes(routes, core) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = async ({ github, context, core }) => {
|
||||
export default async function callMaintainer({ github, context, core }) {
|
||||
const body = context.payload.issue.body;
|
||||
const issue_facts = {
|
||||
const issueFacts = {
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
@@ -70,7 +67,7 @@ module.exports = async ({ github, context, core }) => {
|
||||
const addLabels = (labels) =>
|
||||
github.rest.issues
|
||||
.addLabels({
|
||||
...issue_facts,
|
||||
...issueFacts,
|
||||
labels,
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -79,7 +76,7 @@ module.exports = async ({ github, context, core }) => {
|
||||
const updateIssueState = (state) =>
|
||||
github.rest.issues
|
||||
.update({
|
||||
...issue_facts,
|
||||
...issueFacts,
|
||||
state,
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -138,7 +135,7 @@ module.exports = async ({ github, context, core }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const labels = [`Count: ${successCount}/${routes.length}`];
|
||||
const labels = [''];
|
||||
|
||||
if (failedCount > 0) {
|
||||
labels.push(failTag);
|
||||
@@ -160,14 +157,14 @@ module.exports = async ({ github, context, core }) => {
|
||||
// Reply to the issue and notify the maintainers (if any)
|
||||
await github.rest.issues
|
||||
.createComment({
|
||||
...issue_facts,
|
||||
...issueFacts,
|
||||
body: `${comments}
|
||||
|
||||
|
||||
> To maintainers: if you are not willing to be disturbed, list your username in \`scripts/workflow/test-issue/call-maintainer.js\`. In this way, your username will be wrapped in an inline code block when tagged so you will not be notified.
|
||||
|
||||
如果所有路由都无法匹配,issue 将会被自动关闭。如果 issue 和路由无关,请使用 \`NOROUTE\` 关键词,或者留下评论。我们会重新审核。
|
||||
If all routes can not be found, the issue will be closed automatically. Please use \`NOROUTE\` for a route-irrelevant issue or leave a comment if it is a mistake.
|
||||
如果所有路由都无法匹配,issue 将会被自动关闭。如果 issue 和路由无关,请使用 \`NOROUTE\` 关键词,或者留下评论。我们会重新审核。
|
||||
`,
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -177,4 +174,4 @@ If all routes can not be found, the issue will be closed automatically. Please u
|
||||
if (failedCount && emptyCount === 0 && successCount === 0) {
|
||||
await updateIssueState('closed');
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
const noFound = 'Auto: Route No Found';
|
||||
const testFailed = 'Auto: Route Test Failed';
|
||||
const allowedUser = new Set(['dependabot[bot]', 'pull[bot]']); // dependabot and downstream PR requested by pull[bot]
|
||||
|
||||
module.exports = async ({ github, context, core }, body, number, sender) => {
|
||||
export default async function identify({ github, context, core }, body, number, sender) {
|
||||
core.debug(`sender: ${sender}`);
|
||||
core.debug(`body: ${body}`);
|
||||
// Remove all HTML comments before performing the match
|
||||
const bodyNoCmts = body.replaceAll(/<!--[\S\s]*?-->/g, '');
|
||||
const m = bodyNoCmts.match(/```routes\s+([\S\s]*?)```/);
|
||||
core.debug(`match: ${m}`);
|
||||
let res = null;
|
||||
let routes = null;
|
||||
|
||||
const issueFacts = {
|
||||
owner: context.repo.owner,
|
||||
@@ -31,11 +32,11 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
|
||||
core.warning(error);
|
||||
});
|
||||
|
||||
const removeLabel = () =>
|
||||
const removeLabel = (labelName = noFound) =>
|
||||
github.rest.issues
|
||||
.removeLabel({
|
||||
...issueFacts,
|
||||
name: noFound,
|
||||
name: labelName,
|
||||
})
|
||||
.catch((error) => {
|
||||
core.warning(error);
|
||||
@@ -80,8 +81,13 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
|
||||
.catch((error) => {
|
||||
core.warning(error);
|
||||
});
|
||||
if (pr.pull_request && pr.state === 'closed') {
|
||||
await updatePrState('open');
|
||||
if (pr.pull_request) {
|
||||
if (pr.state === 'closed') {
|
||||
await updatePrState('open');
|
||||
}
|
||||
if (pr.labels.some((e) => e.name === testFailed)) {
|
||||
await removeLabel(testFailed);
|
||||
}
|
||||
}
|
||||
|
||||
if (allowedUser.has(sender)) {
|
||||
@@ -94,19 +100,25 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
|
||||
}
|
||||
|
||||
if (m && m[1]) {
|
||||
res = m[1].trim().split(/\r?\n/);
|
||||
core.info(`routes detected: ${res}`);
|
||||
routes = m[1].trim().split(/\r?\n/);
|
||||
core.info(`routes detected: ${routes}`);
|
||||
|
||||
if (res.length && res[0] === 'NOROUTE') {
|
||||
if (routes.length && routes[0] === 'NOROUTE') {
|
||||
core.info('PR stated no route, passing');
|
||||
await removeLabel();
|
||||
await addLabels(['Auto: Route Test Skipped']);
|
||||
|
||||
return;
|
||||
} else if (res.length && !res.some((e) => e.includes('/:'))) {
|
||||
} else if (routes.length) {
|
||||
if (routes.some((e) => e.includes('/:'))) {
|
||||
await addLabels([noFound]);
|
||||
return createComment(`Please use actual values in \`routes\` section instead of path parameters.
|
||||
请在 \`routes\` 部分使用实际值而不是路径参数。`);
|
||||
}
|
||||
|
||||
core.exportVariable('TEST_CONTINUE', true);
|
||||
await removeLabel();
|
||||
return res;
|
||||
return routes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +131,4 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
|
||||
}
|
||||
|
||||
throw new Error('Please follow the PR rules: failed to detect route');
|
||||
};
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
module.exports = async ({ github, context, core, got }, baseUrl, routes, number) => {
|
||||
if (routes[0] === 'NOROUTE') {
|
||||
return;
|
||||
}
|
||||
|
||||
const links = routes.map((e) => {
|
||||
const l = e.startsWith('/') ? e : `/${e}`;
|
||||
return `${baseUrl}${l}`;
|
||||
});
|
||||
|
||||
let com_l = [];
|
||||
let com = `Successfully [generated](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) as following:\n`;
|
||||
|
||||
for (const lks of links) {
|
||||
core.info(`testing route: ${lks}`);
|
||||
// Intended, one at a time
|
||||
let success = false;
|
||||
let detail;
|
||||
try {
|
||||
// TODO: change me when https://github.com/actions/github-script is run on node20
|
||||
// const res = await fetch(lks);
|
||||
// if (!res.ok) {
|
||||
// throw res;
|
||||
// }
|
||||
// success = true;
|
||||
// detail = (await res.text()).replace(/\s+(\n|$)/g, '\n');
|
||||
const res = await got(lks);
|
||||
if (res && res.body) {
|
||||
success = true;
|
||||
detail = res.body.replaceAll(/\s+(\n|$)/g, '\n');
|
||||
}
|
||||
} catch (error) {
|
||||
// TODO: change me when https://github.com/actions/github-script is run on node20
|
||||
// detail = `HTTPError: Response code ${err.status} (${err.statusText})`;
|
||||
// const res = await err.text();
|
||||
// const errInfoList = err.body && res.match(/(?<=<pre class="message">)(.+?)(?=<\/pre>)/gs);
|
||||
detail = error.toString();
|
||||
const errInfoList = error.response && error.response.body && error.response.body.match(/(?<=<pre class="message">)(.+?)(?=<\/pre>)/gs);
|
||||
if (errInfoList) {
|
||||
detail += '\n\n';
|
||||
detail += errInfoList
|
||||
.slice(0, 3)
|
||||
.map((e) => e.trim())
|
||||
.join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
let temp_com = `
|
||||
<details>
|
||||
<summary><a href="${lks}">${lks}</a> - ${success ? 'Success ✔️' : '<b>Failed ❌</b>'}</summary>
|
||||
|
||||
\`\`\`${success ? 'rss' : ''}`;
|
||||
temp_com += `
|
||||
${detail.slice(0, 65300 - temp_com.length)}
|
||||
\`\`\`
|
||||
</details>
|
||||
`;
|
||||
if (com.length + temp_com.length >= 65500) {
|
||||
com += '\n\n...';
|
||||
com_l.push(com);
|
||||
com = temp_com;
|
||||
} else {
|
||||
com += temp_com;
|
||||
}
|
||||
}
|
||||
|
||||
if (com.length > 0) {
|
||||
com_l.push(com);
|
||||
}
|
||||
|
||||
if (com_l.length >= 5) {
|
||||
com_l = com_l.slice(0, 5);
|
||||
}
|
||||
|
||||
if (process.env.PULL_REQUEST) {
|
||||
await github.rest.issues
|
||||
.addLabels({
|
||||
issue_number: number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
labels: ['Auto: Route Test Complete'],
|
||||
})
|
||||
.catch((error) => {
|
||||
core.warning(error);
|
||||
});
|
||||
}
|
||||
|
||||
for (const com_s of com_l) {
|
||||
// Intended, one at a time
|
||||
await github.rest.issues
|
||||
.createComment({
|
||||
issue_number: number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: com_s,
|
||||
})
|
||||
.catch((error) => {
|
||||
core.warning(error);
|
||||
});
|
||||
}
|
||||
};
|
||||
92
scripts/workflow/test-route/test.mjs
Normal file
92
scripts/workflow/test-route/test.mjs
Normal file
@@ -0,0 +1,92 @@
|
||||
import jsBeautify from 'js-beautify';
|
||||
|
||||
export default async function test({ github, context, core }, baseUrl, routes, number) {
|
||||
if (routes[0] === 'NOROUTE') {
|
||||
return;
|
||||
}
|
||||
|
||||
const links = routes.map((e) => {
|
||||
const l = e.startsWith('/') ? e : `/${e}`;
|
||||
return `${baseUrl}${l}`;
|
||||
});
|
||||
|
||||
let commentList = [];
|
||||
let comment = `Successfully [generated](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) as following:\n`;
|
||||
|
||||
for await (const lks of links) {
|
||||
core.info(`testing route: ${lks}`);
|
||||
// Intended, one at a time
|
||||
let success = false;
|
||||
let detail;
|
||||
|
||||
const res = await fetch(lks);
|
||||
const body = await res.text();
|
||||
if (res.ok) {
|
||||
success = true;
|
||||
detail = jsBeautify.html(body.replaceAll(/\s+(\n|$)/g, '\n'), { indent_size: 2 });
|
||||
} else {
|
||||
detail = `HTTPError: Response code ${res.status} (${res.statusText})`;
|
||||
const errInfoList = body && body.match(/(?<=<p class="message">)(.+?)(?=<\/p>)/gs);
|
||||
if (errInfoList) {
|
||||
detail += '\n\n';
|
||||
detail += errInfoList
|
||||
.slice(0, 5)
|
||||
.map((e) => (e.length > 1000 ? e.slice(0, 1000) + '...' : e).trim())
|
||||
.join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
let routeFeedback = `
|
||||
<details>
|
||||
<summary><a href="${lks}">${lks}</a> - ${success ? 'Success ✔️' : '<b>Failed ❌</b>'}</summary>
|
||||
|
||||
\`\`\`${success ? 'rss' : ''}`;
|
||||
routeFeedback += `
|
||||
${detail.slice(0, 65300 - routeFeedback.length)}
|
||||
\`\`\`
|
||||
</details>
|
||||
`;
|
||||
if (comment.length + routeFeedback.length >= 65500) {
|
||||
comment += '\n\n...';
|
||||
commentList.push(comment);
|
||||
comment = routeFeedback;
|
||||
} else {
|
||||
comment += routeFeedback;
|
||||
}
|
||||
}
|
||||
|
||||
if (comment.length > 0) {
|
||||
commentList.push(comment);
|
||||
}
|
||||
|
||||
if (commentList.length >= 5) {
|
||||
commentList = commentList.slice(0, 5);
|
||||
}
|
||||
|
||||
if (process.env.PULL_REQUEST) {
|
||||
await github.rest.issues
|
||||
.addLabels({
|
||||
issue_number: number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
labels: ['Auto: Route Test Complete'],
|
||||
})
|
||||
.catch((error) => {
|
||||
core.warning(error);
|
||||
});
|
||||
}
|
||||
|
||||
for await (const comment of commentList) {
|
||||
// Intended, one at a time
|
||||
await github.rest.issues
|
||||
.createComment({
|
||||
issue_number: number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: comment,
|
||||
})
|
||||
.catch((error) => {
|
||||
core.warning(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user