Skip to content

Commit

Permalink
Fix backwards-compat issues with {defaultPrDescription} (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Dec 12, 2023
1 parent 0bbe4d1 commit 757b14e
Show file tree
Hide file tree
Showing 8 changed files with 819 additions and 834 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"dependencies": {
"@octokit/rest": "^19.0.7",
"axios": "^1.6.0",
"axios": "^1.6.2",
"dedent": "^0.7.0",
"del": "^6.1.1",
"dotenv": "^16.0.3",
Expand Down Expand Up @@ -112,6 +112,6 @@
"strip-ansi": "^6.0.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "5.2.2"
"typescript": "5.3.3"
}
}
42 changes: 42 additions & 0 deletions src/lib/github/v3/createPullRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,48 @@ describe('getPullRequestBody', () => {
`);
});

it('replaces {defaultPrDescription} and {commits} in order to be backwards-compatible', () => {
const commits = [
{
sourcePullRequest: {
url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
},
sourceCommit: {
sha: 'abcdefghijklm',
message: 'My commit message (#55)',
},
sourceBranch: 'main',
},
{
sourceCommit: {
sha: 'qwertyuiop',
message: 'Another commit message',
},
},
] as Commit[];

const options = {
prDescription:
'{defaultPrDescription}\n\n<!--BACKPORT {commits} BACKPORT-->',
} as ValidConfigOptions;

expect(getPullRequestBody({ options, commits, targetBranch: '7.x' }))
.toMatchInlineSnapshot(`
"# Backport
This will backport the following commits from \`main\` to \`7.x\`:
- [My commit message (#55)](https://github.com/backport-org/different-merge-strategies/pull/55)
- Another commit message (qwertyui)
<!--- Backport version: 1.2.3-mocked -->
### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
<!--BACKPORT [{"sourcePullRequest":{"url":"https://github.com/backport-org/different-merge-strategies/pull/55"},"sourceCommit":{"sha":"abcdefghijklm","message":"My commit message (#55)"},"sourceBranch":"main"},{"sourceCommit":{"sha":"qwertyuiop","message":"Another commit message"}}] BACKPORT-->"
`);
});

it('replaces {{commitsStringified}} with a stringified commits object', () => {
const commits = [
{
Expand Down
4 changes: 3 additions & 1 deletion src/lib/github/v3/createPullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export function getPullRequestBody({

const customPrDescription = options.prDescription
?.replaceAll('{{defaultPrDescription}}', defaultPrDescription)
?.replaceAll('{{commitsStringified}}', JSON.stringify(commits));
?.replaceAll('{defaultPrDescription}', defaultPrDescription) // retain backwards compatibility
?.replaceAll('{{commitsStringified}}', JSON.stringify(commits))
?.replaceAll('{commits}', JSON.stringify(commits)); // retain backwards compatibility

const template = Handlebars.compile(
customPrDescription ?? defaultPrDescription,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe('enablePullRequestAutoMerge', () => {

expect(isMissingStatusChecks).toBe(false);
expect(errorMessage).toMatchInlineSnapshot(
`"["Merge method rebase merging is not allowed on this repository"] (Github API v4)"`,
`"Merge method rebase merging is not allowed on this repository (Github API v4)"`,
);

// ensure Github API reflects the change before querying
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('enablePullRequestAutoMerge', () => {
}

expect(errorMessage).toMatchInlineSnapshot(
`"["Pull request Pull request is in clean status"] (Github API v4)"`,
`"Pull request Pull request is in clean status (Github API v4)"`,
);
expect(isMissingStatusChecks).toBe(true);
});
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('enablePullRequestAutoMerge', () => {
}

expect(errorMessage).toMatchInlineSnapshot(
`"["Pull request Pull request is in clean status"] (Github API v4)"`,
`"Pull request Pull request is in clean status (Github API v4)"`,
);
expect(isMissingStatusChecks).toBe(true);
});
Expand Down
2 changes: 2 additions & 0 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export async function getOptions({
// cli args override the above
...optionsFromCliArgs,

editor: optionsFromCliArgs.editor === 'false' ? undefined : combined.editor,

// required properties
accessToken,
repoName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ View pull request: this-is-a-dry-run"
`--dir=${sandboxPath}`,
'--pr=9',
'--dry-run',
'--editor=false',
],
{
keepAlive: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('interactive error handling', () => {
await resetSandbox(backportDir);
const { output } = await runBackportViaCli(
[
'--editor=false',
'--repo=backport-org/repo-with-conflicts',
'--pr=12',
'--branch=7.x',
Expand Down
Loading

0 comments on commit 757b14e

Please sign in to comment.