Unverified Commit 0ba1ea61 authored by Michael Daniels's avatar Michael Daniels
Browse files

ci/github-script/reviews: allow leaving review comments

parent e05e9846
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
const eventToState = {
  COMMENT: 'COMMENTED',
  REQUEST_CHANGES: 'CHANGES_REQUESTED',
}

/**
 * @param {{
 *  github: InstanceType<import('@actions/github/lib/utils').GitHub>,
 *  context: import('@actions/github/lib/context').Context
 *  core: import('@actions/core')
 *  dry: boolean
 * }} CheckTargetBranchProps
 */
async function dismissReviews({ github, context, dry }) {
  const pull_number = context.payload.pull_request.number

@@ -36,7 +49,14 @@ async function dismissReviews({ github, context, dry }) {
  )
}

async function postReview({ github, context, core, dry, body }) {
async function postReview({
  github,
  context,
  core,
  dry,
  body,
  event = 'REQUEST_CHANGES',
}) {
  const pull_number = context.payload.pull_request.number

  const pendingReview = (
@@ -49,7 +69,7 @@ async function postReview({ github, context, core, dry, body }) {
      review.user?.login === 'github-actions[bot]' &&
      // If a review is still pending, we can just update this instead
      // of posting a new one.
      review.state === 'CHANGES_REQUESTED',
      review.state === eventToState[event],
  )

  if (dry) {
@@ -69,7 +89,7 @@ async function postReview({ github, context, core, dry, body }) {
      await github.rest.pulls.createReview({
        ...context.repo,
        pull_number,
        event: 'REQUEST_CHANGES',
        event,
        body,
      })
    }