Skip to content

Commit

Permalink
Merge 4a2acc3 into 87a37be
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Dec 14, 2021
2 parents 87a37be + 4a2acc3 commit 9f52ed0
Show file tree
Hide file tree
Showing 42 changed files with 535 additions and 287 deletions.
66 changes: 33 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,39 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config

Please note that dashes between the words are optional, for instance you can type `--targetBranch` or `--target-branch` both are valid options.

| Option | Shorthand notation | Description | Default | Type |
| ------------------- | -------------------- | ------------------------------------------------------ | -------------- | --------------- |
| --access-token | --accesstoken | Github access token | | `string` |
| --all | -a | Show commits from other than me | false | `boolean` |
| --author | | Filter commits by author | _Current user_ | `string` |
| --assignees | --assignee, --assign | Assign users to target pull request | | `Array<string>` |
| --auto-assign | | Assign current user to target pull request | false | `boolean` |
| --branch | --b | Target branch to backport to | | `string` |
| --ci | | Disable interactive prompts | false | `boolean` |
| --dry-run | | Perform backport without pushing to Github | false | `string` |
| --editor | | Editor (eg. `code`) to open and solve conflicts | nano | `string` |
| --fork | | Create backports in fork (true) or origin repo (false) | true | `boolean` |
| --git-hostname | | Hostname for Git | github.com | `string` |
| --mainline | | Parent id of merge commit | 1 | `number` |
| --max-number | --number, --n | Number of commits to choose from | 10 | `number` |
| --multiple | | Select multiple commits/branches | false | `boolean` |
| --multiple-branches | | Backport to multiple branches | true | `boolean` |
| --multiple-commits | | Backport multiple commits | false | `boolean` |
| --path | -p | Only list commits touching files under a specific path | | `string` |
| --pull-number | --pr | Pull request to backport | | `number` |
| --pr-description | --description | Pull request description suffix | | `string` |
| --pr-filter | | List commits from PRs filtered by a given query | | `string` |
| --pr-title | --title | Title of pull request | | `string` |
| --reset-author | | Set yourself as commit author | | `boolean` |
| --sha | | Sha of commit to backport | | `string` |
| --source-branch | | Specify a non-default branch to backport from | | `string` |
| --source-pr-labels | --sourcePRLabel | Labels added to the source PR | | `array<string>` |
| --target-pr-Labels | --labels, --label | Labels added to the target PR | | `array<string>` |
| --target-branches | --b, --targetBranch | Target branch(es) to backport to | | `array<string>` |
| --upstream | --up | Name of organization and repository | | `string` |
| --username | | Github username | | `string` |
| --help | | Show help | | |
| -v, --version | | Show version number | | |
| Option | Shorthand notation | Description | Default | Type |
| ------------------- | ------------------ | ------------------------------------------------------ | -------------- | --------------- |
| --access-token | | Github access token | | `string` |
| --all | -a | Show commits from other than me | false | `boolean` |
| --author | | Filter commits by author | _Current user_ | `string` |
| --assignee | --assign | Assign users to target pull request | | `Array<string>` |
| --auto-assign | | Assign current user to target pull request | false | `boolean` |
| --branch | -b | Target branch to backport to | | `string` |
| --ci | | Disable interactive prompts | false | `boolean` |
| --dry-run | | Perform backport without pushing to Github | false | `string` |
| --editor | | Editor (eg. `code`) to open and solve conflicts | nano | `string` |
| --fork | | Create backports in fork (true) or origin repo (false) | true | `boolean` |
| --git-hostname | | Hostname for Git | github.com | `string` |
| --mainline | | Parent id of merge commit | 1 | `number` |
| --max-number | --number, -n | Number of commits to choose from | 10 | `number` |
| --multiple | | Select multiple commits/branches | false | `boolean` |
| --multiple-branches | | Backport to multiple branches | true | `boolean` |
| --multiple-commits | | Backport multiple commits | false | `boolean` |
| --path | -p | Only list commits touching files under a specific path | | `string` |
| --pull-number | --pr | Pull request to backport | | `number` |
| --pr-description | --description | Pull request description suffix | | `string` |
| --pr-filter | | List commits from PRs filtered by a given query | | `string` |
| --pr-title | --title | Title of pull request | | `string` |
| --reset-author | | Set yourself as commit author | | `boolean` |
| --sha | | Sha of commit to backport | | `string` |
| --source-branch | | Specify a non-default branch to backport from | | `string` |
| --source-pr-label | | Labels added to the source PR | | `array<string>` |
| --target-pr-label | --label, -l | Labels added to the target PR | | `array<string>` |
| --target-branch | -b | Target branch(es) to backport to | | `array<string>` |
| --upstream | --up | Name of organization and repository | | `string` |
| --username | | Github username | | `string` |
| --help | | Show help | | |
| -v, --version | | Show version number | | |

The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/master/docs/configuration.md).

Expand Down
13 changes: 7 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Config:
```

## General configuration options

The following options can be used in both the global config, project config, and passed in through CLI.

#### `all`
Expand All @@ -126,7 +127,7 @@ CLI: `--all`, `-a`

Add assignees to the target pull request

CLI: `--assignees <username>`, `-assign <username>`
CLI: `--assignee <username>`, `--assign <username>`

Config:

Expand Down Expand Up @@ -276,7 +277,7 @@ Default: `false`

Default: `true`

#### path
#### commitPaths

Only list commits touching files under the specified path

Expand All @@ -286,7 +287,7 @@ Config:

```json
{
"path": "my/folder"
"commitPaths": ["my/folder"]
}
```

Expand Down Expand Up @@ -382,7 +383,7 @@ Config:

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

CLI: `--source-pr-labels <label>`
CLI: `--source-pr-label <label>`

Config:

Expand All @@ -396,7 +397,7 @@ Config:

Overrides `targetBranchChoices` so instead of displaying a prompt with target branches to choose from, the selected commit(s) will be backported directly to the branches defined in `targetBranches`

CLI: `--target-branches <branch>`, `--branch <branch>`, `-b <branch>`
CLI: `--target-branch <branch>`, `--branch <branch>`, `-b <branch>`

Config:

Expand All @@ -410,7 +411,7 @@ Config:

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

CLI: `--target-pr-labels <label>`, `-l <label>`
CLI: `--target-pr-label <label>`, `-l <label>`

Config:

Expand Down
14 changes: 1 addition & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,12 @@
},
"dependencies": {
"@octokit/rest": "^18.12.0",
"@types/lodash.difference": "^4.5.6",
"@types/lodash.intersection": "^4.4.6",
"axios": "^0.24.0",
"dedent": "^0.7.0",
"del": "^6.0.0",
"find-up": "^5.0.0",
"inquirer": "^8.2.0",
"lodash.difference": "^4.5.0",
"lodash.flatmap": "^4.5.0",
"lodash.intersection": "^4.4.0",
"lodash.isempty": "^4.4.0",
"lodash.isstring": "^4.0.1",
"lodash.uniq": "^4.5.0",
"lodash": "^4.17.21",
"make-dir": "^3.1.0",
"ora": "^5.4.1",
"safe-json-stringify": "^1.2.0",
Expand All @@ -85,10 +78,6 @@
"@types/inquirer": "^8.1.3",
"@types/jest": "^27.0.3",
"@types/lodash": "^4.14.178",
"@types/lodash.flatmap": "^4.5.6",
"@types/lodash.isempty": "^4.4.6",
"@types/lodash.isstring": "^4.0.6",
"@types/lodash.uniq": "^4.5.6",
"@types/node": "^16.11.12",
"@types/safe-json-stringify": "^1.1.2",
"@types/yargs": "^17.0.7",
Expand All @@ -106,7 +95,6 @@
"jest": "^27.4.4",
"jest-snapshot-serializer-ansi": "^1.0.0",
"lint-staged": "^12.1.2",
"lodash": "^4.17.21",
"nock": "^13.2.1",
"prettier": "^2.5.1",
"strip-ansi": "^6.0.1",
Expand Down
5 changes: 5 additions & 0 deletions src/__snapshots__/runWithOptions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Array [
"name": "1. Add 👻 (2e63475c) ",
"short": "2e63475c",
"value": Object {
"committedDate": "2021-12-24T00:00:00Z",
"existingTargetPullRequests": Array [],
"formattedMessage": "Add 👻 (2e63475c)",
"originalMessage": "Add 👻",
Expand All @@ -101,6 +102,7 @@ Array [
"name": "2. Add witch (#85) ",
"short": "#85 (f3b618b9)",
"value": Object {
"committedDate": "2021-12-23T00:00:00Z",
"existingTargetPullRequests": Array [],
"formattedMessage": "Add witch (#85)",
"originalMessage": "Add witch (#85)",
Expand All @@ -114,6 +116,7 @@ Array [
"name": "3. Add SF mention (#80) 6.3",
"short": "#80 (79cf1845)",
"value": Object {
"committedDate": "2021-12-22T00:00:00Z",
"existingTargetPullRequests": Array [
Object {
"branch": "6.3",
Expand All @@ -137,6 +140,7 @@ Array [
"name": "4. Add backport config (3827bbba) ",
"short": "3827bbba",
"value": Object {
"committedDate": "2021-12-21T00:00:00Z",
"existingTargetPullRequests": Array [],
"formattedMessage": "Add backport config (3827bbba)",
"originalMessage": "Add backport config",
Expand All @@ -150,6 +154,7 @@ Array [
"name": "5. Initial commit (5ea0da55) ",
"short": "5ea0da55",
"value": Object {
"committedDate": "2021-12-20T00:00:00Z",
"existingTargetPullRequests": Array [],
"formattedMessage": "Initial commit (5ea0da55)",
"originalMessage": "Initial commit",
Expand Down
2 changes: 1 addition & 1 deletion src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type ConfigOptions = Partial<{
multipleBranches: boolean;
multipleCommits: boolean;
noVerify: boolean;
path: string;
commitPaths: string[];
prDescription: string;
prFilter: string;
prTitle: string;
Expand Down
33 changes: 14 additions & 19 deletions src/options/cliArgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ describe('getOptionsFromCliArgs', () => {
upstream: 'elastic/kibana',
username: 'sqren',
mainline: 1,
assignees: [],
commitPaths: [],
});
});
});
Expand All @@ -50,29 +52,16 @@ describe('getOptionsFromCliArgs', () => {
describe('sourcePRLabels', () => {
it('should handle all variations', () => {
const argv = [
'--sourcePRLabels',
'label a',
'--sourcePrLabels',
'label b',
'--source-pr-labels',
'label c',
'--sourcePRLabel',
'label d',
'label a',
'--sourcePrLabel',
'label e',
'label b',
'--source-pr-label',
'label f',
'label c',
];

const res = getOptionsFromCliArgs(argv);
expect(res.sourcePRLabels).toEqual([
'label a',
'label b',
'label c',
'label d',
'label e',
'label f',
]);
expect(res.sourcePRLabels).toEqual(['label a', 'label b', 'label c']);
});
});

Expand All @@ -90,8 +79,14 @@ describe('getOptionsFromCliArgs', () => {
});

describe('assignees', () => {
it('should set assignees', () => {
const argv = ['--assignees', 'john'];
it('--assignee', () => {
const argv = ['--assignee', 'john'];
const res = getOptionsFromCliArgs(argv);
expect(res.assignees).toEqual(['john']);
});

it('--assign', () => {
const argv = ['--assign', 'john'];
const res = getOptionsFromCliArgs(argv);
expect(res.assignees).toEqual(['john']);
});
Expand Down
39 changes: 28 additions & 11 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export function getOptionsFromCliArgs(
type: 'string',
})

.option('assignees', {
.option('assignee', {
description: 'Add assignees to the target pull request',
alias: ['assignee', 'assign'],
alias: 'assign',
type: 'array',
string: true,
conflicts: ['autoAssign'],
Expand Down Expand Up @@ -159,7 +159,8 @@ export function getOptionsFromCliArgs(
.option('path', {
description: 'Only list commits touching files under the specified path',
alias: 'p',
type: 'string',
type: 'array',
string: true,
})

.option('prTitle', {
Expand Down Expand Up @@ -204,30 +205,29 @@ export function getOptionsFromCliArgs(
type: 'string',
})

.option('sourcePRLabels', {
.option('sourcePRLabel', {
description: 'Add labels to the source (original) PR',
alias: ['sourcePRLabel', 'sourcePrLabel', 'sourcePrLabels'],
alias: 'sourcePrLabel',
type: 'array',
string: true,
})

.option('targetBranches', {
.option('targetBranch', {
description: 'Branch(es) to backport to',
alias: ['targetBranch', 'branch', 'b'],
alias: ['branch', 'b'],
type: 'array',
string: true, // ensure `6.0` is not coerced to `6`
})

.option('targetBranchChoices', {
.option('targetBranchChoice', {
description: 'List branches to backport to',
alias: 'targetBranchChoice',
type: 'array',
string: true,
})

.option('targetPRLabels', {
.option('targetPRLabel', {
description: 'Add labels to the target (backport) PR',
alias: ['labels', 'label', 'l'],
alias: ['label', 'l'],
type: 'array',
string: true,
})
Expand Down Expand Up @@ -285,6 +285,15 @@ export function getOptionsFromCliArgs(
multipleBranches,
multipleCommits,
noVerify,

// array types (should be renamed to plural form)
assignee,
path,
sourcePRLabel,
targetBranch,
targetBranchChoice,
targetPRLabel,

...restOptions
} = yargsInstance.parseSync();

Expand All @@ -295,6 +304,14 @@ export function getOptionsFromCliArgs(
multipleBranches: multiple ?? multipleBranches,
multipleCommits: multiple ?? multipleCommits,

// rename array types to plural
assignees: assignee ?? [],
commitPaths: path ?? [],
sourcePRLabels: sourcePRLabel,
targetBranchChoices: targetBranchChoice,
targetBranches: targetBranch,
targetPRLabels: targetPRLabel,

// `verify` is a cli-only flag to flip the default of `no-verify`
noVerify: verify ?? noVerify,
});
Expand Down
2 changes: 1 addition & 1 deletion src/options/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getProjectConfig } from './projectConfig';

export const defaultConfigOptions = {
all: false,
assignees: [],
assignees: [] as Array<string>,
autoAssign: false,
autoMerge: false,
autoMergeMethod: 'merge',
Expand Down
1 change: 1 addition & 0 deletions src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('getOptions', () => {
gitHostname: 'github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'http://localhost/graphql',
commitPaths: [],
mainline: 1,
maxNumber: 10,
multipleBranches: true,
Expand Down
Loading

0 comments on commit 9f52ed0

Please sign in to comment.