From 905062f10c86a54bc0610ebdde48fd9b9bde7cac Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 12 Feb 2025 01:25:55 +0800 Subject: [PATCH] chore: fix test route in issue command --- .github/workflows/docker-test-cont.yml | 4 +++- scripts/workflow/test-route/identify.mjs | 27 ++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker-test-cont.yml b/.github/workflows/docker-test-cont.yml index 6e18322a2b..be3c207be4 100644 --- a/.github/workflows/docker-test-cont.yml +++ b/.github/workflows/docker-test-cont.yml @@ -43,9 +43,11 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const PR = JSON.parse(process.env.PULL_REQUEST) + const body = PR.body const number = PR.number + const sender = PR.user.login const { default: identify } = await import('${{ github.workspace }}/scripts/workflow/test-route/identify.mjs') - return identify({ github, context, core }, number) + return identify({ github, context, core }, body, number, sender) - name: Fetch Docker image if: (env.TEST_CONTINUE) diff --git a/scripts/workflow/test-route/identify.mjs b/scripts/workflow/test-route/identify.mjs index 321d805278..01ffa6293e 100644 --- a/scripts/workflow/test-route/identify.mjs +++ b/scripts/workflow/test-route/identify.mjs @@ -2,7 +2,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] -export default async function identify({ github, context, core }, number) { +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(//g, ''); + const m = bodyNoCmts?.match(/```routes\s+([\S\s]*?)```/); + core.debug(`match: ${m}`); + let routes = null; + const issueFacts = { owner: context.repo.owner, repo: context.repo.repo, @@ -13,22 +21,13 @@ export default async function identify({ github, context, core }, number) { repo: context.repo.repo, pull_number: number, }; - const { data: pr } = await github.rest.issues + const { data: issue } = await github.rest.issues .get({ ...issueFacts, }) .catch((error) => { core.warning(error); }); - const sender = pr.user.login; - const body = pr.body; - core.debug(`sender: ${sender}`); - core.debug(`body: ${body}`); - // Remove all HTML comments before performing the match - const bodyNoCmts = body?.replaceAll(//g, ''); - const m = bodyNoCmts?.match(/```routes\s+([\S\s]*?)```/); - core.debug(`match: ${m}`); - let routes = null; const addLabels = (labels) => github.rest.issues @@ -78,11 +77,11 @@ export default async function identify({ github, context, core }, number) { 路由测试失败,请确认评论部分符合格式规范,详情请检查 [日志](${logUrl})。`); }; - if (pr.pull_request) { - if (pr.state === 'closed') { + if (issue.pull_request) { + if (issue.state === 'closed') { await updatePrState('open'); } - if (pr.labels.some((e) => e.name === testFailed)) { + if (issue.labels.some((e) => e.name === testFailed)) { await removeLabel(testFailed); } }