export async function pushQuickFixes()

in scan/src/utils.ts [169:236]


export async function pushQuickFixes(
  mode: PushFixesType,
  commitMessage: string
): Promise<void> {
  if (mode === NONE) {
    return
  }
  try {
    const c = github.context
    const pr = c.payload.pull_request as PullRequestPayload | undefined
    let currentBranch = c.ref

    if (pr?.head?.ref) {
      currentBranch = pr.head.ref
    }

    const currentCommit = (
      await exec.getExecOutput('git', ['rev-parse', 'HEAD'])
    ).stdout.trim()
    currentBranch = validateBranchName(currentBranch)
    await git(['config', 'user.name', COMMIT_USER])
    await git(['config', 'user.email', COMMIT_EMAIL])
    await git(['add', '.'])
    let exitCode = await git(['commit', '-m', commitMessage], {
      ignoreReturnCode: true
    })
    if (exitCode !== 0) {
      return
    }
    // Check for any files that may interfere with pull --rebase
    const statusOutput = await gitOutput(['status', '--porcelain'], {
      ignoreReturnCode: true
    })
    if (statusOutput.stdout.trim() !== '') {
      core.info(`Git status before pull --rebase:\n${statusOutput.stdout}`)
    }
    exitCode = await git(['pull', '--rebase', 'origin', currentBranch])
    if (exitCode !== 0) {
      return
    }
    if (mode === BRANCH) {
      if (pr?.head?.ref) {
        const commitToCherryPick = (
          await exec.getExecOutput('git', ['rev-parse', 'HEAD'])
        ).stdout.trim()
        await git(['checkout', currentBranch])
        await git(['cherry-pick', commitToCherryPick])
      }
      await git(['push', 'origin', currentBranch])
      core.info(`Pushed quick-fixes to branch ${currentBranch}`)
    } else if (mode === PULL_REQUEST) {
      const newBranch = `qodana/quick-fixes-${currentCommit.slice(0, 7)}`
      await git(['checkout', '-b', newBranch])
      await git(['push', 'origin', newBranch])
      await createPr(
        commitMessage,
        `${c.repo.owner}/${c.repo.repo}`,
        currentBranch,
        newBranch
      )
      core.info(
        `Pushed quick-fixes to branch ${newBranch} and created pull request`
      )
    }
  } catch (error) {
    core.warning(`Failed to push quick fixes – ${(error as Error).message}`)
  }
}