backport 7.4.0 → 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 +12 -13
- package/dist/backportRun.d.ts +8 -3
- package/dist/backportRun.js +54 -42
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +8 -3
- package/dist/entrypoint.module.js +3 -11
- package/dist/entrypoint.module.private.test.js +47 -346
- package/dist/options/cliArgs.d.ts +9 -4
- package/dist/options/cliArgs.js +28 -15
- package/dist/options/cliArgs.test.js +3 -3
- package/dist/options/config/globalConfig.d.ts +2 -2
- package/dist/options/config/globalConfig.js +13 -10
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/options.d.ts +3 -3
- package/dist/options/options.test.js +5 -1
- package/dist/runSequentially.d.ts +6 -2
- package/dist/runSequentially.js +23 -7
- package/dist/scripts/postinstall.js +1 -0
- package/dist/scripts/postinstall.test.js +5 -1
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/HandledError.js +2 -2
- 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 -122
- 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 -124
- 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 +14 -15
- package/dist/services/github/v3/createStatusComment.test.js +15 -5
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
- package/dist/services/logger.js +5 -1
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +194 -12
- 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.js +26 -19
- package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -8
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +5 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +1 -1
- 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
|
@@ -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);
|
package/dist/backportRun.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ 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 BackportAbortResponse = {
|
|
6
|
+
status: 'aborted';
|
|
7
|
+
commits: Commit[];
|
|
8
|
+
error: HandledError;
|
|
9
|
+
};
|
|
5
10
|
export declare type BackportSuccessResponse = {
|
|
6
11
|
status: 'success';
|
|
7
12
|
commits: Commit[];
|
|
@@ -13,9 +18,9 @@ export declare type BackportFailureResponse = {
|
|
|
13
18
|
error: Error | HandledError;
|
|
14
19
|
errorMessage: string;
|
|
15
20
|
};
|
|
16
|
-
export declare type BackportResponse = BackportSuccessResponse | BackportFailureResponse;
|
|
17
|
-
export declare function backportRun({ processArgs, optionsFromModule,
|
|
21
|
+
export declare type BackportResponse = BackportSuccessResponse | BackportFailureResponse | BackportAbortResponse;
|
|
22
|
+
export declare function backportRun({ processArgs, optionsFromModule, exitCodeOnFailure, }: {
|
|
18
23
|
processArgs: string[];
|
|
19
24
|
optionsFromModule?: ConfigFileOptions;
|
|
20
|
-
|
|
25
|
+
exitCodeOnFailure: boolean;
|
|
21
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,31 +19,42 @@ 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
|
-
const ls = argv.ls ?? optionsFromModule.ls;
|
|
25
25
|
const logFilePath = argv.logFilePath ?? optionsFromModule.logFilePath;
|
|
26
26
|
const logger = (0, logger_1.initLogger)({ ci, logFilePath });
|
|
27
|
-
const spinner = (0, ora_1.ora)(ci);
|
|
28
|
-
// don't show spinner for yargs commands that exit the process without stopping the spinner first
|
|
29
|
-
if (!argv.help && !argv.version && !argv.v) {
|
|
30
|
-
spinner.start('Initializing...');
|
|
31
|
-
}
|
|
32
27
|
let options = null;
|
|
33
28
|
let commits = [];
|
|
34
29
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
}
|
|
38
54
|
commits = await (0, getCommits_1.getCommits)(options);
|
|
39
55
|
logger.info('Commits', commits);
|
|
40
56
|
if (options.ls) {
|
|
41
|
-
return {
|
|
42
|
-
status: 'success',
|
|
43
|
-
commits,
|
|
44
|
-
results: [],
|
|
45
|
-
};
|
|
57
|
+
return { status: 'success', commits, results: [] };
|
|
46
58
|
}
|
|
47
59
|
const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
48
60
|
logger.info('Target branches', targetBranches);
|
|
@@ -62,33 +74,40 @@ async function backportRun({ processArgs, optionsFromModule = {}, isCliMode, })
|
|
|
62
74
|
commits,
|
|
63
75
|
results,
|
|
64
76
|
};
|
|
65
|
-
await (0, createStatusComment_1.createStatusComment)({
|
|
66
|
-
options,
|
|
67
|
-
backportResponse,
|
|
68
|
-
});
|
|
77
|
+
await (0, createStatusComment_1.createStatusComment)({ options, backportResponse });
|
|
69
78
|
return backportResponse;
|
|
70
79
|
}
|
|
71
80
|
catch (e) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
};
|
|
84
98
|
}
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
else {
|
|
100
|
+
throw e;
|
|
87
101
|
}
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
if (options) {
|
|
103
|
+
await (0, createStatusComment_1.createStatusComment)({ options, backportResponse });
|
|
104
|
+
}
|
|
105
|
+
outputError({ e, logFilePath });
|
|
106
|
+
// only change exit code for failures while in cli mode
|
|
107
|
+
if (exitCodeOnFailure && backportResponse.status === 'failure') {
|
|
90
108
|
process.exitCode = 1;
|
|
91
109
|
}
|
|
110
|
+
logger.error('Unhandled exception', e);
|
|
92
111
|
return backportResponse;
|
|
93
112
|
}
|
|
94
113
|
}
|
|
@@ -109,10 +128,3 @@ function outputError({ e, logFilePath, }) {
|
|
|
109
128
|
})}`));
|
|
110
129
|
}
|
|
111
130
|
}
|
|
112
|
-
function isCriticalError(e) {
|
|
113
|
-
if (e instanceof HandledError_1.HandledError &&
|
|
114
|
-
e.errorContext.code === 'no-branches-exception') {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
|
-
}
|
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,
|
|
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,19 +13,11 @@ 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
|
-
// cli args will not automatically be forwarded when it is consumed as a module
|
|
18
|
-
// It is simple to forward args manually via `process.argv`:
|
|
19
|
-
//
|
|
20
|
-
// import { backportRun } from `backport
|
|
21
|
-
// const args = process.argv.slice(2);
|
|
22
|
-
// backportRun(options, args)
|
|
23
|
-
//
|
|
24
|
-
processArgs = []) {
|
|
16
|
+
function backportRun({ options, processArgs = [], exitCodeOnFailure = true, }) {
|
|
25
17
|
return (0, backportRun_1.backportRun)({
|
|
26
|
-
processArgs,
|
|
27
18
|
optionsFromModule: (0, excludeUndefined_1.excludeUndefined)(options),
|
|
28
|
-
|
|
19
|
+
processArgs,
|
|
20
|
+
exitCodeOnFailure,
|
|
29
21
|
});
|
|
30
22
|
}
|
|
31
23
|
exports.backportRun = backportRun;
|