Skip to content

Commit

Permalink
🐛 Do not spam with quick-fixes PRs (QD-7928)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jul 2, 2024
1 parent 9f1eab3 commit 7e0f596
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 52 deletions.
54 changes: 31 additions & 23 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135050,29 +135050,37 @@ var require_utils10 = __commonJS({
if (mode === qodana_12.NONE) {
return;
}
const c = github2.context;
let currentBranch = c.ref;
if (((_a = c.payload.pull_request) === null || _a === void 0 ? void 0 : _a.head.ref) !== void 0) {
currentBranch = c.payload.pull_request.head.ref;
}
currentBranch = (0, qodana_12.validateBranchName)(currentBranch);
yield git(["config", "user.name", output_12.COMMIT_USER]);
yield git(["config", "user.email", output_12.COMMIT_EMAIL]);
yield git(["add", "."]);
const exitCode = yield git(["commit", "-m", commitMessage], {
ignoreReturnCode: true
});
if (exitCode !== 0) {
return;
}
yield git(["pull", "--rebase", "origin", currentBranch]);
if (mode === qodana_12.BRANCH) {
yield git(["push", "origin", currentBranch]);
} else if (mode === qodana_12.PULL_REQUEST) {
const newBranch = `qodana/quick-fixes-${c.runId}`;
yield git(["checkout", "-b", newBranch]);
yield git(["push", "origin", newBranch]);
yield createPr(commitMessage, `${c.repo.owner}/${c.repo.repo}`, currentBranch, newBranch);
try {
const c = github2.context;
let currentBranch = c.ref;
if (((_a = c.payload.pull_request) === null || _a === void 0 ? void 0 : _a.head.ref) !== void 0) {
currentBranch = c.payload.pull_request.head.ref;
}
const currentCommit = (yield exec.getExecOutput("git", ["rev-parse", "HEAD"])).stdout.trim();
currentBranch = (0, qodana_12.validateBranchName)(currentBranch);
yield git(["config", "user.name", output_12.COMMIT_USER]);
yield git(["config", "user.email", output_12.COMMIT_EMAIL]);
yield git(["add", "."]);
let exitCode = yield git(["commit", "-m", commitMessage], {
ignoreReturnCode: true
});
if (exitCode !== 0) {
return;
}
exitCode = yield git(["pull", "--rebase", "origin", currentBranch]);
if (exitCode !== 0) {
return;
}
if (mode === qodana_12.BRANCH) {
yield git(["push", "origin", currentBranch]);
} else if (mode === qodana_12.PULL_REQUEST) {
const newBranch = `qodana/quick-fixes-${currentCommit.slice(0, 7)}`;
yield git(["checkout", "-b", newBranch]);
yield git(["push", "origin", newBranch]);
yield createPr(commitMessage, `${c.repo.owner}/${c.repo.repo}`, currentBranch, newBranch);
}
} catch (error) {
core2.warning(`Failed to push quick fixes \u2013 ${error.message}`);
}
});
}
Expand Down
67 changes: 38 additions & 29 deletions scan/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,44 @@ export async function pushQuickFixes(
if (mode === NONE) {
return
}
const c = github.context
let currentBranch = c.ref
if (c.payload.pull_request?.head.ref !== undefined) {
currentBranch = c.payload.pull_request.head.ref
}
currentBranch = validateBranchName(currentBranch)
await git(['config', 'user.name', COMMIT_USER])
await git(['config', 'user.email', COMMIT_EMAIL])
await git(['add', '.'])
const exitCode = await git(['commit', '-m', commitMessage], {
ignoreReturnCode: true
})
if (exitCode !== 0) {
return
}

await git(['pull', '--rebase', 'origin', currentBranch])
if (mode === BRANCH) {
await git(['push', 'origin', currentBranch])
} else if (mode === PULL_REQUEST) {
const newBranch = `qodana/quick-fixes-${c.runId}`
await git(['checkout', '-b', newBranch])
await git(['push', 'origin', newBranch])
await createPr(
commitMessage,
`${c.repo.owner}/${c.repo.repo}`,
currentBranch,
newBranch
)
try {
const c = github.context
let currentBranch = c.ref
if (c.payload.pull_request?.head.ref !== undefined) {
currentBranch = c.payload.pull_request.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
}
exitCode = await git(['pull', '--rebase', 'origin', currentBranch])
if (exitCode !== 0) {
return
}
if (mode === BRANCH) {
await git(['push', 'origin', 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
)
}
} catch (error) {
core.warning(`Failed to push quick fixes – ${(error as Error).message}`)
}
}

Expand Down

0 comments on commit 7e0f596

Please sign in to comment.