From a24109b6f7a359b024ad9e05a477146fda450488 Mon Sep 17 00:00:00 2001 From: Wenxin Du <117315983+duwenxin99@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:56:03 -0500 Subject: [PATCH] fix: Cloud Build reporter issue comment (#278) * fix: Cloud Build reporter issue comment * bracket --- .../cloud_build_failure_reporter.yml | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cloud_build_failure_reporter.yml b/.github/workflows/cloud_build_failure_reporter.yml index f9e1ab1c..da387522 100644 --- a/.github/workflows/cloud_build_failure_reporter.yml +++ b/.github/workflows/cloud_build_failure_reporter.yml @@ -57,6 +57,7 @@ jobs: creator: 'github-actions[bot]', labels: [periodicLabel] }); + // createOrCommentIssue creates a new issue or comments on an existing issue. const createOrCommentIssue = async function (title, txt) { if (prevIssues.length < 1) { @@ -69,34 +70,39 @@ jobs: }); return; } - if (prevIssues.length > 1) { - console.warn( - `found ${prevIssues.length} issues but only adding comment to ${prevIssues[0].html_url}` - ); + // only comment on issue related to the current test + for (const prevIssue of prevIssues) { + if (prevIssue.title.includes(title)){ + console.log( + `found previous issue ${prevIssue.html_url}, adding comment` + ); + + await github.rest.issues.createComment({ + ...context.repo, + issue_number: prevIssue.number, + body: txt + }); + return; + } } - console.log( - `found previous issue ${prevIssues[0].html_url}, adding comment` - ); - await github.rest.issues.createComment({ - ...context.repo, - issue_number: prevIssues[0].number, - body: txt - }); }; // updateIssues comments on any existing issues. No-op if no issue exists. - const updateIssues = async function (txt) { + const updateIssues = async function (checkName, txt) { if (prevIssues.length < 1) { console.log('no previous issues found.'); return; } + // only comment on issue related to the current test for (const prevIssue of prevIssues) { - console.log(`found previous issue ${prevIssue.html_url}, adding comment`); - await github.rest.issues.createComment({ - ...context.repo, - issue_number: prevIssue.number, - body: txt - }); + if (prevIssue.title.includes(checkName)){ + console.log(`found previous issue ${prevIssue.html_url}, adding comment`); + await github.rest.issues.createComment({ + ...context.repo, + issue_number: prevIssue.number, + body: txt + }); + } } }; @@ -146,6 +152,7 @@ jobs: check.conclusion === 'success' ) { updateIssues( + check.name, `[Tests are passing](${check.html_url}) for commit [${commit.sha}](${commit.html_url}).` ); } else if (check.status === 'in_progress') {