Skip to content

Commit

Permalink
Add options githubApiBaseUrlV3 and githubApiBaseUrlV4 and remove …
Browse files Browse the repository at this point in the history
…`apiHostname`
  • Loading branch information
sorenlouv committed Mar 28, 2020
1 parent c068f7c commit 3cbc336
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 179 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,31 @@ The above commands will start an interactive prompt. You can use the `arrow keys

### CLI arguments

| Option | Description | Default | Type |
| ---------------- | ------------------------------------------------------ | -------------- | ------- |
| --accesstoken | Github access token | | string |
| --all | Show commits from other than me | false | boolean |
| --api-hostname | Hostname for the Github API | api.github.com | string |
| --author | Filter commits by author | _Current user_ | string |
| --branch | Branch to backport to | | string |
| --commits-count | Number of commits to choose from | 10 | number |
| --editor | Editor (eg. `code`) to open and solve conflicts | | string |
| --fork | Create backports in fork (true) or origin repo (false) | true | boolean |
| --git-hostname | Hostname for Git remotes | github.com | string |
| --labels | Pull request labels | | string |
| --multiple | Select multiple commits/branches | false | boolean |
| --path | Only list commits touching files under a specific path | | string |
| --pr-description | Pull request description suffix | | string |
| --pr-title | Pull request title pattern | | string |
| --pr | Pull request to backport | | number |
| --reset-author | Set yourself as commit author | | boolean |
| --sha | Sha of commit to backport | | string |
| --sourceBranch | Backport commits from a non-default branch | | string |
| --upstream | Name of organization and repository | | string |
| --username | Github username | | string |
| --help | Show help | | |
| -v, --version | Show version number | | |
| Option | Description | Default | Type |
| ------------------------ | ------------------------------------------------------ | ------------------------------ | ------- |
| --accesstoken | Github access token | | string |
| --all | Show commits from other than me | false | boolean |
| --author | Filter commits by author | _Current user_ | string |
| --branch | Branch to backport to | | string |
| --commits-count | Number of commits to choose from | 10 | number |
| --editor | Editor (eg. `code`) to open and solve conflicts | | string |
| --fork | Create backports in fork (true) or origin repo (false) | true | boolean |
| --git-hostname | Hostname for Git remotes | github.com | string |
| --github-api-base-url-v3 | Base url for Github's Rest (v3) API | https://api.github.com | string |
| --github-api-base-url-v4 | Base url for Github's GraphQL (v4) API | https://api.github.com/graphql | string |
| --labels | Pull request labels | | string |
| --multiple | Select multiple commits/branches | false | boolean |
| --path | Only list commits touching files under a specific path | | string |
| --pr-description | Pull request description suffix | | string |
| --pr-title | Pull request title pattern | | string |
| --pr | Pull request to backport | | number |
| --reset-author | Set yourself as commit author | | boolean |
| --sha | Sha of commit to backport | | string |
| --sourceBranch | Backport commits from a non-default branch | | string |
| --upstream | Name of organization and repository | | string |
| --username | Github username | | string |
| --help | Show help | | |
| -v, --version | Show version number | | |

All of the CLI arguments can also be configured via the [configuration options](https://github.com/sqren/backport/blob/master/docs/configuration.md) in the config files.

Expand Down
77 changes: 57 additions & 20 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Please select the necessary access scopes:
**For public and private repos (recommended)**
![image](https://user-images.githubusercontent.com/209966/67081197-fe93d380-f196-11e9-8891-c6ba8c4686a4.png)


**For public repos only**
![image](https://user-images.githubusercontent.com/209966/67081207-018ec400-f197-11e9-86aa-4ae4a003fcbd.png)

Expand Down Expand Up @@ -66,18 +65,30 @@ Example:

Github organization/user and repository name separated with forward slash.

Example: "elastic/kibana"

CLI: `--upstream elastic/kibana`

Config:

```json
{
"upsteam": "elastic/kibana"
}
```

#### `branches` **required**

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.

Example: `[{ "name": "6.x", "checked": true }, "6.3", "6.2", "6.1", "6.0"]`

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

Config:

```json
{
"branches": [{ "name": "6.x", "checked": true }, "6.3", "6.2", "6.1", "6.0"]
}
```

#### `all`

`true`: list all commits
Expand All @@ -98,6 +109,14 @@ Default: `true`

CLI: `--fork=false`

Config:

```json
{
"fork": false
}
```

#### `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 @@ -118,20 +137,24 @@ Default: `true`

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

Example: `["backport", "apm-team"]`
CLI: `--labels backport --labels apm-team`

Config:

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

#### `prTitle`

Pull request title pattern. You can access the base branch (`{baseBranch}`) and commit message (`{commitMessages}`) via the special accessors in quotes.
Multiple commits will be concatenated and separated by pipes.

Example: `"{commitMessages} backport for {baseBranch}"`

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

CLI: `--prTitle "My PR Title"`
CLI: `--pr-title "{commitMessages} backport for {baseBranch}"`

#### `prDescription`

Expand All @@ -144,30 +167,44 @@ For people who often need to add the same description to PRs they can create a b
alias backport-skip-ci='backport --prDescription "[skip-ci]"'
```

CLI: `--prDescription "skip-ci"`
CLI: `--pr-description "skip-ci"`

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

CLI: `--sourceBranch 7.x`
Default: master (unless the default branch on Github is changed)

CLI: `--source-branch 7.x`

Config:

```json
{
"sourceBranch": "7.x"
}
```

#### `gitHostname`

Hostname for Github.

Example: `github.my-private-company.com`

Default: `github.com`

CLI: `--gitHostname "github.my-private-company.com"`
CLI: `--git-hostname "github.my-private-company.com"`

#### `githubApiBaseUrlV3`

Base url for Github's Rest (v3) API

Default: `https://api.github.com`

#### `apiHostname`
CLI: `--github-api-base-url-v3 "https://api.github.my-private-company.com"`

Hostname for the Github API.
#### `githubApiBaseUrlV4`

Example: `api.github.my-private-company.com`
Base url for Github's Rest (v3) API

Default: `api.github.com`
Default: `https://api.github.com/graphql`

CLI: `--apiHostname "api.github.my-private-company.com"`
CLI: `--github-api-base-url-v4 "https://github-enterprise.acme-inc.com/api"`
10 changes: 6 additions & 4 deletions src/options/cliArgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ describe('getOptionsFromCliArgs', () => {
const configOptions = {
accessToken: 'myAccessToken',
all: false,
apiHostname: 'api.github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
backportCreatedLabels: [],
branchChoices: [],
fork: true,
Expand Down Expand Up @@ -37,7 +38,8 @@ describe('getOptionsFromCliArgs', () => {
expect(res).toEqual({
accessToken: 'myAccessToken',
all: true,
apiHostname: 'api.github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
backportCreatedLabels: [],
branches: ['6.0', '6.1'],
branchChoices: [],
Expand All @@ -61,15 +63,15 @@ describe('getOptionsFromCliArgs', () => {
const argv = [
'--access-token',
'my access token',
'--apiHostname',
'--githubApiBaseUrlV3',
'my api hostname',
];

const res = getOptionsFromCliArgs(configOptions, argv);

expect(res.accessToken).toEqual('my access token');
expect('access-token' in res).toEqual(false);
expect(res.apiHostname).toEqual('my api hostname');
expect(res.githubApiBaseUrlV3).toEqual('my api hostname');
expect('api-hostname' in res).toEqual(false);
});

Expand Down
15 changes: 10 additions & 5 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ export function getOptionsFromCliArgs(
description: 'List all commits',
type: 'boolean',
})
.option('apiHostname', {
default: configOptions.apiHostname,
description: 'Hostname for the Github API',
type: 'string',
})
.option('author', {
default: configOptions.author,
description: 'Show commits by specific author',
Expand Down Expand Up @@ -65,6 +60,16 @@ export function getOptionsFromCliArgs(
description: 'Hostname for Github',
type: 'string',
})
.option('githubApiBaseUrlV3', {
default: configOptions.githubApiBaseUrlV3,
description: `Base url for Github's REST (v3) API`,
type: 'string',
})
.option('githubApiBaseUrlV4', {
default: configOptions.githubApiBaseUrlV4,
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',
Expand Down
3 changes: 2 additions & 1 deletion src/options/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('getOptionsFromConfigFiles', () => {
expect(res).toEqual({
accessToken: 'myAccessToken',
all: false,
apiHostname: 'api.github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
backportCreatedLabels: [],
branchChoices: [
{ checked: false, name: '6.0' },
Expand Down
3 changes: 2 additions & 1 deletion src/options/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export async function getOptionsFromConfigFiles() {
labels: [] as string[],
prTitle: '[{baseBranch}] {commitMessages}',
gitHostname: 'github.com',
apiHostname: 'api.github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
branchChoices: getBranchesAsObjects(branches),
...combinedConfig,
};
Expand Down
6 changes: 4 additions & 2 deletions src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ describe('getOptions', () => {
expect(options).toEqual({
accessToken: 'myAccessToken',
all: false,
apiHostname: 'api.github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
author: 'sqren',
backportCreatedLabels: [],
branchChoices: [
Expand Down Expand Up @@ -79,7 +80,8 @@ describe('validateRequiredOptions', () => {
const validOptions: OptionsFromCliArgs = {
accessToken: 'myAccessToken',
all: false,
apiHostname: 'api.github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
author: undefined,
backportCreatedLabels: [],
branchChoices: [],
Expand Down
7 changes: 4 additions & 3 deletions src/runWithOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('runWithOptions', () => {
const options: BackportOptions = {
accessToken: 'myAccessToken',
all: false,
apiHostname: 'api.github.com',
githubApiBaseUrlV3: 'https://api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
author: 'sqren',
backportCreatedLabels: [],
branches: [],
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('runWithOptions', () => {
repoName: 'kibana',
repoOwner: 'elastic',
username: 'sqren',
apiHostname: 'api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
})
);
});
Expand All @@ -119,7 +120,7 @@ describe('runWithOptions', () => {
expect.objectContaining({
repoName: 'kibana',
repoOwner: 'elastic',
apiHostname: 'api.github.com',
githubApiBaseUrlV4: 'https://api.github.com/graphql',
}),
{
base: '6.x',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

exports[`fetchCommitsByAuthor when commit has an associated pull request should call with correct args to fetch author id 1`] = `
Array [
"https://api.github.com/graphql",
Object {
"accessToken": "myAccessToken",
"apiHostname": "api.github.com",
"query": "
query getIdByLogin($login: String!) {
user(login: $login) {
Expand All @@ -16,14 +15,19 @@ Array [
"login": "sqren",
},
},
Object {
"headers": Object {
"Authorization": "bearer myAccessToken",
"Content-Type": "application/json",
},
},
]
`;

exports[`fetchCommitsByAuthor when commit has an associated pull request should call with correct args to fetch commits 1`] = `
Array [
"https://api.github.com/graphql",
Object {
"accessToken": "myAccessToken",
"apiHostname": "api.github.com",
"query": "
query getCommitsByAuthorQuery(
$repoOwner: String!
Expand Down Expand Up @@ -104,5 +108,11 @@ Array [
"sourceBranch": undefined,
},
},
Object {
"headers": Object {
"Authorization": "bearer myAccessToken",
"Content-Type": "application/json",
},
},
]
`;
Loading

0 comments on commit 3cbc336

Please sign in to comment.