in vsts/src/utils.ts [454:518]
export async function pushQuickFixes(
mode: PushFixesType,
commitMessage: string
): Promise<void> {
if (mode === NONE) {
return
}
try {
const pullRequest = tl.getVariable('Build.Reason') === 'PullRequest'
let currentBranch
if (pullRequest) {
currentBranch = getVariable('System.PullRequest.SourceBranch')
} else {
currentBranch = getVariable('Build.SourceBranch')
}
currentBranch = currentBranch.replace('refs/heads/', '')
currentBranch = validateBranchName(currentBranch)
const currentCommit = (
await gitOutput(['rev-parse', 'HEAD'], false)
).stdout.trim()
await git(['config', 'user.name', COMMIT_USER], false)
await git(['config', 'user.email', COMMIT_EMAIL], false)
await git(['add', '.'], false)
const exitCode = await git(['commit', '-m', commitMessage], false, {
ignoreReturnCode: true
})
if (exitCode !== 0) {
return
}
// Check for any files that may interfere with pull --rebase
const statusOutput = await gitOutput(['status', '--porcelain'], false, {
ignoreReturnCode: true
})
if (statusOutput.stdout.trim() !== '') {
console.log(`Git status before pull --rebase:\n${statusOutput.stdout}`)
}
const pullExitCode = await git(
['pull', '--rebase', 'origin', currentBranch],
true
)
if (pullExitCode !== 0) {
return
}
if (mode === BRANCH) {
const commitToCherryPick = (
await gitOutput(['rev-parse', 'HEAD'], false)
).stdout.trim()
await git(['checkout', currentBranch], false)
await git(['cherry-pick', commitToCherryPick], false)
await gitPush(currentBranch)
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], false)
await gitPush(newBranch)
await createPr(commitMessage, currentBranch, newBranch)
console.log(
`Pushed quick-fixes to branch ${newBranch} and created pull request`
)
}
} catch (error) {
tl.warning(`Failed to push quick fixes – ${(error as Error).message}`)
}
}