Skip to content

Commit

Permalink
override existing broken-links comment (github#34557)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Laura Coursen <lecoursen@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rachael Sewell <rachmari@github.com>
  • Loading branch information
4 people authored and rachaelrenk committed Feb 8, 2023
1 parent 82dfe5f commit f90f604
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions .github/actions-scripts/rendered-content-link-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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')
Expand Down Expand Up @@ -422,10 +428,48 @@ async function commentOnPR(core, octokit, flaws, opts) {
return
}

const findAgainSymbol = '<!-- rendered-content-link-checker-comment-finder -->'

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
}

Expand All @@ -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) {
Expand Down

0 comments on commit f90f604

Please sign in to comment.