backport 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -42
- package/dist/entrypoint.cli.js +2 -0
- package/dist/entrypoint.module.d.ts +16 -4
- package/dist/entrypoint.module.js +41 -13
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +33 -0
- package/dist/main.js +1 -2
- package/dist/options/ConfigOptions.d.ts +15 -6
- package/dist/options/cliArgs.d.ts +33 -34
- package/dist/options/cliArgs.js +19 -19
- package/dist/options/cliArgs.test.js +8 -5
- package/dist/options/config/config.d.ts +27 -52
- package/dist/options/config/config.js +2 -36
- package/dist/options/config/config.test.js +10 -27
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.js +1 -4
- package/dist/options/config/globalConfig.test.js +0 -2
- package/dist/options/config/projectConfig.test.js +51 -14
- package/dist/options/config/readConfigFile.d.ts +51 -0
- package/dist/options/config/readConfigFile.js +28 -2
- package/dist/options/options.d.ts +52 -33
- package/dist/options/options.js +98 -7
- package/dist/options/options.test.js +180 -73
- package/dist/options/parseRequiredOptions.d.ts +3 -3
- package/dist/options/parseRequiredOptions.js +2 -4
- package/dist/options/parseRequiredOptions.test.js +6 -11
- package/dist/runSequentially.test.js +35 -78
- package/dist/services/git.d.ts +5 -2
- package/dist/services/git.js +11 -10
- package/dist/services/git.test.js +12 -9
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
- package/dist/services/github/v3/createPullRequest.js +10 -13
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +78 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +5 -6
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +15 -15
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
- package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
- package/dist/test/inquirer.private.test.js +42 -34
- package/dist/test/integration/integration.private.test.js +104 -95
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +4 -4
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -29
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +67 -28
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +6 -3
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getTargetBranches.d.ts +2 -1
- package/dist/ui/getTargetBranches.js +17 -1
- package/dist/ui/maybeSetupRepo.js +4 -3
- package/dist/ui/maybeSetupRepo.test.js +49 -3
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +9 -8
- package/yarn.lock +98 -77
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ A simple CLI tool that automates the process of backporting commits on a GitHub
|
|
|
19
19
|
npm install -g backport
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
After installation you should
|
|
22
|
+
After installation you should add an access token to the [global config](https://github.com/sqren/backport/blob/master/docs/configuration.md#global-config-backportconfigjson) in `~/.backport/config.json`. See the [documentation](https://github.com/sqren/backport/blob/master/docs/configuration.md#accesstoken-required) for how the access token is generated.
|
|
23
23
|
|
|
24
24
|
## Quick start
|
|
25
25
|
|
|
@@ -28,11 +28,15 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
|
|
|
28
28
|
```js
|
|
29
29
|
// .backportrc.json
|
|
30
30
|
{
|
|
31
|
-
"
|
|
31
|
+
"repoOwner": "elastic",
|
|
32
|
+
"repoName": "kibana",
|
|
33
|
+
|
|
34
|
+
// the branches available to backport to
|
|
32
35
|
"targetBranchChoices": ["main", "6.3", "6.2", "6.1", "6.0"],
|
|
36
|
+
|
|
37
|
+
// Automatically detect which branches a pull request should be backported to based on the pull request labels.
|
|
33
38
|
"branchLabelMapping": {
|
|
34
|
-
"^
|
|
35
|
-
"^v(\\d+).(\\d+).\\d+$": "$1.$2"
|
|
39
|
+
"^backport-to-(.+)$": "$1"
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
```
|
|
@@ -57,47 +61,159 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
|
|
|
57
61
|
|
|
58
62
|
### CLI options
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
| --
|
|
65
|
-
| --
|
|
66
|
-
| --
|
|
67
|
-
| --
|
|
68
|
-
| --
|
|
69
|
-
| --
|
|
70
|
-
| --
|
|
71
|
-
| --
|
|
72
|
-
| --
|
|
73
|
-
| --
|
|
74
|
-
| --
|
|
75
|
-
| --
|
|
76
|
-
| --
|
|
77
|
-
| --
|
|
78
|
-
| --
|
|
79
|
-
| --
|
|
80
|
-
| --
|
|
81
|
-
| --
|
|
82
|
-
| --
|
|
83
|
-
| --
|
|
84
|
-
| --
|
|
85
|
-
| --
|
|
86
|
-
| --
|
|
87
|
-
| --reset-author | | Set yourself as commit author | |
|
|
88
|
-
| --reviewer | | Add reviewer to the target PR | |
|
|
89
|
-
| --sha | | Sha of commit to backport | |
|
|
90
|
-
| --source-branch | | Specify a non-default branch to backport from | |
|
|
91
|
-
| --source-pr-label | | Labels added to the source PR | |
|
|
92
|
-
| --target-
|
|
93
|
-
| --target-
|
|
94
|
-
| --
|
|
95
|
-
| --
|
|
96
|
-
| --help | | Show help | | |
|
|
97
|
-
| -v, --version | | Show version number | | |
|
|
64
|
+
| Option | Shorthand notation | Description | Default |
|
|
65
|
+
| ------------------- | ------------------ | ------------------------------------------------------------- | -------------- |
|
|
66
|
+
| --access-token | | Github access token | |
|
|
67
|
+
| --all | -a | Show commits from any author | false |
|
|
68
|
+
| --assignee | --assign | Assign users to the target PR | |
|
|
69
|
+
| --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
|
|
70
|
+
| --auto-assign | | Assign current user to the target PR | false |
|
|
71
|
+
| --branch | -b | Target branch to backport to | |
|
|
72
|
+
| --ci | | Disable interactive prompts | false |
|
|
73
|
+
| --dry-run | | Perform backport without pushing to Github | false |
|
|
74
|
+
| --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
|
|
75
|
+
| --fork | | Create backports in fork repo | true |
|
|
76
|
+
| --git-hostname | | Hostname for Git | github.com |
|
|
77
|
+
| --mainline | | Parent id of merge commit | 1 |
|
|
78
|
+
| --max-number | --number, -n | Number of commits to choose from | 10 |
|
|
79
|
+
| --multiple | | Multi-select for commits and branches | false |
|
|
80
|
+
| --multiple-branches | | Multi-select for branches | true |
|
|
81
|
+
| --multiple-commits | | Multi-select for commits | false |
|
|
82
|
+
| --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false |
|
|
83
|
+
| --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
|
|
84
|
+
| --path | -p | Filter commits by path | |
|
|
85
|
+
| --pr-description | --description | Pull request description suffix | |
|
|
86
|
+
| --pr-filter | | Find PRs using [Github's search syntax][2] | |
|
|
87
|
+
| --pr-title | --title | Title of pull request | |
|
|
88
|
+
| --pull-number | --pr | Backport pull request by number | |
|
|
89
|
+
| --repo-name | | Name of repository | |
|
|
90
|
+
| --repo-owner | | Owner of repository | |
|
|
91
|
+
| --reset-author | | Set yourself as commit author | |
|
|
92
|
+
| --reviewer | | Add reviewer to the target PR | |
|
|
93
|
+
| --sha | | Sha of commit to backport | |
|
|
94
|
+
| --source-branch | | Specify a non-default branch to backport from | |
|
|
95
|
+
| --source-pr-label | | Labels added to the source PR | |
|
|
96
|
+
| --target-branch | -b | Target branch(es) to backport to | |
|
|
97
|
+
| --target-pr-label | --label, -l | Labels added to the target PR | |
|
|
98
|
+
| --help | | Show help | |
|
|
99
|
+
| -v, --version | | Show version number | |
|
|
98
100
|
|
|
99
101
|
The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/master/docs/configuration.md).
|
|
100
102
|
|
|
103
|
+
### Node module
|
|
104
|
+
|
|
105
|
+
`backport` can be imported as a Node module and interacted with programatically.
|
|
106
|
+
|
|
107
|
+
#### `backportRun`
|
|
108
|
+
|
|
109
|
+
Backport a commit programatically. Commits can be selected via `pullNumber` or `sha`.
|
|
110
|
+
|
|
111
|
+
##### Arguments:
|
|
112
|
+
|
|
113
|
+
All of the options listed on [configuration.md](https://github.com/sqren/backport/blob/main/docs/configuration.md) are valid. The most common options are:
|
|
114
|
+
|
|
115
|
+
`accessToken` _string_ **(Required)**
|
|
116
|
+
Github access token to authenticate the request
|
|
117
|
+
|
|
118
|
+
`repoName` _string_ **(Required)**
|
|
119
|
+
Name of repository
|
|
120
|
+
|
|
121
|
+
`repoOwner` _string_ **(Required)**
|
|
122
|
+
Owner of repository (organisation or username)
|
|
123
|
+
|
|
124
|
+
`pullNumber` _number_
|
|
125
|
+
Filter commits by pull request number
|
|
126
|
+
|
|
127
|
+
`sha` _string_
|
|
128
|
+
Filter commits by commit sha
|
|
129
|
+
|
|
130
|
+
`ci` _boolean_
|
|
131
|
+
Enabling this will disable the interactive prompts
|
|
132
|
+
|
|
133
|
+
##### Example
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { backportRun } from 'backport';
|
|
137
|
+
|
|
138
|
+
const result = await backportRun({
|
|
139
|
+
accessToken: 'abc',
|
|
140
|
+
repoName: 'kibana',
|
|
141
|
+
repoOwner: 'elastic',
|
|
142
|
+
pullNumber: 121633,
|
|
143
|
+
ci: true,
|
|
144
|
+
targetPRLabels: ['backport'],
|
|
145
|
+
autoMerge: true,
|
|
146
|
+
autoMergeMethod: 'squash',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
console.log(result);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### `getCommits`
|
|
153
|
+
|
|
154
|
+
Retrieve information about commits and whether they are backported
|
|
155
|
+
|
|
156
|
+
##### Arguments:
|
|
157
|
+
|
|
158
|
+
`accessToken` _string_ **(Required)**
|
|
159
|
+
Github access token to authenticate the request
|
|
160
|
+
|
|
161
|
+
`repoName` _string_ **(Required)**
|
|
162
|
+
Name of repository
|
|
163
|
+
|
|
164
|
+
`repoOwner` _string_ **(Required)**
|
|
165
|
+
Owner of repository (organisation or username)
|
|
166
|
+
|
|
167
|
+
`author` _string_
|
|
168
|
+
Filter commits by Github user
|
|
169
|
+
|
|
170
|
+
`pullNumber` _number_
|
|
171
|
+
Filter commits by pull request number
|
|
172
|
+
|
|
173
|
+
`sha` _string_
|
|
174
|
+
Filter commits by commit sha
|
|
175
|
+
|
|
176
|
+
`sourceBranch` _string_
|
|
177
|
+
The branch to display commits from. Defaults to the default branch (normally "main" or "master")
|
|
178
|
+
|
|
179
|
+
##### Example
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { getCommits } from 'backport';
|
|
183
|
+
|
|
184
|
+
const commits = await getCommits({
|
|
185
|
+
accessToken: 'abc',
|
|
186
|
+
repoName: 'kibana',
|
|
187
|
+
repoOwner: 'elastic',
|
|
188
|
+
pullNumber: 121633,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
console.log(commits);
|
|
192
|
+
|
|
193
|
+
/*
|
|
194
|
+
[{
|
|
195
|
+
committedDate: '2021-12-20T14:20:16Z',
|
|
196
|
+
sourceBranch: 'main',
|
|
197
|
+
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
198
|
+
originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
199
|
+
pullNumber: 121633,
|
|
200
|
+
pullUrl: 'https://github.com/elastic/kibana/pull/121633',
|
|
201
|
+
expectedTargetPullRequests: [
|
|
202
|
+
{
|
|
203
|
+
url: 'https://github.com/elastic/kibana/pull/121643',
|
|
204
|
+
number: 121643,
|
|
205
|
+
branch: '8.0',
|
|
206
|
+
state: 'MERGED'
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}]
|
|
210
|
+
*/
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Github Action (beta)
|
|
214
|
+
|
|
215
|
+
A [Github Action](https://github.com/elastic/kibana-github-actions/tree/main/backport) for automatically backporting pull requests.
|
|
216
|
+
|
|
101
217
|
## What is backporting?
|
|
102
218
|
|
|
103
219
|
> Backporting is the action of taking parts from a newer version of a software system [..] and porting them to an older version of the same software. It forms part of the maintenance step in a software development process, and it is commonly used for fixing security issues in older versions of the software and also for providing new features to older versions.
|
package/dist/entrypoint.cli.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const main_1 = require("./main");
|
|
5
|
+
const logger_1 = require("./services/logger");
|
|
5
6
|
const args = process.argv.slice(2);
|
|
7
|
+
(0, logger_1.initLogger)();
|
|
6
8
|
// this is the entrypoint when running from command line
|
|
7
9
|
(0, main_1.main)(args);
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { ConfigFileOptions } from './options/ConfigOptions';
|
|
2
|
-
|
|
2
|
+
import { ValidConfigOptions } from './options/options';
|
|
3
3
|
export { BackportResponse } from './main';
|
|
4
4
|
export { ConfigFileOptions } from './options/ConfigOptions';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
5
|
+
export { Commit } from './services/sourceCommit/parseSourceCommit';
|
|
6
|
+
export { fetchProjectConfig } from './services/github/v4/fetchProjectConfig';
|
|
7
|
+
export declare function backportRun(options: ConfigFileOptions, args?: string[]): Promise<import("./main").BackportResponse>;
|
|
8
|
+
export declare function getCommits(options: {
|
|
9
|
+
accessToken: string;
|
|
10
|
+
repoName: string;
|
|
11
|
+
repoOwner: string;
|
|
12
|
+
author?: string;
|
|
13
|
+
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
14
|
+
githubApiBaseUrlV4?: string;
|
|
15
|
+
pullNumber?: number;
|
|
16
|
+
sha?: string;
|
|
17
|
+
skipRemoteConfig?: boolean;
|
|
18
|
+
sourceBranch?: string;
|
|
19
|
+
}): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
|
|
@@ -1,23 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getCommits = exports.backportRun = exports.fetchProjectConfig = void 0;
|
|
4
4
|
const main_1 = require("./main");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const fetchCommitByPullNumber_1 = require("./services/github/v4/fetchCommits/fetchCommitByPullNumber");
|
|
6
|
+
const fetchCommitBySha_1 = require("./services/github/v4/fetchCommits/fetchCommitBySha");
|
|
7
|
+
const fetchCommitsByAuthor_1 = require("./services/github/v4/fetchCommits/fetchCommitsByAuthor");
|
|
8
|
+
const getOptionsFromGithub_1 = require("./services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
|
|
9
|
+
const logger_1 = require("./services/logger");
|
|
10
|
+
(0, logger_1.initLogger)();
|
|
11
|
+
var fetchProjectConfig_1 = require("./services/github/v4/fetchProjectConfig");
|
|
12
|
+
Object.defineProperty(exports, "fetchProjectConfig", { enumerable: true, get: function () { return fetchProjectConfig_1.fetchProjectConfig; } });
|
|
13
|
+
function backportRun(options,
|
|
14
|
+
// cli args will not automatically be forwarded when it is consumed as a module
|
|
8
15
|
// It is simple to forward args manually via `process.argv`:
|
|
9
16
|
//
|
|
10
|
-
// import {
|
|
17
|
+
// import { backportRun } from `backport
|
|
11
18
|
// const args = process.argv.slice(2);
|
|
12
|
-
//
|
|
19
|
+
// backportRun(options, args)
|
|
13
20
|
//
|
|
14
21
|
args = []) {
|
|
15
22
|
return (0, main_1.main)(args, options);
|
|
16
23
|
}
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
exports.backportRun = backportRun;
|
|
25
|
+
async function getCommits(options) {
|
|
26
|
+
const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(options);
|
|
27
|
+
if (options.pullNumber) {
|
|
28
|
+
return [
|
|
29
|
+
await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
30
|
+
...optionsFromGithub,
|
|
31
|
+
...options,
|
|
32
|
+
pullNumber: options.pullNumber,
|
|
33
|
+
}),
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
if (options.sha) {
|
|
37
|
+
return [
|
|
38
|
+
await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
39
|
+
...optionsFromGithub,
|
|
40
|
+
...options,
|
|
41
|
+
sha: options.sha,
|
|
42
|
+
}),
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
46
|
+
...optionsFromGithub,
|
|
47
|
+
...options,
|
|
48
|
+
author: options.author ?? null,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.getCommits = getCommits;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const entrypoint_module_1 = require("./entrypoint.module");
|
|
4
|
+
const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
|
|
5
|
+
describe('entrypoint.module', () => {
|
|
6
|
+
it('getCommits', async () => {
|
|
7
|
+
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
8
|
+
const commits = await (0, entrypoint_module_1.getCommits)({
|
|
9
|
+
accessToken: accessToken,
|
|
10
|
+
repoName: 'kibana',
|
|
11
|
+
repoOwner: 'elastic',
|
|
12
|
+
pullNumber: 121633,
|
|
13
|
+
});
|
|
14
|
+
expect(commits).toEqual([
|
|
15
|
+
{
|
|
16
|
+
committedDate: '2021-12-20T14:20:16Z',
|
|
17
|
+
expectedTargetPullRequests: [
|
|
18
|
+
{
|
|
19
|
+
branch: '8.0',
|
|
20
|
+
number: 121643,
|
|
21
|
+
state: 'MERGED',
|
|
22
|
+
url: 'https://github.com/elastic/kibana/pull/121643',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
26
|
+
pullNumber: 121633,
|
|
27
|
+
pullUrl: 'https://github.com/elastic/kibana/pull/121633',
|
|
28
|
+
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
29
|
+
sourceBranch: 'main',
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
});
|
package/dist/main.js
CHANGED
|
@@ -14,7 +14,6 @@ const logger_1 = require("./services/logger");
|
|
|
14
14
|
const getCommits_1 = require("./ui/getCommits");
|
|
15
15
|
const getTargetBranches_1 = require("./ui/getTargetBranches");
|
|
16
16
|
async function main(argv, optionsFromModule) {
|
|
17
|
-
const logger = (0, logger_1.initLogger)();
|
|
18
17
|
let options = null;
|
|
19
18
|
let commits = [];
|
|
20
19
|
try {
|
|
@@ -57,7 +56,7 @@ async function main(argv, optionsFromModule) {
|
|
|
57
56
|
(0, logger_1.consoleLog)('Please open an issue in https://github.com/sqren/backport/issues or contact me directly on https://twitter.com/sorenlouv');
|
|
58
57
|
(0, logger_1.consoleLog)(chalk_1.default.italic(`For additional details see the logs: ${(0, env_1.getLogfilePath)()}`));
|
|
59
58
|
// log file
|
|
60
|
-
logger.info('Unknown error:', e);
|
|
59
|
+
logger_1.logger.info('Unknown error:', e);
|
|
61
60
|
}
|
|
62
61
|
return backportResponse;
|
|
63
62
|
}
|
|
@@ -12,19 +12,17 @@ declare type AutoFixConflictsHandler = ({ files, directory, logger, targetBranch
|
|
|
12
12
|
}) => boolean | Promise<boolean>;
|
|
13
13
|
declare type Options = Partial<{
|
|
14
14
|
accessToken: string;
|
|
15
|
-
all: boolean;
|
|
16
15
|
assignees: string[];
|
|
17
|
-
author: string;
|
|
16
|
+
author: string | null;
|
|
18
17
|
autoAssign: boolean;
|
|
19
18
|
autoFixConflicts: AutoFixConflictsHandler;
|
|
20
19
|
autoMerge: boolean;
|
|
21
20
|
autoMergeMethod: string;
|
|
22
|
-
ci: boolean;
|
|
23
21
|
cherrypickRef: boolean;
|
|
22
|
+
ci: boolean;
|
|
24
23
|
commitPaths: string[];
|
|
25
24
|
details: boolean;
|
|
26
25
|
editor: string;
|
|
27
|
-
forceLocalConfig: boolean;
|
|
28
26
|
fork: boolean;
|
|
29
27
|
gitHostname: string;
|
|
30
28
|
githubApiBaseUrlV3: string;
|
|
@@ -38,21 +36,32 @@ declare type Options = Partial<{
|
|
|
38
36
|
prFilter: string;
|
|
39
37
|
prTitle: string;
|
|
40
38
|
pullNumber: number;
|
|
39
|
+
repoName: string;
|
|
40
|
+
repoOwner: string;
|
|
41
41
|
resetAuthor: boolean;
|
|
42
42
|
reviewers: string[];
|
|
43
43
|
sha: string;
|
|
44
|
+
skipRemoteConfig: boolean;
|
|
44
45
|
sourceBranch: string;
|
|
45
46
|
sourcePRLabels: string[];
|
|
46
47
|
targetBranchChoices: TargetBranchChoiceOrString[];
|
|
47
48
|
targetBranches: string[];
|
|
48
49
|
targetPRLabels: string[];
|
|
49
|
-
upstream: string;
|
|
50
|
-
username: string;
|
|
51
50
|
verbose: boolean;
|
|
52
51
|
}>;
|
|
53
52
|
export declare type ConfigFileOptions = Options & Partial<{
|
|
54
53
|
branchLabelMapping: Record<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Replaced by `repoOwner` and `repoName`
|
|
56
|
+
*/
|
|
57
|
+
upstream: string;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Replaced by `targetBranchChoices`
|
|
60
|
+
*/
|
|
55
61
|
branches: TargetBranchChoiceOrString[];
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated Replaced by `targetPRLabels`
|
|
64
|
+
*/
|
|
56
65
|
labels: string[];
|
|
57
66
|
}>;
|
|
58
67
|
export {};
|
|
@@ -2,41 +2,40 @@ export declare type OptionsFromCliArgs = ReturnType<typeof getOptionsFromCliArgs
|
|
|
2
2
|
export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnError }?: {
|
|
3
3
|
exitOnError?: boolean;
|
|
4
4
|
}): {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
fork?: boolean | undefined;
|
|
6
|
+
verbose?: boolean | undefined;
|
|
7
|
+
accessToken?: string | undefined;
|
|
7
8
|
assignees: string[];
|
|
9
|
+
author?: string | null | undefined;
|
|
10
|
+
autoAssign?: boolean | undefined;
|
|
11
|
+
autoMerge?: boolean | undefined;
|
|
12
|
+
autoMergeMethod?: string | undefined;
|
|
13
|
+
cherrypickRef?: boolean | undefined;
|
|
14
|
+
ci?: boolean | undefined;
|
|
8
15
|
commitPaths: string[];
|
|
16
|
+
details?: boolean | undefined;
|
|
17
|
+
editor?: string | undefined;
|
|
18
|
+
gitHostname?: string | undefined;
|
|
19
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
20
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
21
|
+
maxNumber?: number | undefined;
|
|
22
|
+
multipleBranches?: boolean | undefined;
|
|
23
|
+
multipleCommits?: boolean | undefined;
|
|
24
|
+
noVerify?: boolean | undefined;
|
|
25
|
+
prDescription?: string | undefined;
|
|
26
|
+
prFilter?: string | undefined;
|
|
27
|
+
prTitle?: string | undefined;
|
|
28
|
+
pullNumber?: number | undefined;
|
|
29
|
+
repoName?: string | undefined;
|
|
30
|
+
repoOwner?: string | undefined;
|
|
31
|
+
resetAuthor?: boolean | undefined;
|
|
9
32
|
reviewers: string[];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
all: boolean | undefined;
|
|
19
|
-
author: string | undefined;
|
|
20
|
-
autoAssign: boolean | undefined;
|
|
21
|
-
autoMerge: boolean | undefined;
|
|
22
|
-
autoMergeMethod: string | undefined;
|
|
23
|
-
ci: boolean | undefined;
|
|
24
|
-
details: boolean | undefined;
|
|
25
|
-
editor: string | undefined;
|
|
26
|
-
forceLocalConfig: boolean | undefined;
|
|
27
|
-
gitHostname: string | undefined;
|
|
28
|
-
githubApiBaseUrlV3: string | undefined;
|
|
29
|
-
githubApiBaseUrlV4: string | undefined;
|
|
30
|
-
mainline: number | undefined;
|
|
31
|
-
maxNumber: number | undefined;
|
|
32
|
-
prDescription: string | undefined;
|
|
33
|
-
prTitle: string | undefined;
|
|
34
|
-
prFilter: string | undefined;
|
|
35
|
-
pullNumber: number | undefined;
|
|
36
|
-
resetAuthor: boolean | undefined;
|
|
37
|
-
sha: string | undefined;
|
|
38
|
-
sourceBranch: string | undefined;
|
|
39
|
-
upstream: string | undefined;
|
|
40
|
-
username: string | undefined;
|
|
41
|
-
verbose: boolean | undefined;
|
|
33
|
+
sha?: string | undefined;
|
|
34
|
+
skipRemoteConfig?: boolean | undefined;
|
|
35
|
+
sourceBranch?: string | undefined;
|
|
36
|
+
sourcePRLabels?: string[] | undefined;
|
|
37
|
+
targetBranchChoices?: string[] | undefined;
|
|
38
|
+
targetBranches?: string[] | undefined;
|
|
39
|
+
targetPRLabels?: string[] | undefined;
|
|
40
|
+
mainline?: number | undefined;
|
|
42
41
|
};
|
package/dist/options/cliArgs.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getOptionsFromCliArgs = void 0;
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
const excludeUndefined_1 = require("../utils/excludeUndefined");
|
|
8
9
|
function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
9
10
|
const yargsInstance = (0, yargs_1.default)(argv)
|
|
10
11
|
.parserConfiguration({
|
|
@@ -24,6 +25,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
24
25
|
description: 'List all commits',
|
|
25
26
|
alias: 'a',
|
|
26
27
|
type: 'boolean',
|
|
28
|
+
conflicts: 'author',
|
|
27
29
|
})
|
|
28
30
|
.option('assignee', {
|
|
29
31
|
description: 'Add assignees to the target pull request',
|
|
@@ -31,10 +33,6 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
31
33
|
type: 'array',
|
|
32
34
|
string: true,
|
|
33
35
|
conflicts: ['autoAssign'],
|
|
34
|
-
})
|
|
35
|
-
.option('author', {
|
|
36
|
-
description: 'Show commits by specific author',
|
|
37
|
-
type: 'string',
|
|
38
36
|
})
|
|
39
37
|
.option('autoAssign', {
|
|
40
38
|
description: 'Auto assign the target pull request to yourself',
|
|
@@ -67,11 +65,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
67
65
|
description: 'Editor to be opened during conflict resolution',
|
|
68
66
|
type: 'string',
|
|
69
67
|
})
|
|
70
|
-
.option('
|
|
68
|
+
.option('skipRemoteConfig', {
|
|
71
69
|
description: 'Use local .backportrc.json config instead of loading from Github',
|
|
72
70
|
type: 'boolean',
|
|
73
71
|
})
|
|
74
|
-
// push target branch to {
|
|
72
|
+
// push target branch to {authenticatedUsername}/{repoName}
|
|
75
73
|
.option('fork', {
|
|
76
74
|
description: 'Create backports in fork or origin repo',
|
|
77
75
|
type: 'boolean',
|
|
@@ -181,6 +179,14 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
181
179
|
description: 'Add reviewer to the target PR',
|
|
182
180
|
type: 'array',
|
|
183
181
|
string: true,
|
|
182
|
+
})
|
|
183
|
+
.option('repoOwner', {
|
|
184
|
+
description: 'Repository owner',
|
|
185
|
+
type: 'string',
|
|
186
|
+
})
|
|
187
|
+
.option('repoName', {
|
|
188
|
+
description: 'Repository name',
|
|
189
|
+
type: 'string',
|
|
184
190
|
})
|
|
185
191
|
.option('sha', {
|
|
186
192
|
conflicts: ['pullNumber', 'prFilter'],
|
|
@@ -215,14 +221,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
215
221
|
type: 'array',
|
|
216
222
|
string: true,
|
|
217
223
|
})
|
|
218
|
-
.option('
|
|
219
|
-
description: '
|
|
220
|
-
alias: '
|
|
221
|
-
type: 'string',
|
|
222
|
-
})
|
|
223
|
-
.option('username', {
|
|
224
|
-
description: 'Github username',
|
|
224
|
+
.option('author', {
|
|
225
|
+
description: 'Show commits by a specific user',
|
|
226
|
+
alias: 'author',
|
|
225
227
|
type: 'string',
|
|
228
|
+
conflicts: 'all',
|
|
226
229
|
})
|
|
227
230
|
.option('verbose', {
|
|
228
231
|
description: 'Show additional debug information',
|
|
@@ -252,13 +255,14 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
252
255
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
253
256
|
$0, _,
|
|
254
257
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
255
|
-
multiple, multipleBranches, multipleCommits,
|
|
258
|
+
multiple, multipleBranches, multipleCommits, all, author,
|
|
256
259
|
// negations
|
|
257
260
|
verify, noVerify, noCherrypickRef, noFork,
|
|
258
261
|
// array types (should be renamed to plural form)
|
|
259
262
|
assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
|
|
260
|
-
return excludeUndefined({
|
|
263
|
+
return (0, excludeUndefined_1.excludeUndefined)({
|
|
261
264
|
...restOptions,
|
|
265
|
+
author: all ? null : author,
|
|
262
266
|
// `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
|
|
263
267
|
multipleBranches: multiple ?? multipleBranches,
|
|
264
268
|
multipleCommits: multiple ?? multipleCommits,
|
|
@@ -277,7 +281,3 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
277
281
|
});
|
|
278
282
|
}
|
|
279
283
|
exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
|
|
280
|
-
function excludeUndefined(obj) {
|
|
281
|
-
Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);
|
|
282
|
-
return obj;
|
|
283
|
-
}
|
|
@@ -20,16 +20,19 @@ describe('getOptionsFromCliArgs', () => {
|
|
|
20
20
|
const argv = [
|
|
21
21
|
'--access-token',
|
|
22
22
|
'my access token',
|
|
23
|
-
'--
|
|
23
|
+
'--author',
|
|
24
24
|
'sqren',
|
|
25
|
-
'--
|
|
26
|
-
'elastic
|
|
25
|
+
'--repo-owner',
|
|
26
|
+
'elastic',
|
|
27
|
+
'--repo-name',
|
|
28
|
+
'kibana',
|
|
27
29
|
];
|
|
28
30
|
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
29
31
|
expect(res).toEqual({
|
|
30
32
|
accessToken: 'my access token',
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
repoOwner: 'elastic',
|
|
34
|
+
repoName: 'kibana',
|
|
35
|
+
author: 'sqren',
|
|
33
36
|
mainline: 1,
|
|
34
37
|
reviewers: [],
|
|
35
38
|
assignees: [],
|