in gitlab/src/utils.ts [427:487]
export async function pushQuickFixes(
mode: PushFixesType,
commitMessage: string
): Promise<void> {
if (mode === NONE) {
return
}
try {
let currentBranch
if (isMergeRequest()) {
currentBranch = getEnvVariable('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME')
} else {
currentBranch = getEnvVariable('CI_COMMIT_BRANCH')
}
currentBranch = validateBranchName(currentBranch)
const currentCommit = (await gitOutput(['rev-parse', 'HEAD'])).stdout.trim()
await git(['config', 'user.name', COMMIT_USER])
await git(['config', 'user.email', COMMIT_EMAIL])
await git(['add', '.'])
commitMessage = commitMessage + '\n\n[skip-ci]'
const output = await gitOutput(['commit', '-m', `'${commitMessage}'`], true)
if (output.returnCode !== 0) {
console.warn(`Failed to commit fixes: ${output.stderr}`)
return
}
// Check for any files that may interfere with pull --rebase
const statusOutput = await gitOutput(['status', '--porcelain'], true)
if (statusOutput.stdout.trim() !== '') {
console.log(`Git status before pull --rebase:\n${statusOutput.stdout}`)
}
const pullReturnCode = await git([
'pull',
'--rebase',
'origin',
currentBranch
])
if (pullReturnCode !== 0) {
return
}
if (mode === BRANCH) {
const commitToCherryPick = (
await gitOutput(['rev-parse', 'HEAD'])
).stdout.trim()
await git(['checkout', currentBranch])
await git(['cherry-pick', commitToCherryPick])
await git(['fetch', 'origin', currentBranch])
await gitPush(currentBranch, false)
console.log(`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 gitPush(newBranch, true)
await createPr(commitMessage, newBranch, currentBranch)
console.log(
`Pushed quick-fixes to branch ${newBranch} and created pull request`
)
}
} catch (e) {
console.warn(`Failed to push quick fixes – ${(e as Error).message}`)
}
}