Skip to content

Commit

Permalink
Delete outdated GitHub issue comment for empty diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Dec 1, 2023
1 parent c474310 commit aabe22d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion .github/workflows/scripts/comments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export async function commentDiff(
// Read diff from previous step
const diffText = await readFile(path, 'utf8')

// Skip comment for empty diff
// Skip or delete comment for empty diff
if (!diffText && skipEmpty) {
console.log(`Skipping GitHub comment for ${basename(path)}`)
await deleteComment(githubActionContext, issueNumber, markerText)
return
}

Expand Down Expand Up @@ -248,6 +249,34 @@ function githubActionRunUrl(context) {
return `https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}/attempts/${process.env.GITHUB_RUN_ATTEMPT}`
}

/**
* Delete GitHub issue comment with marker `<!-- Example -->`
*
* @param {Pick<GithubActionContext, "github" | "context">} githubActionContext
* @param {number} issueNumber
* @param {Comment["markerText"]} markerText
*/
export async function deleteComment(
{ github, context },
issueNumber,
markerText
) {
const { issues } = github.rest

// Find first match for marker
const comment = await getComment({ github, context }, issueNumber, markerText)

// Delete comment
if (comment) {
await issues.deleteComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id
})
}
}

/**
* Find GitHub issue comment with marker `<!-- Example -->`
*
Expand Down

0 comments on commit aabe22d

Please sign in to comment.