chore: reopen and test pr/issue after edited

This commit is contained in:
TonyRL
2023-04-05 14:05:00 +00:00
parent a60eb5835d
commit 64cb56827e
6 changed files with 50 additions and 28 deletions

View File

@@ -40,7 +40,7 @@ async function parseBodyRoutes(body, core) {
return dedup;
}
throw 'unable to parse the issue body: route does not exist';
throw Error('unable to parse the issue body: route does not exist');
}
async function getMaintainersByRoutes(routes, core) {
@@ -64,6 +64,17 @@ module.exports = async ({ github, context, core }) => {
repo: context.repo.repo,
};
if (context.payload.issue.state === 'closed') {
await github.rest.issues
.update({
...issue_facts,
state: 'open',
})
.catch((e) => {
core.warning(e);
});
}
const routes = await parseBodyRoutes(body, core).catch((e) => {
core.warning(e);
});
@@ -155,15 +166,15 @@ module.exports = async ({ github, context, core }) => {
> 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 there is any route not 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\` 关键词,或者留下评论。我们会重新审核。
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.
`,
})
.catch((e) => {
core.warning(e);
});
if (failedCount > 0) {
if (failedCount && emptyCount === 0 && successCount === 0) {
await github.rest.issues
.update({
...issue_facts,

View File

@@ -8,26 +8,44 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
core.debug(`match: ${m}`);
let res = null;
const issue_facts = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
};
const pr_facts = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
};
const removeLabel = () =>
github.rest.issues
.removeLabel({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
...issue_facts,
name: noFound,
})
.catch((e) => {
core.warning(e);
});
if (context.payload.pull_request.state === 'closed') {
await github.rest.pulls
.update({
...pr_facts,
state: 'open',
})
.catch((e) => {
core.warning(e);
});
}
if (whiteListedUser.includes(sender)) {
core.info('PR created by a whitelisted user, passing');
await removeLabel();
await github.rest.issues
.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
...issue_facts,
labels: ['Auto: whitelisted'],
})
.catch((e) => {
@@ -47,9 +65,7 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
await removeLabel();
await github.rest.issues
.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
...issue_facts,
labels: ['Auto: No Route Needed'],
})
.catch((e) => {
@@ -68,9 +84,7 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
await github.rest.issues
.addLabels({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
...issue_facts,
labels: [noFound],
})
.catch((e) => {
@@ -78,9 +92,7 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
});
await github.rest.issues
.createComment({
issue_number: number,
owner: context.repo.owner,
repo: context.repo.repo,
...issue_facts,
body: `自动检测失败, 请确认PR正文部分符合格式规范并重新开启, 详情请检查日志
Auto Route test failed, please check your PR body format and reopen pull request. Check logs for more details`,
})
@@ -89,14 +101,12 @@ Auto Route test failed, please check your PR body format and reopen pull request
});
await github.rest.pulls
.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
...pr_facts,
state: 'closed',
})
.catch((e) => {
core.warning(e);
});
throw 'Please follow the PR rules: failed to detect route';
throw Error('Please follow the PR rules: failed to detect route');
};