diff --git a/README.md b/README.md index 5844d2ac..8b8e6e34 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ The above commands will start an interactive prompt. You can use the `arrow keys | --labels | Pull request labels | string | | --multiple | Backport multiple commits and/or branches | boolean | | --prDescription | Description to be added to pull request | string | +| --prTitle | Title for the pull request | string | | --sha | Commit sha to backport | string | | --upstream | Name of repository | string | | --username | Github username | string | diff --git a/docs/configuration.md b/docs/configuration.md index 6dd9c69b..6924bea3 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -104,6 +104,17 @@ Example: `["backport", "apm-team"]` CLI: `--labels myLabel --labels myOtherLabel` +#### `prTitle` + +Text that will be the pull request title. Note: You can access the base branch (`baseBranch`) and commit message (`commitMessages`) strings by wrapping them in curly braces (See Example). +If there are multiple commits the commit messages will be concatenated and separated by pipes. + +Example: `"{commitMessages} backport for {baseBranch}"` + +Default: `"[{baseBranch}] {commitMessages}"` + +CLI: `--prTitle "My PR Title"` + #### `prDescription` Text that will be added to the pull request body. diff --git a/src/options/cliArgs.ts b/src/options/cliArgs.ts index 602d26db..f9afafec 100644 --- a/src/options/cliArgs.ts +++ b/src/options/cliArgs.ts @@ -46,6 +46,11 @@ export function getOptionsFromCliArgs( description: 'Backport to multiple branches', type: 'boolean' }) + .option('prTitle', { + default: configOptions.prTitle, + description: 'Title of pull request', + type: 'string' + }) .option('prDescription', { default: configOptions.prDescription, description: 'Description to be added to pull request', @@ -79,6 +84,7 @@ export function getOptionsFromCliArgs( multiple: cliArgs.multiple, multipleBranches: cliArgs.multipleBranches || cliArgs.multiple, multipleCommits: cliArgs.multipleCommits || cliArgs.multiple, + prTitle: cliArgs.prTitle, prDescription: cliArgs.prDescription, sha: cliArgs.sha, upstream: cliArgs.upstream, diff --git a/src/options/config/config.ts b/src/options/config/config.ts index de0f33c3..6580ee1a 100644 --- a/src/options/config/config.ts +++ b/src/options/config/config.ts @@ -18,6 +18,7 @@ export async function getOptionsFromConfigFiles() { multipleBranches: true, all: false, labels: [] as string[], + prTitle: '[{baseBranch}] {commitMessages}', // options from config files ...globalConfig, diff --git a/src/options/config/globalConfig.ts b/src/options/config/globalConfig.ts index 737ace4e..b2d42e01 100644 --- a/src/options/config/globalConfig.ts +++ b/src/options/config/globalConfig.ts @@ -5,6 +5,7 @@ import { getGlobalConfigPath, getReposPath } from '../../services/env'; interface GlobalConfig { username?: string; accessToken?: string; + prTitle?: string; prDescription?: string; // the following are overwritable by project config: diff --git a/src/options/options.ts b/src/options/options.ts index 02c8889b..328fd92c 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -46,6 +46,7 @@ export function validateOptions({ multiple, multipleBranches, multipleCommits, + prTitle, prDescription, sha, upstream, @@ -84,6 +85,7 @@ export function validateOptions({ multiple, multipleBranches, multipleCommits, + prTitle, prDescription, sha, upstream, diff --git a/src/steps/doBackportVersions.ts b/src/steps/doBackportVersions.ts index 7956784a..671c5632 100644 --- a/src/steps/doBackportVersions.ts +++ b/src/steps/doBackportVersions.ts @@ -24,6 +24,7 @@ export function doBackportVersions( branches: string[], username: string, labels: string[], + prTitle: string, prDescription: string | undefined ) { return sequentially(branches, async branch => { @@ -35,6 +36,7 @@ export function doBackportVersions( branch, username, labels, + prTitle, prDescription ); log(`View pull request: ${pullRequest.html_url}`); @@ -56,6 +58,7 @@ export async function doBackportVersion( baseBranch: string, username: string, labels: string[] = [], + prTitle: string, prDescription: string | undefined ) { const featureBranch = getFeatureBranchName(baseBranch, commits); @@ -92,6 +95,7 @@ export async function doBackportVersion( baseBranch, commits, username, + prTitle, prDescription ); const pullRequest = await createPullRequest(owner, repoName, payload); @@ -171,19 +175,27 @@ async function resolveConflictsOrAbort(owner: string, repoName: string) { } } -function getPullRequestTitle(baseBranch: string, commits: Commit[]) { +function getPullRequestTitle( + baseBranch: string, + commits: Commit[], + prTitle: string +) { const commitMessages = commits .map(commit => commit.message) .join(' | ') .slice(0, 200); - return `[${baseBranch}] ${commitMessages}`; + // prTitle could include baseBranch or commitMessages in template literal + return prTitle + .replace('{baseBranch}', baseBranch) + .replace('{commitMessages}', commitMessages); } export function getPullRequestPayload( baseBranch: string, commits: Commit[], username: string, + prTitle: string, prDescription: string | undefined ) { const featureBranch = getFeatureBranchName(baseBranch, commits); @@ -197,7 +209,7 @@ export function getPullRequestPayload( const bodySuffix = prDescription ? `\n\n${prDescription}` : ''; return { - title: getPullRequestTitle(baseBranch, commits), + title: getPullRequestTitle(baseBranch, commits, prTitle), body: `Backports the following commits to ${baseBranch}:\n${commitRefs}${bodySuffix}`, head: `${username}:${featureBranch}`, base: `${baseBranch}` diff --git a/src/steps/steps.ts b/src/steps/steps.ts index 99dc8536..b475bcba 100755 --- a/src/steps/steps.ts +++ b/src/steps/steps.ts @@ -25,6 +25,7 @@ export async function initSteps(options: BackportOptions) { branches, options.username, options.labels, + options.prTitle, options.prDescription ); } diff --git a/test/options/cliArgs.test.ts b/test/options/cliArgs.test.ts index 4f53e065..c233d10b 100644 --- a/test/options/cliArgs.test.ts +++ b/test/options/cliArgs.test.ts @@ -12,6 +12,7 @@ describe('getOptionsFromCliArgs', () => { multiple: false, multipleBranches: true, multipleCommits: false, + prTitle: 'myPrTitle', upstream: 'elastic/kibana', username: 'sqren' }; @@ -43,6 +44,7 @@ describe('getOptionsFromCliArgs', () => { multiple: false, multipleBranches: true, multipleCommits: false, + prTitle: 'myPrTitle', sha: undefined, upstream: 'sqren/backport-demo', username: 'sqren' diff --git a/test/options/config/config.test.ts b/test/options/config/config.test.ts index 3878ffd3..ece13e75 100644 --- a/test/options/config/config.test.ts +++ b/test/options/config/config.test.ts @@ -40,6 +40,7 @@ describe('getOptionsFromConfigFiles', () => { multiple: false, multipleBranches: true, multipleCommits: false, + prTitle: '[{baseBranch}] {commitMessages}', upstream: 'elastic/kibana', username: 'sqren' }); diff --git a/test/options/options.test.ts b/test/options/options.test.ts index c917d704..aa2b71b8 100644 --- a/test/options/options.test.ts +++ b/test/options/options.test.ts @@ -9,6 +9,7 @@ const validOptions = { multiple: false, multipleBranches: true, multipleCommits: false, + prTitle: 'myPrTitle', prDescription: undefined, sha: undefined, upstream: 'elastic/kibana', diff --git a/test/steps/__snapshots__/steps.test.ts.snap b/test/steps/__snapshots__/steps.test.ts.snap index 966bfc1d..a63e05c7 100644 --- a/test/steps/__snapshots__/steps.test.ts.snap +++ b/test/steps/__snapshots__/steps.test.ts.snap @@ -234,7 +234,7 @@ Object { "patch": Array [], "post": Array [ Object { - "data": "{\\"title\\":\\"[6.2] myCommitMessage\\",\\"body\\":\\"Backports the following commits to 6.2:\\\\n - myCommitMessage (#myPullRequestNumber)\\\\n\\\\nmyPrDescription\\",\\"head\\":\\"sqren:backport/6.2/pr-myPullRequestNumber\\",\\"base\\":\\"6.2\\"}", + "data": "{\\"title\\":\\"myPrTitle\\",\\"body\\":\\"Backports the following commits to 6.2:\\\\n - myCommitMessage (#myPullRequestNumber)\\\\n\\\\nmyPrDescription\\",\\"head\\":\\"sqren:backport/6.2/pr-myPullRequestNumber\\",\\"base\\":\\"6.2\\"}", "headers": Object { "Accept": "application/json, text/plain, */*", "Content-Type": "application/json;charset=utf-8", diff --git a/test/steps/doBackportVersions.test.ts b/test/steps/doBackportVersions.test.ts index ac773edf..8a59a4e3 100644 --- a/test/steps/doBackportVersions.test.ts +++ b/test/steps/doBackportVersions.test.ts @@ -57,6 +57,7 @@ describe('doBackportVersion', () => { '6.x', 'sqren', ['backport'], + '[{baseBranch}] {commitMessages}', 'myPrSuffix' ); }); @@ -107,6 +108,7 @@ describe('doBackportVersion', () => { '6.x', 'sqren', ['backport'], + '[{baseBranch}] {commitMessages}', undefined ); }); @@ -168,6 +170,7 @@ describe('doBackportVersion', () => { '6.x', 'sqren', ['backport'], + 'myPrTitle', undefined ); diff --git a/test/steps/steps.test.ts b/test/steps/steps.test.ts index 7e106f9d..87cdc15d 100644 --- a/test/steps/steps.test.ts +++ b/test/steps/steps.test.ts @@ -161,6 +161,7 @@ describe('run through steps', () => { multiple: false, multipleBranches: false, multipleCommits: false, + prTitle: 'myPrTitle', prDescription: 'myPrDescription', sha: undefined, upstream, @@ -185,7 +186,7 @@ describe('run through steps', () => { base: '6.2', body: `Backports the following commits to 6.2:\n - myCommitMessage (#myPullRequestNumber)\n\nmyPrDescription`, head: 'sqren:backport/6.2/pr-myPullRequestNumber', - title: '[6.2] myCommitMessage' + title: 'myPrTitle' }); });