Skip to content

Commit

Permalink
fix: improve squashed commit message (#204)
Browse files Browse the repository at this point in the history
* Removes reference to original PR from message to avoid double PR reference
* Replaces instances of ({branch}) with ({newBranch}) so the backport message makes sense

Co-authored-by: Shelley Vohr <[email protected]>
Co-authored-by: John Kleinschmidt <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2023
1 parent 5f6fbeb commit 7fbf8fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
24 changes: 22 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,22 @@ const tryBackportSquashCommit = async (opts: TryBackportOptions) => {
},
});

const patch = await patchBody.text();
const rawPatch = await patchBody.text();
let patch: string = '';
let subjectLineFound = false;
for (const patchLine of rawPatch.split('\n')) {
if (patchLine.startsWith('Subject: ') && !subjectLineFound) {
subjectLineFound = true;
const branchAwarePatchLine = patchLine
// Replace branch references in commit message with new branch
.replaceAll(`(${opts.pr.base.ref})`, `${opts.targetBranch}`)
// Replace PR references in squashed message with empty string
.replaceAll(/ \(#[0-9]+\)$/g, '');
patch += `${branchAwarePatchLine}\n`;
} else {
patch += `${patchLine}\n`;
}
}

log('backportImpl', LogLevel.INFO, 'Got squash commit details');

Expand Down Expand Up @@ -516,11 +531,16 @@ export const backportImpl = async (
if (purpose === BackportPurpose.ExecuteBackport) {
log('backportImpl', LogLevel.INFO, 'Creating Pull Request');

const branchAwarePrTitle = pr.title.replaceAll(
`(${pr.base.ref})`,
`(${targetBranch})`,
);

const { data: newPr } = await context.github.pulls.create(
context.repo({
head: `${tempBranch}`,
base: targetBranch,
title: pr.title,
title: branchAwarePrTitle,
body: await createBackportComment(context, pr),
maintainer_can_modify: false,
}),
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"target": "es2018",
"outDir": "lib",
"lib": [
"es6",
"es2016.array.include"
"ESNext"
],
"sourceMap": true,
"rootDir": "src",
Expand Down

0 comments on commit 7fbf8fe

Please sign in to comment.