From b68265831534d9f219e75fab9c96ff2e51d57af2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 8 Feb 2023 14:22:24 -0500 Subject: [PATCH] override existing broken-links comment (#34557) Signed-off-by: dependabot[bot] Co-authored-by: Laura Coursen Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rachael Sewell --- .../rendered-content-link-checker.js | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/.github/actions-scripts/rendered-content-link-checker.js b/.github/actions-scripts/rendered-content-link-checker.js index ec27cdd0c3..54aa21ba6e 100755 --- a/.github/actions-scripts/rendered-content-link-checker.js +++ b/.github/actions-scripts/rendered-content-link-checker.js @@ -288,6 +288,12 @@ async function main(core, octokit, uploadArtifact, opts = {}) { ) } } + } else { + // It might be that the PR got a comment about >0 flaws before, + // and now it can update that comment to say all is well again. + if (shouldComment) { + await commentOnPR(core, octokit, flaws, opts) + } } } @@ -327,7 +333,7 @@ async function linkReports(core, octokit, newReport, opts) { const [owner, repo] = reportRepository.split('/') - core.debug('Attempting to link reports...') + core.info('Attempting to link reports...') // Find previous broken link report issue let previousReports try { @@ -346,7 +352,7 @@ async function linkReports(core, octokit, newReport, opts) { core.setFailed('Error listing issues for repo') throw error } - core.debug(`Found ${previousReports.length} previous reports`) + core.info(`Found ${previousReports.length} previous reports`) if (previousReports.length <= 1) { core.info('No previous reports to link to') @@ -422,10 +428,48 @@ async function commentOnPR(core, octokit, flaws, opts) { return } + const findAgainSymbol = '' + const body = flawIssueDisplay(flaws, opts, false) + + const { data } = await octokit.rest.issues.listComments({ + owner, + repo, + issue_number: pullNumber, + }) + let previousCommentId + for (const { body, id } of data) { + if (body.includes(findAgainSymbol)) { + previousCommentId = id + } + } + // Since failed external urls aren't included in PR comment, body may be empty if (!body) { core.info('No flaws qualify for comment') + + if (previousCommentId) { + const nothingComment = 'Previous broken links comment now moot. 👌😙' + await octokit.rest.issues.updateComment({ + owner, + repo, + comment_id: previousCommentId, + body: `${nothingComment}\n\n${findAgainSymbol}`, + }) + core.info(`Updated comment on PR: ${pullNumber} (${previousCommentId})`) + } + return + } + + if (previousCommentId) { + const noteComment = '(*The original automated comment was updated*)' + await octokit.rest.issues.updateComment({ + owner, + repo, + comment_id: previousCommentId, + body: `${body}\n\n${noteComment}\n\n${findAgainSymbol}`, + }) + core.info(`Updated comment on PR: ${pullNumber} (${previousCommentId})`) return } @@ -434,7 +478,7 @@ async function commentOnPR(core, octokit, flaws, opts) { owner, repo, issue_number: pullNumber, - body, + body: `${body}\n\n${findAgainSymbol}`, }) core.info(`Created comment on PR: ${pullNumber}`) } catch (error) {