Skip to content

Commit

Permalink
Refactor config options (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Jun 20, 2020
1 parent 00edf3a commit bb61438
Show file tree
Hide file tree
Showing 21 changed files with 290 additions and 215 deletions.
98 changes: 88 additions & 10 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Config:

List of target branches the user can select interactively. 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: `--branch 6.1 --branch 6.0`
CLI: `target-branch-choice <branch>`

Config:

Expand All @@ -117,13 +117,15 @@ Config:

Default: `false`

CLI: `--all`
CLI: `--all`, `-a`

#### `branchLabelMapping`

Pre-select target branch choices based on the source PR labels.

Example:
CLI: N/A

Config:

```json
{
Expand Down Expand Up @@ -211,6 +213,22 @@ When backporting a merge commit the parent id must be specified. This is directl
- Defaults to 1 when no parent id is given: `backport --mainline`
- Specifying parent id: `backport --mainline 2`

#### maxNumber

Number of commits that will be listed for the user to choose from.

Default: 10

CLI: `--max-number <number>`, `--number <number>`, `-n <number>`

Config:

```json
{
"maxNumber": 20
}
```

#### `multipleCommits`

`true`: you will be able to select multiple commits to backport. You will use `<space>` to select, and `<enter>` to confirm you selection.
Expand All @@ -227,17 +245,31 @@ Default: `false`

Default: `true`

#### path

Only list commits touching files under the specified path

CLI: `--path <path>`, `-p <path>`

Config:

```json
{
"path": "my/folder"
}
```

#### `prTitle`

Pull request title pattern.
Title for the target pull request
Template values:

- `{targetBranch}`: Branch the backport PR will be targeting
- `{commitMessages}`: Multiple commits will be concatenated and separated by pipes (`|`).
- `{commitMessages}`: Message of backported commit. For multiple commits the messages will be separated by pipes (`|`).

Default: `"[{targetBranch}] {commitMessages}"`

CLI: `--pr-title "{commitMessages} backport for {targetBranch}"`
CLI: `--pr-title "<title>"`, `--title "<title>"`

Config:

Expand All @@ -249,15 +281,15 @@ Config:

#### `prDescription`

Text that will be appended to the pull request description.
Text that will be appended to the description of the target pull request

For people who often need to add the same description to PRs they can create a bash alias:

```sh
alias backport-skip-ci='backport --prDescription "[skip-ci]"'
```

CLI: `--pr-description "skip-ci"`
CLI: `--pr-description "<text>"`, `--description "<text>"`

Config:

Expand All @@ -267,6 +299,38 @@ Config:
}
```

#### `prFilter`

Filter source pull requests by any [Github query](https://help.github.com/en/github/searching-for-information-on-github/understanding-the-search-syntax). Text with whitespace [must contain escaped quotes](https://help.github.com/en/github/searching-for-information-on-github/understanding-the-search-syntax#use-quotation-marks-for-queries-with-whitespace).

CLI: `--pr-filter "<query>"`

Config:

```json
{
"prFilter": "label: \"Backport Needed\""
}
```

#### `pullNumber`

Backport a pull request by specifying its number

CLI: `--pull-number "<number>"`, `--pr "<number>"`

#### `resetAuthor`

Change the author of the backported commit to the current user

CLI: `--reset-author`

#### `sha`

Backport a commit by specifying its commit sha

CLI: `--sha "<sha>"`, `--commit "<sha>"`

#### `sourceBranch`

By default the list of commits will be sourced from the repository's default branch (mostly "master"). Use `sourceBranch` to list and backport commits from other branches than the default.
Expand All @@ -287,7 +351,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 was-backported`
CLI: `--source-pr-labels <label>`

Config:

Expand All @@ -297,11 +361,25 @@ Config:
}
```

#### `targetBranches`

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>`

Config:

```json
{
"targetBranches": ["7.x", "7.7"]
}
```

#### `targetPRLabels`

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: `--labels backport --labels apm-team`
CLI: `--target-pr-labels <label>`, `-l <label>`

Config:

Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module.exports = {
setupFiles: ['./src/test/setupFiles/automatic-mocks.ts'],
preset: 'ts-jest',
testRegex: '(test|src)/.*test.ts$',

// exclude private tests that requires credentials and can therefore not run on CI for external contributors
modulePathIgnorePatterns: ['.*.private.test.ts$'],

moduleFileExtensions: ['ts', 'js', 'json'],
globals: {
'ts-jest': {
Expand Down
10 changes: 10 additions & 0 deletions jest.config.private.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require('./jest.config');

module.exports = {
...config,

// only include (private) tests that cannot run on CI because they require credentials and thus exclude external contributors
testRegex: ['.*.private.test.ts$'],
modulePathIgnorePatterns: [],
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"postinstall": "test -f ./dist/scripts/runPostinstall.js && node ./dist/scripts/runPostinstall.js || echo 'Dist folder missing'",
"prepublishOnly": "tsc --project ./tsconfig.prod.json",
"test": "jest",
"test-private": "jest --config ./jest.config.private.js",
"test-all": "yarn test && yarn test-private",
"start": "ts-node --transpile-only ./src/index.ts"
},
"lint-staged": {
Expand Down
2 changes: 0 additions & 2 deletions src/options/cliArgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('getOptionsFromCliArgs', () => {
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
maxNumber: 10,
multiple: false,
multipleBranches: true,
multipleCommits: false,
noVerify: true,
Expand Down Expand Up @@ -46,7 +45,6 @@ describe('getOptionsFromCliArgs', () => {
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
maxNumber: 10,
multiple: false,
multipleBranches: true,
multipleCommits: false,
noVerify: true,
Expand Down
Loading

0 comments on commit bb61438

Please sign in to comment.