diff --git a/src/options/cliArgs.ts b/src/options/cliArgs.ts index fd97ffa2..e32657a1 100644 --- a/src/options/cliArgs.ts +++ b/src/options/cliArgs.ts @@ -45,6 +45,11 @@ export function getOptionsFromCliArgs( description: 'Backport to multiple branches', type: 'boolean' }) + .option('prDescription', { + default: configOptions.prDescription, + description: 'Description to be added to pull request', + type: 'string' + }) .option('sha', { description: 'Commit sha to backport', type: 'string', @@ -73,6 +78,7 @@ export function getOptionsFromCliArgs( multiple: cliArgs.multiple, multipleBranches: cliArgs.multipleBranches || cliArgs.multiple, multipleCommits: cliArgs.multipleCommits || cliArgs.multiple, + prDescription: cliArgs.prDescription, sha: cliArgs.sha, upstream: cliArgs.upstream, username: cliArgs.username diff --git a/src/options/config/globalConfig.ts b/src/options/config/globalConfig.ts index fd1ccdd4..737ace4e 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; + prDescription?: string; // the following are overwritable by project config: all?: boolean; diff --git a/src/options/options.ts b/src/options/options.ts index a2334b53..02c8889b 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -46,6 +46,7 @@ export function validateOptions({ multiple, multipleBranches, multipleCommits, + prDescription, sha, upstream, username @@ -83,6 +84,7 @@ export function validateOptions({ multiple, multipleBranches, multipleCommits, + prDescription, sha, upstream, username diff --git a/src/steps/doBackportVersions.ts b/src/steps/doBackportVersions.ts index 92723b34..5b0a3737 100644 --- a/src/steps/doBackportVersions.ts +++ b/src/steps/doBackportVersions.ts @@ -22,7 +22,8 @@ export function doBackportVersions( commits: Commit[], branches: string[], username: string, - labels: string[] + labels: string[], + prDescription: string | undefined ) { return sequentially(branches, async branch => { try { @@ -32,7 +33,8 @@ export function doBackportVersions( commits, branch, username, - labels + labels, + prDescription ); log(`View pull request: ${pullRequest.html_url}`); } catch (e) { @@ -52,7 +54,8 @@ export async function doBackportVersion( commits: Commit[], baseBranch: string, username: string, - labels: string[] = [] + labels: string[] = [], + prDescription: string | undefined ) { const featureBranch = getFeatureBranchName(baseBranch, commits); const refValues = commits.map(commit => getReferenceLong(commit)).join(', '); @@ -84,7 +87,12 @@ export async function doBackportVersion( ); return withSpinner({ text: 'Creating pull request' }, async () => { - const payload = getPullRequestPayload(baseBranch, commits, username); + const payload = getPullRequestPayload( + baseBranch, + commits, + username, + prDescription + ); const pullRequest = await createPullRequest(owner, repoName, payload); if (labels.length > 0) { await addLabelsToPullRequest(owner, repoName, pullRequest.number, labels); @@ -178,7 +186,8 @@ function getPullRequestTitle(baseBranch: string, commits: Commit[]) { export function getPullRequestPayload( baseBranch: string, commits: Commit[], - username: string + username: string, + prDescription: string | undefined ) { const featureBranch = getFeatureBranchName(baseBranch, commits); const commitRefs = commits @@ -188,9 +197,11 @@ export function getPullRequestPayload( }) .join('\n'); + const bodySuffix = prDescription ? `\n\n${prDescription}` : ''; + return { title: getPullRequestTitle(baseBranch, commits), - body: `Backports the following commits to ${baseBranch}:\n${commitRefs}`, + 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 2d6e145a..99dc8536 100755 --- a/src/steps/steps.ts +++ b/src/steps/steps.ts @@ -24,6 +24,7 @@ export async function initSteps(options: BackportOptions) { commits, branches, options.username, - options.labels + options.labels, + options.prDescription ); } diff --git a/test/options/options.test.ts b/test/options/options.test.ts index 3921446f..c917d704 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, + prDescription: undefined, sha: undefined, upstream: 'elastic/kibana', username: 'sqren' diff --git a/test/steps/__snapshots__/steps.test.ts.snap b/test/steps/__snapshots__/steps.test.ts.snap index 59042bfb..50403247 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)\\",\\"head\\":\\"sqren:backport/6.2/pr-myPullRequestNumber\\",\\"base\\":\\"6.2\\"}", + "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\\"}", "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 2f5a9381..ac773edf 100644 --- a/test/steps/doBackportVersions.test.ts +++ b/test/steps/doBackportVersions.test.ts @@ -56,7 +56,8 @@ describe('doBackportVersion', () => { commits, '6.x', 'sqren', - ['backport'] + ['backport'], + 'myPrSuffix' ); }); @@ -76,7 +77,7 @@ describe('doBackportVersion', () => { { title: '[6.x] myCommitMessage | myOtherCommitMessage', body: - 'Backports the following commits to 6.x:\n - myCommitMessage (#1000)\n - myOtherCommitMessage (#2000)', + 'Backports the following commits to 6.x:\n - myCommitMessage (#1000)\n - myOtherCommitMessage (#2000)\n\nmyPrSuffix', head: 'sqren:backport/6.x/pr-1000_pr-2000', base: '6.x' } @@ -99,9 +100,15 @@ describe('doBackportVersion', () => { } ]; - await doBackportVersion('elastic', 'kibana', commits, '6.x', 'sqren', [ - 'backport' - ]); + await doBackportVersion( + 'elastic', + 'kibana', + commits, + '6.x', + 'sqren', + ['backport'], + undefined + ); }); it('should create pull request and add labels', () => { @@ -160,7 +167,8 @@ describe('doBackportVersion', () => { commits, '6.x', 'sqren', - ['backport'] + ['backport'], + undefined ); return { logSpy, execSpy, promise }; diff --git a/test/steps/steps.test.ts b/test/steps/steps.test.ts index fc0975b0..af04eb6e 100644 --- a/test/steps/steps.test.ts +++ b/test/steps/steps.test.ts @@ -147,14 +147,9 @@ describe('run through steps', () => { }); await initSteps({ - username: 'sqren', - branches: [], - sha: undefined, accessToken: 'myAccessToken', - multiple: false, - multipleBranches: false, - multipleCommits: false, - upstream, + all: false, + branches: [], branchChoices: [ { name: '6.x' }, { name: '6.0' }, @@ -162,8 +157,14 @@ describe('run through steps', () => { { name: '5.5' }, { name: '5.4' } ], - all: false, - labels: [] + labels: [], + multiple: false, + multipleBranches: false, + multipleCommits: false, + prDescription: 'myPrDescription', + sha: undefined, + upstream, + username: 'sqren' }); }); @@ -183,7 +184,7 @@ describe('run through steps', () => { it('createPullRequest should be called with correct args', () => { expect(github.createPullRequest).toHaveBeenCalledWith('elastic', 'kibana', { base: '6.2', - body: `Backports the following commits to 6.2:\n - myCommitMessage (#myPullRequestNumber)`, + body: `Backports the following commits to 6.2:\n - myCommitMessage (#myPullRequestNumber)\n\nmyPrDescription`, head: 'sqren:backport/6.2/pr-myPullRequestNumber', title: '[6.2] myCommitMessage' });