backport 7.3.5 → 8.0.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 +13 -18
- package/dist/backportRun.d.ts +14 -3
- package/dist/backportRun.js +59 -37
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +8 -3
- package/dist/entrypoint.module.js +6 -10
- package/dist/entrypoint.module.private.test.js +129 -330
- package/dist/options/ConfigOptions.d.ts +2 -2
- package/dist/options/cliArgs.d.ts +10 -6
- package/dist/options/cliArgs.js +32 -21
- package/dist/options/cliArgs.test.js +3 -3
- package/dist/options/config/config.d.ts +2 -2
- package/dist/options/config/config.js +2 -2
- package/dist/options/config/globalConfig.d.ts +2 -2
- package/dist/options/config/globalConfig.js +13 -10
- package/dist/options/config/projectConfig.d.ts +2 -2
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +19 -7
- package/dist/options/config/readConfigFile.d.ts +4 -4
- package/dist/options/options.d.ts +4 -5
- package/dist/options/options.js +2 -3
- package/dist/options/options.test.js +7 -4
- package/dist/runSequentially.d.ts +5 -1
- package/dist/runSequentially.js +23 -8
- package/dist/scripts/postinstall.js +1 -0
- package/dist/scripts/postinstall.test.js +5 -1
- package/dist/services/HandledError.d.ts +6 -2
- package/dist/services/HandledError.js +8 -8
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +188 -126
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -158
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +3 -1
- package/dist/services/github/v3/createStatusComment.js +16 -16
- package/dist/services/github/v3/createStatusComment.test.js +17 -5
- package/dist/services/github/v4/apiRequestV4.js +6 -9
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
- package/dist/services/logger.d.ts +1 -4
- package/dist/services/logger.js +14 -19
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +401 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
- package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
- package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -10
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +16 -12
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +8 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +1 -1
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +13 -13
- package/yarn.lock +414 -695
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
## 🎉 New! The Backport Tool as a Github Action 🎉
|
|
10
10
|
|
|
11
|
-
A [Github Action](https://github.com/
|
|
11
|
+
A [Github Action](https://github.com/sqren/backport-github-action) around The Backport Tool now exists. It makes it a breeze to get automatic backports when pull requests are merged.
|
|
12
12
|
|
|
13
13
|
# Backport CLI tool
|
|
14
14
|
|
|
@@ -33,7 +33,7 @@ The remaining documentation focuses on the Backport CLI tool (not the Github Act
|
|
|
33
33
|
npm install -g backport
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
After installation you should add an access token to the [global config](https://github.com/sqren/backport/blob/
|
|
36
|
+
After installation you should add an access token to the [global config](https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson) in `~/.backport/config.json`. See the [documentation](https://github.com/sqren/backport/blob/main/docs/configuration.md#accesstoken-required) for how the access token is generated.
|
|
37
37
|
|
|
38
38
|
## Quick start
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ After installation you should add an access token to the [global config](https:/
|
|
|
41
41
|
npm install backport
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
Add a [project config](https://github.com/sqren/backport/blob/
|
|
44
|
+
Add a [project config](https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson) to the root of your repository:
|
|
45
45
|
|
|
46
46
|
```js
|
|
47
47
|
// .backportrc.json
|
|
@@ -60,7 +60,7 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
|
|
|
60
60
|
}
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
Add personal access token to [global config](https://github.com/sqren/backport/blob/
|
|
63
|
+
Add personal access token to [global config](https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson):
|
|
64
64
|
|
|
65
65
|
```js
|
|
66
66
|
// ~/.backport/config.json
|
|
@@ -79,7 +79,7 @@ _This will start an interactive prompt. You can use your keyboards arrow keys to
|
|
|
79
79
|
|
|
80
80
|
### Config options
|
|
81
81
|
|
|
82
|
-
See [configuration.md](https://github.com/sqren/backport/blob/
|
|
82
|
+
See [configuration.md](https://github.com/sqren/backport/blob/main/docs/configuration.md)
|
|
83
83
|
|
|
84
84
|
### CLI options
|
|
85
85
|
|
|
@@ -124,7 +124,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
|
|
|
124
124
|
| --help | | Show help | |
|
|
125
125
|
| -v, --version | | Show version number | |
|
|
126
126
|
|
|
127
|
-
The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/
|
|
127
|
+
The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/main/docs/configuration.md).
|
|
128
128
|
|
|
129
129
|
## Backport Module API
|
|
130
130
|
|
|
@@ -162,14 +162,13 @@ Enabling this will disable the interactive prompts
|
|
|
162
162
|
import { backportRun } from 'backport';
|
|
163
163
|
|
|
164
164
|
const result = await backportRun({
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
autoMergeMethod: 'squash',
|
|
165
|
+
options: {
|
|
166
|
+
accessToken: 'very secret',
|
|
167
|
+
repoName: 'kibana',
|
|
168
|
+
repoOwner: 'elastic',
|
|
169
|
+
pullNumber: 121633,
|
|
170
|
+
ci: true,
|
|
171
|
+
},
|
|
173
172
|
});
|
|
174
173
|
|
|
175
174
|
console.log(result);
|
|
@@ -244,10 +243,6 @@ console.log(commits);
|
|
|
244
243
|
*/
|
|
245
244
|
```
|
|
246
245
|
|
|
247
|
-
## The Backport Tool as a Github Action
|
|
248
|
-
|
|
249
|
-
A [Github Action](https://github.com/elastic/kibana-github-actions/tree/main/backport) around The Backport Tool for automatically creating backports when pull requests are merged.
|
|
250
|
-
|
|
251
246
|
## What is backporting?
|
|
252
247
|
|
|
253
248
|
> 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/backportRun.d.ts
CHANGED
|
@@ -2,14 +2,25 @@ import { ConfigFileOptions } from './options/ConfigOptions';
|
|
|
2
2
|
import { Result } from './runSequentially';
|
|
3
3
|
import { HandledError } from './services/HandledError';
|
|
4
4
|
import { Commit } from './services/sourceCommit/parseSourceCommit';
|
|
5
|
-
export declare type
|
|
5
|
+
export declare type BackportAbortResponse = {
|
|
6
|
+
status: 'aborted';
|
|
7
|
+
commits: Commit[];
|
|
8
|
+
error: HandledError;
|
|
9
|
+
};
|
|
10
|
+
export declare type BackportSuccessResponse = {
|
|
6
11
|
status: 'success';
|
|
7
12
|
commits: Commit[];
|
|
8
13
|
results: Result[];
|
|
9
|
-
}
|
|
14
|
+
};
|
|
15
|
+
export declare type BackportFailureResponse = {
|
|
10
16
|
status: 'failure';
|
|
11
17
|
commits: Commit[];
|
|
12
18
|
error: Error | HandledError;
|
|
13
19
|
errorMessage: string;
|
|
14
20
|
};
|
|
15
|
-
export declare
|
|
21
|
+
export declare type BackportResponse = BackportSuccessResponse | BackportFailureResponse | BackportAbortResponse;
|
|
22
|
+
export declare function backportRun({ processArgs, optionsFromModule, exitCodeOnFailure, }: {
|
|
23
|
+
processArgs: string[];
|
|
24
|
+
optionsFromModule?: ConfigFileOptions;
|
|
25
|
+
exitCodeOnFailure: boolean;
|
|
26
|
+
}): Promise<BackportResponse>;
|
package/dist/backportRun.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.backportRun = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
9
|
+
const cliArgs_1 = require("./options/cliArgs");
|
|
9
10
|
const options_1 = require("./options/options");
|
|
10
11
|
const runSequentially_1 = require("./runSequentially");
|
|
11
12
|
const HandledError_1 = require("./services/HandledError");
|
|
@@ -18,33 +19,45 @@ const getGitConfigAuthor_1 = require("./ui/getGitConfigAuthor");
|
|
|
18
19
|
const getTargetBranches_1 = require("./ui/getTargetBranches");
|
|
19
20
|
const ora_1 = require("./ui/ora");
|
|
20
21
|
const setupRepo_1 = require("./ui/setupRepo");
|
|
21
|
-
async function backportRun(processArgs, optionsFromModule = {}) {
|
|
22
|
+
async function backportRun({ processArgs, optionsFromModule = {}, exitCodeOnFailure, }) {
|
|
22
23
|
const argv = (0, yargs_parser_1.default)(processArgs);
|
|
23
24
|
const ci = argv.ci ?? optionsFromModule.ci;
|
|
24
25
|
const logFilePath = argv.logFilePath ?? optionsFromModule.logFilePath;
|
|
25
|
-
(0, logger_1.initLogger)({ ci, logFilePath });
|
|
26
|
-
// don't show spinner for yargs commands that exit the process without stopping the spinner first
|
|
27
|
-
const spinner = (0, ora_1.ora)(ci);
|
|
28
|
-
if (!argv.help && !argv.version && !argv.v) {
|
|
29
|
-
spinner.start('Initializing...');
|
|
30
|
-
}
|
|
26
|
+
const logger = (0, logger_1.initLogger)({ ci, logFilePath });
|
|
31
27
|
let options = null;
|
|
32
28
|
let commits = [];
|
|
33
29
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const spinner = (0, ora_1.ora)(ci);
|
|
31
|
+
try {
|
|
32
|
+
// don't show spinner for yargs commands that exit the process without stopping the spinner first
|
|
33
|
+
if (!argv.help && !argv.version && !argv.v) {
|
|
34
|
+
spinner.start('Initializing...');
|
|
35
|
+
}
|
|
36
|
+
options = await (0, options_1.getOptions)(processArgs, optionsFromModule);
|
|
37
|
+
logger.info('Backporting options', options);
|
|
38
|
+
spinner.stop();
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
spinner.stop();
|
|
42
|
+
if (e instanceof cliArgs_1.CliError) {
|
|
43
|
+
(0, logger_1.consoleLog)(e.message);
|
|
44
|
+
(0, logger_1.consoleLog)(`Run "backport --help" to see all options`);
|
|
45
|
+
return {
|
|
46
|
+
status: 'failure',
|
|
47
|
+
error: e,
|
|
48
|
+
errorMessage: e.message,
|
|
49
|
+
commits: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
37
54
|
commits = await (0, getCommits_1.getCommits)(options);
|
|
38
|
-
|
|
55
|
+
logger.info('Commits', commits);
|
|
39
56
|
if (options.ls) {
|
|
40
|
-
return {
|
|
41
|
-
status: 'success',
|
|
42
|
-
commits,
|
|
43
|
-
results: [],
|
|
44
|
-
};
|
|
57
|
+
return { status: 'success', commits, results: [] };
|
|
45
58
|
}
|
|
46
59
|
const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
47
|
-
|
|
60
|
+
logger.info('Target branches', targetBranches);
|
|
48
61
|
const [gitConfigAuthor] = await Promise.all([
|
|
49
62
|
(0, getGitConfigAuthor_1.getGitConfigAuthor)(options),
|
|
50
63
|
(0, setupRepo_1.setupRepo)(options),
|
|
@@ -55,37 +68,46 @@ async function backportRun(processArgs, optionsFromModule = {}) {
|
|
|
55
68
|
targetBranches,
|
|
56
69
|
gitConfigAuthor,
|
|
57
70
|
});
|
|
58
|
-
|
|
71
|
+
logger.info('Results', results);
|
|
59
72
|
const backportResponse = {
|
|
60
73
|
status: 'success',
|
|
61
74
|
commits,
|
|
62
75
|
results,
|
|
63
76
|
};
|
|
64
|
-
await (0, createStatusComment_1.createStatusComment)({
|
|
65
|
-
options,
|
|
66
|
-
backportResponse,
|
|
67
|
-
});
|
|
77
|
+
await (0, createStatusComment_1.createStatusComment)({ options, backportResponse });
|
|
68
78
|
return backportResponse;
|
|
69
79
|
}
|
|
70
80
|
catch (e) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
let backportResponse;
|
|
82
|
+
if (e instanceof HandledError_1.HandledError &&
|
|
83
|
+
e.errorContext.code === 'no-branches-exception') {
|
|
84
|
+
backportResponse = {
|
|
85
|
+
status: 'aborted',
|
|
86
|
+
commits,
|
|
87
|
+
error: e,
|
|
88
|
+
};
|
|
89
|
+
// this will catch both HandledError and Error
|
|
90
|
+
}
|
|
91
|
+
else if (e instanceof Error) {
|
|
92
|
+
backportResponse = {
|
|
93
|
+
status: 'failure',
|
|
94
|
+
commits,
|
|
95
|
+
error: e,
|
|
96
|
+
errorMessage: e.message,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
78
102
|
if (options) {
|
|
79
|
-
await (0, createStatusComment_1.createStatusComment)({
|
|
80
|
-
options,
|
|
81
|
-
backportResponse,
|
|
82
|
-
});
|
|
103
|
+
await (0, createStatusComment_1.createStatusComment)({ options, backportResponse });
|
|
83
104
|
}
|
|
84
|
-
|
|
85
|
-
|
|
105
|
+
outputError({ e, logFilePath });
|
|
106
|
+
// only change exit code for failures while in cli mode
|
|
107
|
+
if (exitCodeOnFailure && backportResponse.status === 'failure') {
|
|
108
|
+
process.exitCode = 1;
|
|
86
109
|
}
|
|
87
|
-
|
|
88
|
-
process.exitCode = 1;
|
|
110
|
+
logger.error('Unhandled exception', e);
|
|
89
111
|
return backportResponse;
|
|
90
112
|
}
|
|
91
113
|
}
|
package/dist/entrypoint.cli.js
CHANGED
|
@@ -7,7 +7,7 @@ const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
|
7
7
|
const backportRun_1 = require("./backportRun");
|
|
8
8
|
const processArgs = process.argv.slice(2);
|
|
9
9
|
// this is the entrypoint when running from command line
|
|
10
|
-
(0, backportRun_1.backportRun)(processArgs).then((backportResponse) => {
|
|
10
|
+
(0, backportRun_1.backportRun)({ processArgs, exitCodeOnFailure: true }).then((backportResponse) => {
|
|
11
11
|
const argv = (0, yargs_parser_1.default)(processArgs);
|
|
12
12
|
const { ci, ls } = argv;
|
|
13
13
|
if (ci || ls) {
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import { BackportResponse } from './backportRun';
|
|
1
2
|
import { ConfigFileOptions } from './options/ConfigOptions';
|
|
2
3
|
import { ValidConfigOptions } from './options/options';
|
|
3
4
|
import { Commit } from './services/sourceCommit/parseSourceCommit';
|
|
4
|
-
export { BackportResponse }
|
|
5
|
-
export { ConfigFileOptions } from './options/ConfigOptions';
|
|
5
|
+
export { BackportResponse };
|
|
6
6
|
export { Commit };
|
|
7
|
+
export { ConfigFileOptions } from './options/ConfigOptions';
|
|
7
8
|
export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
|
|
8
9
|
export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
|
|
9
|
-
export declare function backportRun(options
|
|
10
|
+
export declare function backportRun({ options, processArgs, exitCodeOnFailure, }: {
|
|
11
|
+
options: ConfigFileOptions;
|
|
12
|
+
processArgs?: string[];
|
|
13
|
+
exitCodeOnFailure?: boolean;
|
|
14
|
+
}): Promise<BackportResponse>;
|
|
10
15
|
export declare function getCommits(options: {
|
|
11
16
|
accessToken: string;
|
|
12
17
|
repoName: string;
|
|
@@ -13,16 +13,12 @@ var fetchRemoteProjectConfig_1 = require("./services/github/v4/fetchRemoteProjec
|
|
|
13
13
|
Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
|
|
14
14
|
var globalConfig_1 = require("./options/config/globalConfig");
|
|
15
15
|
Object.defineProperty(exports, "getLocalGlobalConfig", { enumerable: true, get: function () { return globalConfig_1.getGlobalConfig; } });
|
|
16
|
-
function backportRun(options,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// backportRun(options, args)
|
|
23
|
-
//
|
|
24
|
-
processArgs = []) {
|
|
25
|
-
return (0, backportRun_1.backportRun)(processArgs, (0, excludeUndefined_1.excludeUndefined)(options));
|
|
16
|
+
function backportRun({ options, processArgs = [], exitCodeOnFailure = true, }) {
|
|
17
|
+
return (0, backportRun_1.backportRun)({
|
|
18
|
+
optionsFromModule: (0, excludeUndefined_1.excludeUndefined)(options),
|
|
19
|
+
processArgs,
|
|
20
|
+
exitCodeOnFailure,
|
|
21
|
+
});
|
|
26
22
|
}
|
|
27
23
|
exports.backportRun = backportRun;
|
|
28
24
|
async function getCommits(options) {
|