flow: pr auto test template

This commit is contained in:
NeverBehave
2021-01-10 18:55:03 -05:00
parent 51c3f05699
commit 16d3799970
4 changed files with 166 additions and 2 deletions
+51
View File
@@ -0,0 +1,51 @@
const noFound = 'Auto: Route No Found'
module.exports = ({github, context, core}, body, number) => {
core.debug(`body: ${body}`)
const m = body.match(/```routes\r\n((.|\r\n)*)```/)
core.debug(`match: ${m}`)
let res = null
const removeLabel = () => {
github.issues.removeLabel({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
name: noFound
}).catch(() => {})
}
if (m && m[1]) {
res = m[1].trim().split("\r\n")
core.info(`routes detected: ${res}`)
if (res.length > 0 && res[0] === "NOROUTE") {
core.info("PR stated no route, passing")
removeLabel()
github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Auto: No Route Needed']
})
return
} else if (res.length > 0) {
core.exportVariable('TEST_CONTINUE', true)
removeLabel()
return res
}
}
core.info("seems no route found, failing")
github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [noFound]
})
throw "Please follow the PR rules: failed to detect route"
}
+54
View File
@@ -0,0 +1,54 @@
module.exports = async ({github, context}, baseUrl, routes, number) => {
if (routes[0] === 'NOROUTE') {
return
}
const links = routes.map(e => {
const l = e.startsWith('/') ? e : `/${e}`
return `${baseUrl}${l}`
})
let com = 'Successfully generated as following:\n\n'
for (const lks of links) {
console.log("testing route: ", lks)
const res = await github.request(`GET ${lks}`).catch(err => {
com+= `
<details>
<summary><a href="${lks}">${lks}</a> - **Failed**</summary>
\`\`\`
${err}
\`\`\`
</details>
`
})
if (res && res.data) {
const { data } = res
com += `
<details>
<summary><a href="${lks}">${lks}</a> - Success</summary>
\`\`\`
${data.split("\n").slice(0, 30).join("\n")}
\`\`\`
</details>
`
}
}
github.issues.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Auto: Route Test Complete']
})
github.issues.createComment({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
body: com
});
}