[CodeFactor] Apply fixes

[ci skip] [skip ci]
This commit is contained in:
codefactor-io
2021-01-10 23:58:27 +00:00
parent 41726260bf
commit 036796e716
2 changed files with 35 additions and 35 deletions

View File

@@ -1,11 +1,11 @@
const noFound = 'Auto: Route No Found' const noFound = 'Auto: Route No Found';
module.exports = ({github, context, core}, body, number) => { module.exports = ({github, context, core}, body, number) => {
core.debug(`body: ${body}`) core.debug(`body: ${body}`);
const m = body.match(/```routes\r\n((.|\r\n)*)```/) const m = body.match(/```routes\r\n((.|\r\n)*)```/);
core.debug(`match: ${m}`) core.debug(`match: ${m}`);
let res = null let res = null;
const removeLabel = () => { const removeLabel = () => {
github.issues.removeLabel({ github.issues.removeLabel({
@@ -13,39 +13,39 @@ module.exports = ({github, context, core}, body, number) => {
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
name: noFound name: noFound
}).catch(() => {}) }).catch(() => {});
} };
if (m && m[1]) { if (m && m[1]) {
res = m[1].trim().split("\r\n") res = m[1].trim().split("\r\n");
core.info(`routes detected: ${res}`) core.info(`routes detected: ${res}`);
if (res.length > 0 && res[0] === "NOROUTE") { if (res.length > 0 && res[0] === "NOROUTE") {
core.info("PR stated no route, passing") core.info("PR stated no route, passing");
removeLabel() removeLabel();
github.issues.addLabels({ github.issues.addLabels({
issue_number: number, issue_number: number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
labels: ['Auto: No Route Needed'] labels: ['Auto: No Route Needed']
}) });
return return;
} else if (res.length > 0) { } else if (res.length > 0) {
core.exportVariable('TEST_CONTINUE', true) core.exportVariable('TEST_CONTINUE', true);
removeLabel() removeLabel();
return res return res;
} }
} }
core.info("seems no route found, failing") core.info("seems no route found, failing");
github.issues.addLabels({ github.issues.addLabels({
issue_number: number, issue_number: number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
labels: [noFound] labels: [noFound]
}) });
throw "Please follow the PR rules: failed to detect route" throw "Please follow the PR rules: failed to detect route";
} };

View File

@@ -1,19 +1,19 @@
module.exports = async ({github, context}, baseUrl, routes, number) => { module.exports = async ({github, context}, baseUrl, routes, number) => {
if (routes[0] === 'NOROUTE') { if (routes[0] === 'NOROUTE') {
return return;
} }
const links = routes.map(e => { const links = routes.map((e) => {
const l = e.startsWith('/') ? e : `/${e}` const l = e.startsWith('/') ? e : `/${e}`;
return `${baseUrl}${l}` return `${baseUrl}${l}`;
}) });
let com = 'Successfully generated as following:\n\n' let com = 'Successfully generated as following:\n\n';
for (const lks of links) { for (const lks of links) {
console.log("testing route: ", lks) console.log("testing route: ", lks);
const res = await github.request(`GET ${lks}`).catch(err => { const res = await github.request(`GET ${lks}`).catch((err) => {
com+= ` com += `
<details> <details>
<summary><a href="${lks}">${lks}</a> - **Failed**</summary> <summary><a href="${lks}">${lks}</a> - **Failed**</summary>
@@ -23,10 +23,10 @@ module.exports = async ({github, context}, baseUrl, routes, number) => {
\`\`\` \`\`\`
</details> </details>
` `;
}) });
if (res && res.data) { if (res && res.data) {
const { data } = res const { data } = res;
com += ` com += `
<details> <details>
<summary><a href="${lks}">${lks}</a> - Success</summary> <summary><a href="${lks}">${lks}</a> - Success</summary>
@@ -36,7 +36,7 @@ module.exports = async ({github, context}, baseUrl, routes, number) => {
\`\`\` \`\`\`
</details> </details>
` `;
} }
} }
github.issues.addLabels({ github.issues.addLabels({
@@ -44,11 +44,11 @@ module.exports = async ({github, context}, baseUrl, routes, number) => {
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
labels: ['Auto: Route Test Complete'] labels: ['Auto: Route Test Complete']
}) });
github.issues.createComment({ github.issues.createComment({
issue_number: number, issue_number: number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body: com body: com
}); });
} };