Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cli naming (breaking changes) #183

Merged
merged 6 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Example:
{
"upstream": "elastic/kibana",
"branches": [{ "name": "6.x", "checked": true }, "6.3", "6.2", "6.1", "6.0"],
"labels": ["backport"]
"targetPRLabels": ["backport"]
}
```

Expand All @@ -79,7 +79,7 @@ Config:

List of branches that will be available to backport to. The array can contain branch names as strings or objects that also contains the field `checked` which indicates whether the branch should be pre-selected. It is useful to pre-select branches you often backport to.

CLI: `--branches 6.1 --branches 6.0`
CLI: `--branch 6.1 --branch 6.0`

Config:

Expand All @@ -104,16 +104,17 @@ CLI: `--all`
Pre-select branch options based on labels on the source PR.

Example:

```json
{
"branchLabelMapping": {
"v8.0.0": "",
"^v7.8.0$": "7.x",
"^v(\\d+).(\\d+).\\d+$": "$1.$2"
}
}
```
*Note: backslashes must be escaped.*

_Note: backslashes must be escaped._

#### `fork`

Expand Down Expand Up @@ -182,20 +183,6 @@ Default: `false`

Default: `true`

#### `labels`

Labels that will be added to the backport pull request. These are often useful if you want to filter for backport PRs.

CLI: `--labels backport --labels apm-team`

Config:

```json
{
"labels": ["backport", "apm-team"]
}
```

#### `prTitle`

Pull request title pattern.
Expand Down Expand Up @@ -251,3 +238,31 @@ Config:
"sourceBranch": "7.x"
}
```

#### `sourcePRLabels`

Labels that will be added to the source (original) pull request. This can be useful if you, at a later time, want to filter for PRs that were already backported.

CLI: `--source-labels backport --source-labels apm-team`

Config:

```json
{
"sourcePRLabels": ["was-backported"]
}
```

#### `targetPRLabels`

Labels that will be added to the target (backport) pull request. This can be useful if you, at a later time, want to filter for backport PRs.

CLI: `--labels backport --labels apm-team`

Config:

```json
{
"targetPRLabels": ["backport", "apm-team"]
}
```
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
},
"license": "MIT",
"scripts": {
"format": "prettier \"./{src,test}/**/*.{ts,js,json}\" --write",
"lint": "tsc --project ./src/test/tsconfig.json && eslint './**/*.{ts,js}'",
"postinstall": "test -f ./dist/scripts/runPostinstall.js && node ./dist/scripts/runPostinstall.js || echo 'Dist folder missing'",
"prepublishOnly": "tsc",
"publish-dry-run": "tar -tf $(npm pack)",
"test": "jest",
"start": "ts-node --transpile-only ./src/index.ts"
},
Expand Down
10 changes: 5 additions & 5 deletions src/__snapshots__/runWithOptions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Array [
"name": "1. Add 👻 (2e63475c) ",
"short": "2e63475c",
"value": Object {
"existingBackports": Array [],
"existingTargetPullRequests": Array [],
"formattedMessage": "Add 👻 (2e63475c)",
"pullNumber": undefined,
"sha": "2e63475c483f7844b0f2833bc57fdee32095bacb",
Expand All @@ -100,7 +100,7 @@ Array [
"name": "2. Add witch (#85) ",
"short": "#85 (f3b618b9)",
"value": Object {
"existingBackports": Array [],
"existingTargetPullRequests": Array [],
"formattedMessage": "Add witch (#85)",
"pullNumber": 85,
"sha": "f3b618b9421fdecdb36862f907afbdd6344b361d",
Expand All @@ -112,7 +112,7 @@ Array [
"name": "3. Add SF mention (#80) 6.3",
"short": "#80 (79cf1845)",
"value": Object {
"existingBackports": Array [
"existingTargetPullRequests": Array [
Object {
"branch": "6.3",
"state": "MERGED",
Expand All @@ -129,7 +129,7 @@ Array [
"name": "4. Add backport config (3827bbba) ",
"short": "3827bbba",
"value": Object {
"existingBackports": Array [],
"existingTargetPullRequests": Array [],
"formattedMessage": "Add backport config (3827bbba)",
"pullNumber": undefined,
"sha": "3827bbbaf39914eda4f02f6940189844375fd097",
Expand All @@ -141,7 +141,7 @@ Array [
"name": "5. Initial commit (5ea0da55) ",
"short": "5ea0da55",
"value": Object {
"existingBackports": Array [],
"existingTargetPullRequests": Array [],
"formattedMessage": "Initial commit (5ea0da55)",
"pullNumber": undefined,
"sha": "5ea0da550ac191029459289d67f99ad7d310812b",
Expand Down
8 changes: 4 additions & 4 deletions src/options/cliArgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ describe('getOptionsFromCliArgs', () => {
all: false,
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
backportCreatedLabels: [],
sourcePRLabels: [],
targetBranchChoices: [],
fork: true,
gitHostname: 'github.com',
labels: [],
targetPRLabels: [],
multiple: false,
multipleBranches: true,
multipleCommits: false,
Expand Down Expand Up @@ -40,13 +40,13 @@ describe('getOptionsFromCliArgs', () => {
all: true,
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
backportCreatedLabels: [],
sourcePRLabels: [],
dryRun: false,
targetBranches: ['6.0', '6.1'],
targetBranchChoices: [],
fork: true,
gitHostname: 'github.com',
labels: [],
targetPRLabels: [],
multiple: false,
multipleBranches: true,
multipleCommits: false,
Expand Down
54 changes: 30 additions & 24 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,18 @@ export function getOptionsFromCliArgs(
.option('all', {
default: configOptions.all,
description: 'List all commits',
alias: 'a',
type: 'boolean',
})
.option('author', {
default: configOptions.author,
description: 'Show commits by specific author',
type: 'string',
})
.option('backportCreatedLabels', {
default: configOptions.backportCreatedLabels,
description: 'Pull request labels for the original PR',
type: 'array',
})
.option('targetBranches', {
default: [] as string[],
description: 'Branch(es) to backport to',
type: 'array',
alias: 'branch',
string: true, // ensure `6.0` is not coerced to `6`
})
.option('commitsCount', {
default: configOptions.commitsCount,
.option('maxNumber', {
default: configOptions.maxNumber,
description: 'Number of commits to choose from',
alias: 'count',
alias: ['number', 'n'],
type: 'number',
})
.option('dryRun', {
Expand Down Expand Up @@ -76,11 +65,6 @@ export function getOptionsFromCliArgs(
description: `Base url for Github's GraphQL (v4) API`,
type: 'string',
})
.option('labels', {
default: configOptions.labels,
description: 'Pull request labels for the resulting backport PRs',
type: 'array',
})
.option('mainline', {
description:
'Parent id of merge commit. Defaults to 1 when supplied without arguments',
Expand Down Expand Up @@ -118,16 +102,19 @@ export function getOptionsFromCliArgs(
.option('path', {
default: configOptions.path,
description: 'Only list commits touching files under the specified path',
alias: 'p',
type: 'string',
})
.option('prTitle', {
default: configOptions.prTitle,
description: 'Title of pull request',
alias: 'title',
type: 'string',
})
.option('prDescription', {
default: configOptions.prDescription,
description: 'Description to be added to pull request',
alias: 'description',
type: 'string',
})
.option('pullNumber', {
Expand All @@ -145,16 +132,35 @@ export function getOptionsFromCliArgs(
type: 'string',
alias: 'commit',
})
.option('upstream', {
default: configOptions.upstream,
description: 'Name of repository',
type: 'string',
.option('sourcePRLabels', {
default: configOptions.sourcePRLabels,
description: 'Add labels to the source (original) PR',
type: 'array',
})
.option('sourceBranch', {
default: configOptions.sourceBranch,
description: `List commits to backport from another branch than master`,
type: 'string',
})
.option('targetBranches', {
default: [] as string[],
description: 'Branch(es) to backport to',
type: 'array',
alias: ['branch', 'b'],
string: true, // ensure `6.0` is not coerced to `6`
})
.option('targetPRLabels', {
default: configOptions.targetPRLabels,
description: 'Add labels to the target (backport) PR',
alias: 'labels',
type: 'array',
})
.option('upstream', {
default: configOptions.upstream,
description: 'Name of repository',
alias: 'up',
type: 'string',
})
.option('username', {
default: configOptions.username,
description: 'Github username',
Expand Down
4 changes: 2 additions & 2 deletions src/options/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('getOptionsFromConfigFiles', () => {
all: false,
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
backportCreatedLabels: [],
sourcePRLabels: [],
targetBranchChoices: [
{ checked: false, name: '6.0' },
{ checked: false, name: '5.9' },
],
fork: true,
gitHostname: 'github.com',
labels: [],
targetPRLabels: [],
multiple: false,
multipleBranches: true,
multipleCommits: false,
Expand Down
4 changes: 2 additions & 2 deletions src/options/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export async function getOptionsFromConfigFiles() {

return {
// defaults
backportCreatedLabels: [] as string[] | never[],
sourcePRLabels: [] as string[] | never[],
fork: true,
multiple: false,
multipleCommits: false,
multipleBranches: true,
all: false,
labels: [] as string[],
targetPRLabels: [] as string[],
prTitle: '[{targetBranch}] {commitMessages}',
gitHostname: 'github.com',
githubApiBaseUrlV3: 'https://api.github.com',
Expand Down
10 changes: 5 additions & 5 deletions src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('getOptions', () => {
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
author: 'sqren',
backportCreatedLabels: [],
sourcePRLabels: [],
dryRun: false,
targetBranchChoices: [
{ checked: false, name: '6.0' },
Expand All @@ -86,7 +86,7 @@ describe('getOptions', () => {
targetBranches: ['6.0', '6.1'],
fork: true,
gitHostname: 'github.com',
labels: [],
targetPRLabels: [],
multiple: false,
multipleBranches: true,
multipleCommits: false,
Expand All @@ -109,15 +109,15 @@ describe('validateRequiredOptions', () => {
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
author: undefined,
backportCreatedLabels: [],
sourcePRLabels: [],
dryRun: false,
targetBranchChoices: [],
targetBranches: ['branchA'],
commitsCount: 10,
maxNumber: 10,
editor: 'code',
fork: true,
gitHostname: 'github.com',
labels: [],
targetPRLabels: [],
mainline: undefined,
multiple: false,
multipleBranches: true,
Expand Down
6 changes: 3 additions & 3 deletions src/runWithOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('runWithOptions', () => {
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
author: 'sqren',
backportCreatedLabels: [],
sourcePRLabels: [],
dryRun: false,
targetBranches: [],
targetBranchChoices: [
Expand All @@ -36,11 +36,11 @@ describe('runWithOptions', () => {
{ name: '5.5' },
{ name: '5.4' },
],
commitsCount: 10,
maxNumber: 10,
editor: 'code',
fork: true,
gitHostname: 'github.com',
labels: [],
targetPRLabels: [],
mainline: undefined,
multiple: false,
multipleBranches: false,
Expand Down
4 changes: 2 additions & 2 deletions src/runWithOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BackportOptions } from './options/options';
import { HandledError } from './services/HandledError';
import { logger, consoleLog } from './services/logger';
import { sequentially } from './services/sequentially';
import { cherrypickAndCreatePullRequest } from './ui/cherrypickAndCreatePullRequest';
import { cherrypickAndCreateTargetPullRequest } from './ui/cherrypickAndCreateTargetPullRequest';
import { getTargetBranches } from './ui/getBranches';
import { getCommits } from './ui/getCommits';
import { maybeSetupRepo } from './ui/maybeSetupRepo';
Expand All @@ -21,7 +21,7 @@ export async function runWithOptions(options: BackportOptions) {
await sequentially(targetBranches, async (targetBranch) => {
logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
try {
await cherrypickAndCreatePullRequest({
await cherrypickAndCreateTargetPullRequest({
options,
commits,
targetBranch,
Expand Down
Loading