backport 7.2.0 → 7.3.1
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 +12 -5
- package/dist/backportRun.js +12 -1
- package/dist/entrypoint.cli.d.ts +0 -1
- package/dist/entrypoint.cli.js +0 -1
- package/dist/entrypoint.cli.private.test.js +1 -0
- package/dist/options/ConfigOptions.d.ts +3 -1
- package/dist/options/cliArgs.d.ts +3 -1
- package/dist/options/cliArgs.js +16 -7
- package/dist/options/config/config.d.ts +3 -1
- package/dist/options/config/readConfigFile.d.ts +3 -1
- package/dist/options/options.d.ts +3 -1
- package/dist/options/options.js +3 -1
- package/dist/options/options.test.js +2 -1
- package/dist/runSequentially.d.ts +3 -1
- package/dist/runSequentially.js +2 -3
- package/dist/services/git.d.ts +15 -7
- package/dist/services/git.integration.test.js +38 -58
- package/dist/services/git.js +21 -28
- package/dist/services/git.test.js +56 -17
- package/dist/services/github/v3/createPullRequest.test.js +52 -0
- package/dist/services/github/v3/createStatusComment.test.js +12 -2
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -3
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -1
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +20 -0
- package/dist/services/prompt.test.js +5 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +6 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +1 -0
- package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/cli.private.test.js +219 -0
- package/dist/test/e2e/cli/commit-author.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +96 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +108 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +49 -0
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -0
- package/dist/test/e2e/cli/runBackportViaCli.js +53 -0
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +73 -0
- package/dist/test/e2e/module/module.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module/module.mutation.test.js +369 -0
- package/dist/test/e2e/module.e2e.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module.e2e.mutation.test.js +369 -0
- package/dist/test/e2e/module.e2e.private.test.js +6 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +3 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +29 -10
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +38 -25
- package/dist/ui/getCommitsWithoutBackports.test.js +20 -0
- package/dist/ui/getGitConfigAuthor.d.ts +6 -0
- package/dist/ui/getGitConfigAuthor.js +15 -0
- package/dist/ui/getTargetBranches.test.js +2 -0
- package/dist/ui/setupRepo.d.ts +2 -0
- package/dist/ui/setupRepo.js +56 -0
- package/dist/ui/setupRepo.test.d.ts +1 -0
- package/dist/ui/setupRepo.test.js +236 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +11 -11
- package/yarn.lock +61 -81
package/README.md
CHANGED
|
@@ -29,6 +29,10 @@ After installation you should add an access token to the [global config](https:/
|
|
|
29
29
|
|
|
30
30
|
## Quick start
|
|
31
31
|
|
|
32
|
+
```
|
|
33
|
+
npm install backport
|
|
34
|
+
```
|
|
35
|
+
|
|
32
36
|
Add a [project config](https://github.com/sqren/backport/blob/master/docs/configuration.md#project-config-backportrcjson) to the root of your repository:
|
|
33
37
|
|
|
34
38
|
```js
|
|
@@ -48,10 +52,13 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
|
|
|
48
52
|
}
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
Add personal access token to [global config](https://github.com/sqren/backport/blob/master/docs/configuration.md#global-config-backportconfigjson):
|
|
52
56
|
|
|
53
|
-
```
|
|
54
|
-
|
|
57
|
+
```js
|
|
58
|
+
// ~/.backport/config.json
|
|
59
|
+
{
|
|
60
|
+
"accessToken": "ghp_very_secret"
|
|
61
|
+
}
|
|
55
62
|
```
|
|
56
63
|
|
|
57
64
|
Run:
|
|
@@ -71,7 +78,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
|
|
|
71
78
|
| Option | Shorthand notation | Description | Default |
|
|
72
79
|
| ------------------- | ------------------ | -------------------------------------------------------------------------- | ------------------------- |
|
|
73
80
|
| --access-token | | Github access token | |
|
|
74
|
-
| --all | -a | Show commits from any author
|
|
81
|
+
| --all | -a | Show commits from any author. Opposite of `--author` | false |
|
|
75
82
|
| --assignee | --assign | Assign users to the target PR | |
|
|
76
83
|
| --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
|
|
77
84
|
| --auto-assign | | Assign current user to the target PR | false |
|
|
@@ -96,6 +103,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
|
|
|
96
103
|
| --pr-filter | | Find PRs using [Github's search syntax][2] | |
|
|
97
104
|
| --pr-title | --title | Title of pull request | |
|
|
98
105
|
| --pull-number | --pr | Backport pull request by number | |
|
|
106
|
+
| --repo-fork-owner | | The owner of the fork where the backport branch is pushed. | _Current user_ |
|
|
99
107
|
| --repo-name | | Name of repository | |
|
|
100
108
|
| --repo-owner | | Owner of repository | |
|
|
101
109
|
| --reset-author | | Set yourself as commit author | |
|
|
@@ -265,6 +273,5 @@ See [CONTRIBUTING.md](https://github.com/sqren/backport/blob/master/CONTRIBUTING
|
|
|
265
273
|
[1]: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x
|
|
266
274
|
[2]: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
|
|
267
275
|
|
|
268
|
-
[](https://app.travis-ci.com/github/sqren/backport)
|
|
269
276
|
[](https://www.npmjs.com/package/backport)
|
|
270
277
|
[](https://coveralls.io/github/sqren/backport?branch=master)
|
package/dist/backportRun.js
CHANGED
|
@@ -14,8 +14,10 @@ const createStatusComment_1 = require("./services/github/v3/createStatusComment"
|
|
|
14
14
|
const apiRequestV4_1 = require("./services/github/v4/apiRequestV4");
|
|
15
15
|
const logger_1 = require("./services/logger");
|
|
16
16
|
const getCommits_1 = require("./ui/getCommits");
|
|
17
|
+
const getGitConfigAuthor_1 = require("./ui/getGitConfigAuthor");
|
|
17
18
|
const getTargetBranches_1 = require("./ui/getTargetBranches");
|
|
18
19
|
const ora_1 = require("./ui/ora");
|
|
20
|
+
const setupRepo_1 = require("./ui/setupRepo");
|
|
19
21
|
async function backportRun(processArgs, optionsFromModule = {}) {
|
|
20
22
|
const argv = (0, yargs_parser_1.default)(processArgs);
|
|
21
23
|
const ci = argv.ci ?? optionsFromModule.ci;
|
|
@@ -36,7 +38,16 @@ async function backportRun(processArgs, optionsFromModule = {}) {
|
|
|
36
38
|
logger_1.logger.info('Commits', commits);
|
|
37
39
|
const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
38
40
|
logger_1.logger.info('Target branches', targetBranches);
|
|
39
|
-
const
|
|
41
|
+
const [gitConfigAuthor] = await Promise.all([
|
|
42
|
+
(0, getGitConfigAuthor_1.getGitConfigAuthor)(options),
|
|
43
|
+
(0, setupRepo_1.setupRepo)(options),
|
|
44
|
+
]);
|
|
45
|
+
const results = await (0, runSequentially_1.runSequentially)({
|
|
46
|
+
options,
|
|
47
|
+
commits,
|
|
48
|
+
targetBranches,
|
|
49
|
+
gitConfigAuthor,
|
|
50
|
+
});
|
|
40
51
|
logger_1.logger.info('Results', results);
|
|
41
52
|
const backportResponse = {
|
|
42
53
|
status: 'success',
|
package/dist/entrypoint.cli.d.ts
CHANGED
package/dist/entrypoint.cli.js
CHANGED
|
@@ -27,6 +27,8 @@ declare type Options = Partial<{
|
|
|
27
27
|
dir: string;
|
|
28
28
|
editor: string;
|
|
29
29
|
fork: boolean;
|
|
30
|
+
gitAuthorEmail: string;
|
|
31
|
+
gitAuthorName: string;
|
|
30
32
|
gitHostname: string;
|
|
31
33
|
githubApiBaseUrlV3: string;
|
|
32
34
|
githubApiBaseUrlV4: string;
|
|
@@ -41,6 +43,7 @@ declare type Options = Partial<{
|
|
|
41
43
|
prTitle: string;
|
|
42
44
|
publishStatusComment: boolean;
|
|
43
45
|
pullNumber: number;
|
|
46
|
+
repoForkOwner: string;
|
|
44
47
|
repoName: string;
|
|
45
48
|
repoOwner: string;
|
|
46
49
|
resetAuthor: boolean;
|
|
@@ -52,7 +55,6 @@ declare type Options = Partial<{
|
|
|
52
55
|
targetBranchChoices: TargetBranchChoiceOrString[];
|
|
53
56
|
targetBranches: string[];
|
|
54
57
|
targetPRLabels: string[];
|
|
55
|
-
username: string;
|
|
56
58
|
verbose: boolean;
|
|
57
59
|
}>;
|
|
58
60
|
export declare type ConfigFileOptions = Options & Partial<{
|
|
@@ -22,11 +22,14 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
|
|
|
22
22
|
gitHostname?: string | undefined;
|
|
23
23
|
githubApiBaseUrlV3?: string | undefined;
|
|
24
24
|
githubApiBaseUrlV4?: string | undefined;
|
|
25
|
+
gitAuthorName?: string | undefined;
|
|
26
|
+
gitAuthorEmail?: string | undefined;
|
|
25
27
|
mainline?: number | undefined;
|
|
26
28
|
maxNumber?: number | undefined;
|
|
27
29
|
multipleBranches?: boolean | undefined;
|
|
28
30
|
multipleCommits?: boolean | undefined;
|
|
29
31
|
noVerify?: boolean | undefined;
|
|
32
|
+
repoForkOwner?: string | undefined;
|
|
30
33
|
prDescription?: string | undefined;
|
|
31
34
|
prTitle?: string | undefined;
|
|
32
35
|
prFilter?: string | undefined;
|
|
@@ -36,7 +39,6 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
|
|
|
36
39
|
repoOwner?: string | undefined;
|
|
37
40
|
repoName?: string | undefined;
|
|
38
41
|
sourceBranch?: string | undefined;
|
|
39
|
-
username?: string | undefined;
|
|
40
42
|
dateSince?: string | undefined;
|
|
41
43
|
dateUntil?: string | undefined;
|
|
42
44
|
commitPaths?: string[] | undefined;
|
package/dist/options/cliArgs.js
CHANGED
|
@@ -96,9 +96,9 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
|
|
|
96
96
|
description: 'Use local .backportrc.json config instead of loading from Github',
|
|
97
97
|
type: 'boolean',
|
|
98
98
|
})
|
|
99
|
-
// push target branch to {
|
|
99
|
+
// push target branch to {repoForkOwner}/{repoName}
|
|
100
100
|
.option('fork', {
|
|
101
|
-
description: 'Create backports in fork or origin repo',
|
|
101
|
+
description: 'Create backports in fork or origin repo. Defaults to true',
|
|
102
102
|
type: 'boolean',
|
|
103
103
|
conflicts: ['noFork'],
|
|
104
104
|
})
|
|
@@ -116,6 +116,14 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
|
|
|
116
116
|
hidden: true,
|
|
117
117
|
description: `Base url for Github's GraphQL (v4) API`,
|
|
118
118
|
type: 'string',
|
|
119
|
+
})
|
|
120
|
+
.option('gitAuthorName', {
|
|
121
|
+
description: `Set commit author name`,
|
|
122
|
+
type: 'string',
|
|
123
|
+
})
|
|
124
|
+
.option('gitAuthorEmail', {
|
|
125
|
+
description: `Set commit author email`,
|
|
126
|
+
type: 'string',
|
|
119
127
|
})
|
|
120
128
|
.option('logFilePath', {
|
|
121
129
|
hidden: true,
|
|
@@ -179,7 +187,7 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
|
|
|
179
187
|
.option('noFork', {
|
|
180
188
|
description: 'Create backports in the origin repo',
|
|
181
189
|
type: 'boolean',
|
|
182
|
-
conflicts: ['fork'],
|
|
190
|
+
conflicts: ['fork', 'repoForkOwner'],
|
|
183
191
|
})
|
|
184
192
|
.option('path', {
|
|
185
193
|
description: 'Only list commits touching files under the specified path',
|
|
@@ -216,6 +224,11 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
|
|
|
216
224
|
description: 'Add reviewer to the target PR',
|
|
217
225
|
type: 'array',
|
|
218
226
|
string: true,
|
|
227
|
+
})
|
|
228
|
+
.option('repoForkOwner', {
|
|
229
|
+
description: 'The owner of the fork where the backport branch is pushed. Defaults to the currently authenticated user',
|
|
230
|
+
type: 'string',
|
|
231
|
+
conflicts: ['noFork'],
|
|
219
232
|
})
|
|
220
233
|
.option('repoOwner', {
|
|
221
234
|
description: 'Repository owner',
|
|
@@ -264,10 +277,6 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
|
|
|
264
277
|
alias: ['label', 'l'],
|
|
265
278
|
type: 'array',
|
|
266
279
|
string: true,
|
|
267
|
-
})
|
|
268
|
-
.option('username', {
|
|
269
|
-
description: 'Defaults to the authenticated user ',
|
|
270
|
-
type: 'string',
|
|
271
280
|
})
|
|
272
281
|
.option('verbose', {
|
|
273
282
|
description: 'Show additional debug information',
|
|
@@ -27,6 +27,8 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
|
|
|
27
27
|
dir?: string | undefined;
|
|
28
28
|
editor?: string | undefined;
|
|
29
29
|
fork?: boolean | undefined;
|
|
30
|
+
gitAuthorEmail?: string | undefined;
|
|
31
|
+
gitAuthorName?: string | undefined;
|
|
30
32
|
gitHostname?: string | undefined;
|
|
31
33
|
githubApiBaseUrlV3?: string | undefined;
|
|
32
34
|
githubApiBaseUrlV4?: string | undefined;
|
|
@@ -41,6 +43,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
|
|
|
41
43
|
prTitle?: string | undefined;
|
|
42
44
|
publishStatusComment?: boolean | undefined;
|
|
43
45
|
pullNumber?: number | undefined;
|
|
46
|
+
repoForkOwner?: string | undefined;
|
|
44
47
|
repoName?: string | undefined;
|
|
45
48
|
repoOwner?: string | undefined;
|
|
46
49
|
resetAuthor?: boolean | undefined;
|
|
@@ -52,7 +55,6 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
|
|
|
52
55
|
targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
53
56
|
targetBranches?: string[] | undefined;
|
|
54
57
|
targetPRLabels?: string[] | undefined;
|
|
55
|
-
username?: string | undefined;
|
|
56
58
|
verbose?: boolean | undefined;
|
|
57
59
|
help?: boolean | undefined;
|
|
58
60
|
version?: boolean | undefined;
|
|
@@ -21,11 +21,14 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
21
21
|
gitHostname?: string | undefined;
|
|
22
22
|
githubApiBaseUrlV3?: string | undefined;
|
|
23
23
|
githubApiBaseUrlV4?: string | undefined;
|
|
24
|
+
gitAuthorName?: string | undefined;
|
|
25
|
+
gitAuthorEmail?: string | undefined;
|
|
24
26
|
maxNumber?: number | undefined;
|
|
25
27
|
multiple?: boolean | undefined;
|
|
26
28
|
multipleBranches?: boolean | undefined;
|
|
27
29
|
multipleCommits?: boolean | undefined;
|
|
28
30
|
noVerify?: boolean | undefined;
|
|
31
|
+
repoForkOwner?: string | undefined;
|
|
29
32
|
prDescription?: string | undefined;
|
|
30
33
|
prTitle?: string | undefined;
|
|
31
34
|
prFilter?: string | undefined;
|
|
@@ -35,7 +38,6 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
35
38
|
repoOwner?: string | undefined;
|
|
36
39
|
repoName?: string | undefined;
|
|
37
40
|
sourceBranch?: string | undefined;
|
|
38
|
-
username?: string | undefined;
|
|
39
41
|
version?: boolean | undefined;
|
|
40
42
|
v?: boolean | undefined;
|
|
41
43
|
commitPaths?: string[] | undefined;
|
|
@@ -23,11 +23,14 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
23
23
|
gitHostname: string;
|
|
24
24
|
githubApiBaseUrlV3?: string | undefined;
|
|
25
25
|
githubApiBaseUrlV4?: string | undefined;
|
|
26
|
+
gitAuthorName?: string | undefined;
|
|
27
|
+
gitAuthorEmail?: string | undefined;
|
|
26
28
|
mainline?: number | undefined;
|
|
27
29
|
maxNumber: number;
|
|
28
30
|
multipleBranches: boolean;
|
|
29
31
|
multipleCommits: boolean;
|
|
30
32
|
noVerify: boolean;
|
|
33
|
+
repoForkOwner: string;
|
|
31
34
|
prDescription?: string | undefined;
|
|
32
35
|
prTitle?: string | undefined;
|
|
33
36
|
prFilter?: string | undefined;
|
|
@@ -35,7 +38,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
35
38
|
sha?: string | string[] | undefined;
|
|
36
39
|
resetAuthor: boolean;
|
|
37
40
|
sourceBranch: string;
|
|
38
|
-
username?: string | undefined;
|
|
39
41
|
dateSince: string | null;
|
|
40
42
|
dateUntil: string | null;
|
|
41
43
|
commitPaths: string[];
|
package/dist/options/options.js
CHANGED
|
@@ -64,6 +64,8 @@ async function getOptions(processArgs, optionsFromModule) {
|
|
|
64
64
|
const options = {
|
|
65
65
|
// default author
|
|
66
66
|
author: optionsFromGithub.authenticatedUsername,
|
|
67
|
+
// default fork owner
|
|
68
|
+
repoForkOwner: optionsFromGithub.authenticatedUsername,
|
|
67
69
|
// default values have lowest precedence
|
|
68
70
|
...defaultConfigOptions,
|
|
69
71
|
// local config options override default options
|
|
@@ -132,11 +134,11 @@ function throwForRequiredOptions(options) {
|
|
|
132
134
|
'prDescription',
|
|
133
135
|
'prFilter',
|
|
134
136
|
'prTitle',
|
|
137
|
+
'repoForkOwner',
|
|
135
138
|
'repoName',
|
|
136
139
|
'repoOwner',
|
|
137
140
|
'sha',
|
|
138
141
|
'sourceBranch',
|
|
139
|
-
'username',
|
|
140
142
|
];
|
|
141
143
|
// Disallow empty strings
|
|
142
144
|
// this is primarily an issue in Github actions where inputs default to empty strings instead of undefined
|
|
@@ -83,7 +83,7 @@ describe('getOptions', () => {
|
|
|
83
83
|
});
|
|
84
84
|
describe('whe option is an empty string', () => {
|
|
85
85
|
it('throws for "username"', async () => {
|
|
86
|
-
await expect(() => (0, options_1.getOptions)([], {
|
|
86
|
+
await expect(() => (0, options_1.getOptions)([], { repoForkOwner: '', author: 'sqren' })).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"repoForkOwner\\" cannot be empty!"`);
|
|
87
87
|
});
|
|
88
88
|
it('throws for "author"', async () => {
|
|
89
89
|
await expect(() => (0, options_1.getOptions)([], { author: '' })).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"author\\" cannot be empty!"`);
|
|
@@ -180,6 +180,7 @@ describe('getOptions', () => {
|
|
|
180
180
|
multipleCommits: false,
|
|
181
181
|
noVerify: true,
|
|
182
182
|
publishStatusComment: true,
|
|
183
|
+
repoForkOwner: 'john.diller',
|
|
183
184
|
repoName: 'kibana',
|
|
184
185
|
repoOwner: 'elastic',
|
|
185
186
|
resetAuthor: false,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ValidConfigOptions } from './options/options';
|
|
2
2
|
import { HandledError } from './services/HandledError';
|
|
3
3
|
import { Commit } from './services/sourceCommit/parseSourceCommit';
|
|
4
|
+
import { GitConfigAuthor } from './ui/getGitConfigAuthor';
|
|
4
5
|
export declare type Result = {
|
|
5
6
|
status: 'success';
|
|
6
7
|
didUpdate: boolean;
|
|
@@ -12,8 +13,9 @@ export declare type Result = {
|
|
|
12
13
|
targetBranch: string;
|
|
13
14
|
error: HandledError;
|
|
14
15
|
};
|
|
15
|
-
export declare function runSequentially({ options, commits, targetBranches, }: {
|
|
16
|
+
export declare function runSequentially({ options, commits, targetBranches, gitConfigAuthor, }: {
|
|
16
17
|
options: ValidConfigOptions;
|
|
17
18
|
commits: Commit[];
|
|
18
19
|
targetBranches: string[];
|
|
20
|
+
gitConfigAuthor?: GitConfigAuthor;
|
|
19
21
|
}): Promise<Result[]>;
|
package/dist/runSequentially.js
CHANGED
|
@@ -4,10 +4,8 @@ exports.runSequentially = void 0;
|
|
|
4
4
|
const logger_1 = require("./services/logger");
|
|
5
5
|
const sequentially_1 = require("./services/sequentially");
|
|
6
6
|
const cherrypickAndCreateTargetPullRequest_1 = require("./ui/cherrypickAndCreateTargetPullRequest");
|
|
7
|
-
|
|
8
|
-
async function runSequentially({ options, commits, targetBranches, }) {
|
|
7
|
+
async function runSequentially({ options, commits, targetBranches, gitConfigAuthor, }) {
|
|
9
8
|
logger_1.logger.verbose('Backport options', options);
|
|
10
|
-
await (0, maybeSetupRepo_1.maybeSetupRepo)(options);
|
|
11
9
|
const results = [];
|
|
12
10
|
await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
|
|
13
11
|
logger_1.logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
|
|
@@ -16,6 +14,7 @@ async function runSequentially({ options, commits, targetBranches, }) {
|
|
|
16
14
|
options,
|
|
17
15
|
commits,
|
|
18
16
|
targetBranch,
|
|
17
|
+
gitConfigAuthor: gitConfigAuthor,
|
|
19
18
|
});
|
|
20
19
|
results.push({
|
|
21
20
|
targetBranch,
|
package/dist/services/git.d.ts
CHANGED
|
@@ -21,14 +21,22 @@ export declare function getRepoInfoFromGitRemotes({ cwd }: {
|
|
|
21
21
|
repoOwner: string;
|
|
22
22
|
repoName: string;
|
|
23
23
|
}[]>;
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function getGitProjectRootPath(dir: string): Promise<string | undefined>;
|
|
25
25
|
export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
|
|
26
26
|
export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
27
27
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
28
28
|
export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
|
|
29
29
|
export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
|
|
30
30
|
export declare function getCommitsInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
|
|
31
|
-
export declare function cherrypick(options
|
|
31
|
+
export declare function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }: {
|
|
32
|
+
options: ValidConfigOptions;
|
|
33
|
+
sha: string;
|
|
34
|
+
mergedTargetPullRequest?: ExpectedTargetPullRequest;
|
|
35
|
+
commitAuthor: {
|
|
36
|
+
name: string;
|
|
37
|
+
email: string;
|
|
38
|
+
};
|
|
39
|
+
}): Promise<{
|
|
32
40
|
conflictingFiles: {
|
|
33
41
|
absolute: string;
|
|
34
42
|
relative: string;
|
|
@@ -43,10 +51,10 @@ export declare function getConflictingFiles(options: ValidConfigOptions): Promis
|
|
|
43
51
|
relative: string;
|
|
44
52
|
}[]>;
|
|
45
53
|
export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
|
|
46
|
-
export declare function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}>;
|
|
54
|
+
export declare function getGitConfig({ dir, key, }: {
|
|
55
|
+
dir: string;
|
|
56
|
+
key: 'user.name' | 'user.email';
|
|
57
|
+
}): Promise<string | undefined>;
|
|
50
58
|
export declare function createBackportBranch({ options, targetBranch, backportBranch, }: {
|
|
51
59
|
options: ValidConfigOptions;
|
|
52
60
|
targetBranch: string;
|
|
@@ -67,4 +75,4 @@ export declare function pushBackportBranch({ options, backportBranch, }: {
|
|
|
67
75
|
stdout: string;
|
|
68
76
|
stderr: string;
|
|
69
77
|
}>;
|
|
70
|
-
export declare function
|
|
78
|
+
export declare function getLocalRepoPath(options: ValidConfigOptions): Promise<string | undefined>;
|
|
@@ -24,13 +24,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
const promises_1 = require("fs/promises");
|
|
26
26
|
const make_dir_1 = __importDefault(require("make-dir"));
|
|
27
|
-
const nockHelpers_1 = require("../test/nockHelpers");
|
|
28
27
|
const sandbox_1 = require("../test/sandbox");
|
|
29
28
|
const childProcess = __importStar(require("./child-process-promisified"));
|
|
30
29
|
const git_1 = require("./git");
|
|
31
30
|
const commitFormatters_1 = require("./github/commitFormatters");
|
|
32
31
|
jest.unmock('del');
|
|
33
32
|
jest.unmock('make-dir');
|
|
33
|
+
const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
|
|
34
34
|
describe('git.integration', () => {
|
|
35
35
|
describe('getIsCommitInBranch', () => {
|
|
36
36
|
let firstSha;
|
|
@@ -117,13 +117,21 @@ describe('git.integration', () => {
|
|
|
117
117
|
});
|
|
118
118
|
it('should not cherrypick commit that already exists', async () => {
|
|
119
119
|
const shortSha = (0, commitFormatters_1.getShortSha)(firstSha);
|
|
120
|
-
return expect(() => (0, git_1.cherrypick)({
|
|
120
|
+
return expect(() => (0, git_1.cherrypick)({
|
|
121
|
+
options: { dir: sandboxPath },
|
|
122
|
+
sha: firstSha,
|
|
123
|
+
commitAuthor: { name: 'Soren L', email: 'soren@mail.dk' },
|
|
124
|
+
})).rejects.toThrowError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
|
|
121
125
|
});
|
|
122
126
|
it('should cherrypick commit cleanly', async () => {
|
|
123
127
|
const res = await (0, git_1.cherrypick)({
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
options: {
|
|
129
|
+
cherrypickRef: false,
|
|
130
|
+
dir: sandboxPath,
|
|
131
|
+
},
|
|
132
|
+
sha: secondSha,
|
|
133
|
+
commitAuthor,
|
|
134
|
+
});
|
|
127
135
|
expect(res).toEqual({
|
|
128
136
|
conflictingFiles: [],
|
|
129
137
|
needsResolving: false,
|
|
@@ -134,9 +142,13 @@ describe('git.integration', () => {
|
|
|
134
142
|
});
|
|
135
143
|
it('should cherrypick commit cleanly and append "(cherry picked from commit...)"', async () => {
|
|
136
144
|
const res = await (0, git_1.cherrypick)({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
options: {
|
|
146
|
+
cherrypickRef: true,
|
|
147
|
+
dir: sandboxPath,
|
|
148
|
+
},
|
|
149
|
+
sha: secondSha,
|
|
150
|
+
commitAuthor,
|
|
151
|
+
});
|
|
140
152
|
expect(res).toEqual({
|
|
141
153
|
conflictingFiles: [],
|
|
142
154
|
needsResolving: false,
|
|
@@ -146,14 +158,15 @@ describe('git.integration', () => {
|
|
|
146
158
|
expect(message).toEqual(`Update bar.md\n\n(cherry picked from commit ${secondSha})`);
|
|
147
159
|
});
|
|
148
160
|
it('should cherrypick commit with conflicts', async () => {
|
|
149
|
-
const res = await (0, git_1.cherrypick)({
|
|
161
|
+
const res = await (0, git_1.cherrypick)({
|
|
162
|
+
options: { dir: sandboxPath },
|
|
163
|
+
sha: fourthSha,
|
|
164
|
+
commitAuthor,
|
|
165
|
+
});
|
|
150
166
|
expect(res).toEqual({
|
|
151
167
|
needsResolving: true,
|
|
152
168
|
conflictingFiles: [
|
|
153
|
-
{
|
|
154
|
-
absolute: `${sandboxPath}/foo.md`,
|
|
155
|
-
relative: 'foo.md',
|
|
156
|
-
},
|
|
169
|
+
{ absolute: `${sandboxPath}/foo.md`, relative: 'foo.md' },
|
|
157
170
|
],
|
|
158
171
|
unstagedFiles: [`${sandboxPath}/foo.md`],
|
|
159
172
|
});
|
|
@@ -186,44 +199,36 @@ describe('git.integration', () => {
|
|
|
186
199
|
await expect(() => (0, promises_1.access)(`${backportRepo}/my-file.txt`)).not.toThrowError();
|
|
187
200
|
});
|
|
188
201
|
});
|
|
189
|
-
describe('
|
|
190
|
-
let
|
|
202
|
+
describe('getLocalRepoPath', () => {
|
|
203
|
+
let sandboxPath;
|
|
191
204
|
beforeEach(async () => {
|
|
192
|
-
|
|
205
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
193
206
|
filename: __filename,
|
|
194
|
-
specname: '
|
|
207
|
+
specname: 'getLocalRepoPath',
|
|
195
208
|
});
|
|
196
|
-
sourceRepo = `${sandboxPath}/source-repo`;
|
|
197
209
|
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
198
|
-
|
|
199
|
-
const execOpts = { cwd: sourceRepo };
|
|
210
|
+
const execOpts = { cwd: sandboxPath };
|
|
200
211
|
await childProcess.exec(`git init`, execOpts);
|
|
201
|
-
await childProcess.exec(`git remote add
|
|
202
|
-
|
|
203
|
-
childRepoOwner: 'sqren',
|
|
204
|
-
parentRepoOwner: 'elastic',
|
|
205
|
-
repoName: 'kibana',
|
|
206
|
-
});
|
|
212
|
+
await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
|
|
213
|
+
await childProcess.exec(`git remote add elastic git@github.com:elastic/kibana.git`, execOpts);
|
|
207
214
|
});
|
|
208
215
|
it('returns local source repo, when one remote matches', async () => {
|
|
209
216
|
const options = {
|
|
210
|
-
accessToken: 'verysecret',
|
|
211
217
|
repoName: 'kibana',
|
|
212
218
|
repoOwner: 'elastic',
|
|
213
|
-
cwd:
|
|
219
|
+
cwd: sandboxPath,
|
|
214
220
|
githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
|
|
215
221
|
};
|
|
216
|
-
expect(await (0, git_1.
|
|
222
|
+
expect(await (0, git_1.getLocalRepoPath)(options)).toBe(sandboxPath);
|
|
217
223
|
});
|
|
218
|
-
it(
|
|
224
|
+
it('returns undefined when no remotes match', async () => {
|
|
219
225
|
const options = {
|
|
220
|
-
accessToken: 'verysecret',
|
|
221
226
|
repoName: 'kibana',
|
|
222
227
|
repoOwner: 'not-a-match',
|
|
223
|
-
cwd:
|
|
228
|
+
cwd: sandboxPath,
|
|
224
229
|
githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
|
|
225
230
|
};
|
|
226
|
-
expect(await (0, git_1.
|
|
231
|
+
expect(await (0, git_1.getLocalRepoPath)(options)).toBe(undefined);
|
|
227
232
|
});
|
|
228
233
|
});
|
|
229
234
|
describe('when cloning "backport-org/different-merge-strategies"', () => {
|
|
@@ -293,28 +298,3 @@ async function getCurrentMessage(execOpts) {
|
|
|
293
298
|
const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
|
|
294
299
|
return stdout.trim();
|
|
295
300
|
}
|
|
296
|
-
function mockRepoOwnerAndName({ repoName, parentRepoOwner, childRepoOwner, }) {
|
|
297
|
-
return (0, nockHelpers_1.mockGqlRequest)({
|
|
298
|
-
name: 'RepoOwnerAndName',
|
|
299
|
-
statusCode: 200,
|
|
300
|
-
body: {
|
|
301
|
-
data: {
|
|
302
|
-
// @ts-expect-error
|
|
303
|
-
repository: {
|
|
304
|
-
isFork: !!parentRepoOwner,
|
|
305
|
-
name: repoName,
|
|
306
|
-
owner: {
|
|
307
|
-
login: childRepoOwner,
|
|
308
|
-
},
|
|
309
|
-
parent: parentRepoOwner
|
|
310
|
-
? {
|
|
311
|
-
owner: {
|
|
312
|
-
login: parentRepoOwner,
|
|
313
|
-
},
|
|
314
|
-
}
|
|
315
|
-
: null,
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
});
|
|
320
|
-
}
|