backport 7.2.0-beta.2 → 7.3.0-beta.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 +10 -5
- package/dist/entrypoint.cli.d.ts +0 -1
- package/dist/entrypoint.cli.js +0 -1
- package/dist/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.private.test.js +47 -0
- package/dist/options/ConfigOptions.d.ts +2 -0
- package/dist/options/cliArgs.test.d.ts +1 -0
- package/dist/options/cliArgs.test.js +182 -0
- package/dist/options/config/config.d.ts +2 -0
- package/dist/options/config/config.test.d.ts +1 -0
- package/dist/options/config/config.test.js +32 -0
- package/dist/options/config/globalConfig.test.d.ts +1 -0
- package/dist/options/config/globalConfig.test.js +61 -0
- package/dist/options/config/projectConfig.test.d.ts +1 -0
- package/dist/options/config/projectConfig.test.js +109 -0
- package/dist/options/config/readConfigFile.d.ts +2 -0
- package/dist/options/options.d.ts +2 -0
- package/dist/options/options.test.d.ts +1 -0
- package/dist/options/options.test.js +384 -0
- package/dist/runSequentially.js +2 -2
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +243 -0
- package/dist/scripts/postinstall.test.d.ts +1 -0
- package/dist/scripts/postinstall.test.js +53 -0
- package/dist/services/env.test.d.ts +1 -0
- package/dist/services/env.test.js +21 -0
- package/dist/services/git.d.ts +11 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +286 -0
- package/dist/services/git.js +34 -16
- package/dist/services/git.test.d.ts +1 -0
- package/dist/services/git.test.js +543 -0
- package/dist/services/github/commitFormatters.test.d.ts +1 -0
- package/dist/services/github/commitFormatters.test.js +11 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +377 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +396 -0
- package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/services/github/v4/apiRequestV4.test.js +109 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +94 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +135 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +117 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +104 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +176 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +139 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -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.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +226 -0
- package/dist/test/ExecError.d.ts +16 -0
- package/dist/test/ExecError.js +15 -0
- package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/cli.private.test.js +215 -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/cli.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/cli.e2e.private.test.js +433 -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.d.ts +1 -0
- package/dist/test/e2e/module.e2e.private.test.js +369 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +56 -0
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +21 -0
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/nockHelpers.d.ts +16 -0
- package/dist/test/nockHelpers.js +36 -0
- package/dist/test/private/getDevAccessToken.d.ts +2 -0
- package/dist/test/private/getDevAccessToken.js +12 -0
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/test/sandbox.js +43 -0
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +63 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +469 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +331 -0
- package/dist/ui/getTargetBranches.test.d.ts +1 -0
- package/dist/ui/getTargetBranches.test.js +200 -0
- package/dist/ui/maybeSetupRepo.js +7 -3
- package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
- package/dist/ui/maybeSetupRepo.test.js +238 -0
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/ui/setupRepo.d.ts +3 -0
- package/dist/ui/setupRepo.js +88 -0
- package/dist/ui/setupRepo.test.d.ts +1 -0
- package/dist/ui/setupRepo.test.js +288 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +6 -6
- package/yarn.lock +3 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runBackportViaCli = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
|
+
const TIMEOUT_IN_SECONDS = 15;
|
|
12
|
+
jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
|
|
13
|
+
function runBackportViaCli(cliArgs, { showOra, waitForString, cwd, } = {}) {
|
|
14
|
+
const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
|
|
15
|
+
const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
|
|
16
|
+
const proc = (0, child_process_1.spawn)(tsNodeBinary, [
|
|
17
|
+
'--transpile-only',
|
|
18
|
+
entrypointFile,
|
|
19
|
+
'--log-file-path',
|
|
20
|
+
'/dev/null',
|
|
21
|
+
...cliArgs,
|
|
22
|
+
], { cwd });
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let data = '';
|
|
25
|
+
const timeoutSeconds = 2;
|
|
26
|
+
const rejectOnTimeout = (0, lodash_1.debounce)(() => {
|
|
27
|
+
reject(`Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${data.toString()}`);
|
|
28
|
+
}, timeoutSeconds * 1000, { maxWait: 15000 });
|
|
29
|
+
// fail if expectations hasn't been found within 10 seconds
|
|
30
|
+
const onChunk = (chunk) => {
|
|
31
|
+
data += chunk;
|
|
32
|
+
const stringfiedData = data.toString();
|
|
33
|
+
rejectOnTimeout();
|
|
34
|
+
// remove ansi codes and whitespace
|
|
35
|
+
const output = (0, strip_ansi_1.default)(stringfiedData).replace(/\s+$/gm, '');
|
|
36
|
+
if (!waitForString || output.includes(waitForString)) {
|
|
37
|
+
rejectOnTimeout.cancel();
|
|
38
|
+
resolve(output);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
proc.stdout.on('data', onChunk);
|
|
42
|
+
// ora (loading spinner) is redirected to stderr
|
|
43
|
+
if (showOra) {
|
|
44
|
+
proc.stderr.on('data', onChunk);
|
|
45
|
+
}
|
|
46
|
+
proc.on('error', (err) => {
|
|
47
|
+
reject(`runBackportViaCli failed with: ${err}`);
|
|
48
|
+
});
|
|
49
|
+
}).finally(() => {
|
|
50
|
+
proc.kill();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.runBackportViaCli = runBackportViaCli;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const child_process_promisified_1 = require("../../../services/child-process-promisified");
|
|
4
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
5
|
+
const sandbox_1 = require("../../sandbox");
|
|
6
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
7
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
8
|
+
describe('test-that-repo-can-be-cloned', () => {
|
|
9
|
+
describe('when local repo does not exist', () => {
|
|
10
|
+
let sandboxPath;
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
13
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
14
|
+
});
|
|
15
|
+
function run() {
|
|
16
|
+
return (0, runBackportViaCli_1.runBackportViaCli)([
|
|
17
|
+
'--repo=backport-org/test-that-repo-can-be-cloned',
|
|
18
|
+
'--branch=foo',
|
|
19
|
+
'--pr=1',
|
|
20
|
+
`--dir=${sandboxPath}`,
|
|
21
|
+
'--dry-run',
|
|
22
|
+
`--accessToken=${accessToken}`,
|
|
23
|
+
], { showOra: true, waitForString: 'Backporting to foo:' });
|
|
24
|
+
}
|
|
25
|
+
it('clones the repo remote repo', async () => {
|
|
26
|
+
const output = await run();
|
|
27
|
+
expect(output).toContain('Cloning repository from github.com');
|
|
28
|
+
expect(output).toMatchInlineSnapshot(`
|
|
29
|
+
"- Initializing...
|
|
30
|
+
? Select pull request Beginning of a beautiful repo (#1)
|
|
31
|
+
✔ 100% Cloning repository from github.com (one-time operation)
|
|
32
|
+
Backporting to foo:"
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
it('does not clone again on subsequent runs', async () => {
|
|
36
|
+
const output = await run();
|
|
37
|
+
expect(output).not.toContain('Cloning repository from github.com');
|
|
38
|
+
expect(output).toMatchInlineSnapshot(`
|
|
39
|
+
"- Initializing...
|
|
40
|
+
? Select pull request Beginning of a beautiful repo (#1)
|
|
41
|
+
Backporting to foo:"
|
|
42
|
+
`);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('when local repo exists', () => {
|
|
46
|
+
let sourceRepo;
|
|
47
|
+
let backportRepo;
|
|
48
|
+
beforeEach(async () => {
|
|
49
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
50
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
51
|
+
sourceRepo = `${sandboxPath}/source`;
|
|
52
|
+
backportRepo = `${sandboxPath}/backport`;
|
|
53
|
+
await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/test-that-repo-can-be-cloned.git ${sourceRepo}`, { cwd: sandboxPath });
|
|
54
|
+
});
|
|
55
|
+
function run() {
|
|
56
|
+
return (0, runBackportViaCli_1.runBackportViaCli)([
|
|
57
|
+
'--branch=foo',
|
|
58
|
+
'--pr=1',
|
|
59
|
+
`--dir=${backportRepo}`,
|
|
60
|
+
'--dry-run',
|
|
61
|
+
`--accessToken=${accessToken}`,
|
|
62
|
+
], {
|
|
63
|
+
cwd: sourceRepo,
|
|
64
|
+
showOra: true,
|
|
65
|
+
waitForString: 'Backporting to foo:',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
it('clones using the local repo', async () => {
|
|
69
|
+
const output = await run();
|
|
70
|
+
expect(output).toEqual(expect.stringMatching(/100% Cloning repository from .*\/src\/test\/_tmp_sandbox_\/test-that-repo-can-be-cloned.private.test\/source \(one-time operation\)/gm));
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const child_process_1 = require("child_process");
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
27
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
28
|
+
const child_process_promisified_1 = require("../../services/child-process-promisified");
|
|
29
|
+
const packageVersion = __importStar(require("../../utils/packageVersion"));
|
|
30
|
+
const getDevAccessToken_1 = require("../private/getDevAccessToken");
|
|
31
|
+
const sandbox_1 = require("../sandbox");
|
|
32
|
+
const TIMEOUT_IN_SECONDS = 15;
|
|
33
|
+
jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
|
|
34
|
+
const devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
35
|
+
describe('inquirer cli', () => {
|
|
36
|
+
it('--version', async () => {
|
|
37
|
+
const res = await runBackportViaCli([`--version`], {
|
|
38
|
+
showLoadingSpinner: true,
|
|
39
|
+
});
|
|
40
|
+
expect(res).toEqual(process.env.npm_package_version);
|
|
41
|
+
});
|
|
42
|
+
it('-v', async () => {
|
|
43
|
+
const res = await runBackportViaCli([`-v`], {
|
|
44
|
+
showLoadingSpinner: true,
|
|
45
|
+
});
|
|
46
|
+
expect(res).toEqual(process.env.npm_package_version);
|
|
47
|
+
});
|
|
48
|
+
it('PACKAGE_VERSION should match', async () => {
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
|
|
51
|
+
});
|
|
52
|
+
it('--help', async () => {
|
|
53
|
+
const res = await runBackportViaCli([`--help`]);
|
|
54
|
+
expect(res).toMatchInlineSnapshot(`
|
|
55
|
+
"entrypoint.cli.ts [args]
|
|
56
|
+
Options:
|
|
57
|
+
-v, -V, --version Show version number [boolean]
|
|
58
|
+
--accessToken, --accesstoken Github access token [string]
|
|
59
|
+
-a, --all List all commits [boolean]
|
|
60
|
+
--assignee, --assign Add assignees to the target pull request [array]
|
|
61
|
+
--autoAssign Auto assign the target pull request to yourself [boolean]
|
|
62
|
+
--autoMerge Enable auto-merge for created pull requests [boolean]
|
|
63
|
+
--autoMergeMethod Sets auto-merge method when using --auto-merge. Default:
|
|
64
|
+
merge [string] [choices: \\"merge\\", \\"rebase\\", \\"squash\\"]
|
|
65
|
+
--ci Disable interactive prompts [boolean]
|
|
66
|
+
--cherrypickRef Append commit message with \\"(cherry picked from commit...)
|
|
67
|
+
[boolean]
|
|
68
|
+
--configFile, --config Path to project config [string]
|
|
69
|
+
--since ISO-8601 date for filtering commits [string]
|
|
70
|
+
--until ISO-8601 date for filtering commits [string]
|
|
71
|
+
--dir Location where the temporary repository will be stored
|
|
72
|
+
[string]
|
|
73
|
+
--details Show details about each commit [boolean]
|
|
74
|
+
--dryRun Run backport locally without pushing to Github [boolean]
|
|
75
|
+
--editor Editor to be opened during conflict resolution [string]
|
|
76
|
+
--skipRemoteConfig Use local .backportrc.json config instead of loading from
|
|
77
|
+
Github [boolean]
|
|
78
|
+
--fork Create backports in fork or origin repo [boolean]
|
|
79
|
+
--mainline Parent id of merge commit. Defaults to 1 when supplied
|
|
80
|
+
without arguments [number]
|
|
81
|
+
-n, --maxNumber, --number Number of commits to choose from [number]
|
|
82
|
+
--multiple Select multiple branches/commits [boolean]
|
|
83
|
+
--multipleBranches Backport to multiple branches [boolean]
|
|
84
|
+
--multipleCommits Backport multiple commits [boolean]
|
|
85
|
+
--noCherrypickRef Do not append commit message with \\"(cherry picked from
|
|
86
|
+
commit...)\\" [boolean]
|
|
87
|
+
--noStatusComment Don't publish status comment to Github [boolean]
|
|
88
|
+
--noVerify Bypass the pre-commit and commit-msg hooks [boolean]
|
|
89
|
+
--noFork Create backports in the origin repo [boolean]
|
|
90
|
+
-p, --path Only list commits touching files under the specified path
|
|
91
|
+
[array]
|
|
92
|
+
--prDescription, --description Description to be added to pull request [string]
|
|
93
|
+
--prTitle, --title Title of pull request [string]
|
|
94
|
+
--prFilter Filter source pull requests by a query [string]
|
|
95
|
+
--pullNumber, --pr Pull request to backport [number]
|
|
96
|
+
--resetAuthor Set yourself as commit author [boolean]
|
|
97
|
+
--reviewer Add reviewer to the target PR [array]
|
|
98
|
+
--repoOwner Repository owner [string]
|
|
99
|
+
--repoName Repository name [string]
|
|
100
|
+
--repo Repo owner and name [string]
|
|
101
|
+
--sha, --commit Commit sha to backport [string]
|
|
102
|
+
--sourceBranch Specify a non-default branch (normally \\"master\\") to backport
|
|
103
|
+
from [string]
|
|
104
|
+
--sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
|
|
105
|
+
-b, --targetBranch, --branch Branch(es) to backport to [array]
|
|
106
|
+
--targetBranchChoice List branches to backport to [array]
|
|
107
|
+
-l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
|
|
108
|
+
--username Defaults to the authenticated user [string]
|
|
109
|
+
--verbose Show additional debug information [boolean]
|
|
110
|
+
--verify Opposite of no-verify [boolean]
|
|
111
|
+
--help Show help [boolean]
|
|
112
|
+
For bugs, feature requests or questions: https://github.com/sqren/backport/issues
|
|
113
|
+
Or contact me directly: https://twitter.com/sorenlouv"
|
|
114
|
+
`);
|
|
115
|
+
});
|
|
116
|
+
it('should return error when branch is missing', async () => {
|
|
117
|
+
const res = await runBackportViaCli([
|
|
118
|
+
'--skip-remote-config',
|
|
119
|
+
'--repo-owner',
|
|
120
|
+
'backport-org',
|
|
121
|
+
'--repo-name',
|
|
122
|
+
'backport-e2e',
|
|
123
|
+
'--accessToken',
|
|
124
|
+
devAccessToken,
|
|
125
|
+
]);
|
|
126
|
+
expect(res).toMatchInlineSnapshot(`
|
|
127
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
128
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
129
|
+
`);
|
|
130
|
+
});
|
|
131
|
+
it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
|
|
132
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
133
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
134
|
+
await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
|
|
135
|
+
await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
|
|
136
|
+
const res = await runBackportViaCli(['--accessToken', devAccessToken], {
|
|
137
|
+
cwd: sandboxPath,
|
|
138
|
+
waitForString: 'Select commit',
|
|
139
|
+
});
|
|
140
|
+
expect(res).toMatchInlineSnapshot(`
|
|
141
|
+
"? Select commit (Use arrow keys)
|
|
142
|
+
❯ 1. Add sheep emoji (#9) 7.8
|
|
143
|
+
2. Change Ulysses to Gretha (conflict) (#8) 7.x
|
|
144
|
+
3. Add 🍏 emoji (#5) 7.x, 7.8
|
|
145
|
+
4. Add family emoji (#2) 7.x
|
|
146
|
+
5. Add \`backport\` dep
|
|
147
|
+
6. Merge pull request #1 from backport-org/add-heart-emoji
|
|
148
|
+
7. Add ❤️ emoji
|
|
149
|
+
8. Update .backportrc.json
|
|
150
|
+
9. Bump to 8.0.0
|
|
151
|
+
10.Add package.json"
|
|
152
|
+
`);
|
|
153
|
+
});
|
|
154
|
+
it('should return error when access token is invalid', async () => {
|
|
155
|
+
const res = await runBackportViaCli([
|
|
156
|
+
'--branch',
|
|
157
|
+
'foo',
|
|
158
|
+
'--repo-owner',
|
|
159
|
+
'foo',
|
|
160
|
+
'--repo-name',
|
|
161
|
+
'bar',
|
|
162
|
+
'--accessToken',
|
|
163
|
+
'some-token',
|
|
164
|
+
]);
|
|
165
|
+
expect(res).toContain('Please check your access token and make sure it is valid');
|
|
166
|
+
});
|
|
167
|
+
it(`should return error when repo doesn't exist`, async () => {
|
|
168
|
+
const res = await runBackportViaCli([
|
|
169
|
+
'--branch',
|
|
170
|
+
'foo',
|
|
171
|
+
'--repo-owner',
|
|
172
|
+
'foo',
|
|
173
|
+
'--repo-name',
|
|
174
|
+
'bar',
|
|
175
|
+
'--author',
|
|
176
|
+
'sqren',
|
|
177
|
+
'--accessToken',
|
|
178
|
+
devAccessToken,
|
|
179
|
+
]);
|
|
180
|
+
expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
|
|
181
|
+
});
|
|
182
|
+
it(`should list commits from master`, async () => {
|
|
183
|
+
const output = await runBackportViaCli([
|
|
184
|
+
'--branch',
|
|
185
|
+
'foo',
|
|
186
|
+
'--repo-owner',
|
|
187
|
+
'backport-org',
|
|
188
|
+
'--repo-name',
|
|
189
|
+
'backport-e2e',
|
|
190
|
+
'--author',
|
|
191
|
+
'sqren',
|
|
192
|
+
'--accessToken',
|
|
193
|
+
devAccessToken,
|
|
194
|
+
'--max-number',
|
|
195
|
+
'6',
|
|
196
|
+
], { waitForString: 'Select commit' });
|
|
197
|
+
expect(output).toMatchInlineSnapshot(`
|
|
198
|
+
"? Select commit (Use arrow keys)
|
|
199
|
+
❯ 1. Add sheep emoji (#9) 7.8
|
|
200
|
+
2. Change Ulysses to Gretha (conflict) (#8) 7.x
|
|
201
|
+
3. Add 🍏 emoji (#5) 7.x, 7.8
|
|
202
|
+
4. Add family emoji (#2) 7.x
|
|
203
|
+
5. Add \`backport\` dep
|
|
204
|
+
6. Merge pull request #1 from backport-org/add-heart-emoji"
|
|
205
|
+
`);
|
|
206
|
+
});
|
|
207
|
+
it(`should filter commits by "since" and "until"`, async () => {
|
|
208
|
+
const output = await runBackportViaCli([
|
|
209
|
+
'--branch',
|
|
210
|
+
'foo',
|
|
211
|
+
'--repo-owner',
|
|
212
|
+
'backport-org',
|
|
213
|
+
'--repo-name',
|
|
214
|
+
'backport-e2e',
|
|
215
|
+
'--accessToken',
|
|
216
|
+
devAccessToken,
|
|
217
|
+
'--since',
|
|
218
|
+
'2020-08-15T10:00:00.000Z',
|
|
219
|
+
'--until',
|
|
220
|
+
'2020-08-15T10:30:00.000Z',
|
|
221
|
+
], { waitForString: 'Select commit' });
|
|
222
|
+
expect(output).toMatchInlineSnapshot(`
|
|
223
|
+
"? Select commit (Use arrow keys)
|
|
224
|
+
❯ 1. Bump to 8.0.0
|
|
225
|
+
2. Add package.json
|
|
226
|
+
3. Update .backportrc.json
|
|
227
|
+
4. Create .backportrc.json"
|
|
228
|
+
`);
|
|
229
|
+
});
|
|
230
|
+
it(`should list commits from 7.x`, async () => {
|
|
231
|
+
const output = await runBackportViaCli([
|
|
232
|
+
'--branch',
|
|
233
|
+
'foo',
|
|
234
|
+
'--repo-owner',
|
|
235
|
+
'backport-org',
|
|
236
|
+
'--repo-name',
|
|
237
|
+
'backport-e2e',
|
|
238
|
+
'--author',
|
|
239
|
+
'sqren',
|
|
240
|
+
'--accessToken',
|
|
241
|
+
devAccessToken,
|
|
242
|
+
'--max-number',
|
|
243
|
+
'6',
|
|
244
|
+
'--source-branch',
|
|
245
|
+
'7.x',
|
|
246
|
+
], { waitForString: 'Select commit' });
|
|
247
|
+
expect(output).toMatchInlineSnapshot(`
|
|
248
|
+
"? Select commit (Use arrow keys)
|
|
249
|
+
❯ 1. Add 🍏 emoji (#5) (#6)
|
|
250
|
+
2. Change Ulysses to Carol
|
|
251
|
+
3. Add family emoji (#2) (#4)
|
|
252
|
+
4. Update .backportrc.json
|
|
253
|
+
5. Branch off: 7.9.0 (7.x)
|
|
254
|
+
6. Bump to 8.0.0"
|
|
255
|
+
`);
|
|
256
|
+
});
|
|
257
|
+
describe('repo: repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
|
|
258
|
+
it('should list commits', async () => {
|
|
259
|
+
const output = await runBackportViaCli([
|
|
260
|
+
'--branch',
|
|
261
|
+
'foo',
|
|
262
|
+
'--repo',
|
|
263
|
+
'backport-org/repo-with-backportrc-removed',
|
|
264
|
+
'--accessToken',
|
|
265
|
+
devAccessToken,
|
|
266
|
+
], { waitForString: 'Select commit' });
|
|
267
|
+
expect(output).toMatchInlineSnapshot(`
|
|
268
|
+
"? Select commit (Use arrow keys)
|
|
269
|
+
❯ 1. Rename README.me to README.md
|
|
270
|
+
2. Merge pull request #1 from backport-org/add-readme
|
|
271
|
+
3. Create README.me
|
|
272
|
+
4. Delete .backportrc.json
|
|
273
|
+
5. Create .backportrc.json
|
|
274
|
+
6. Delete .backportrc.json
|
|
275
|
+
7. Create .backportrc.json"
|
|
276
|
+
`);
|
|
277
|
+
});
|
|
278
|
+
it('should attempt to backport by PR', async () => {
|
|
279
|
+
const output = await runBackportViaCli([
|
|
280
|
+
'--branch',
|
|
281
|
+
'foo',
|
|
282
|
+
'--repo',
|
|
283
|
+
'backport-org/repo-with-backportrc-removed',
|
|
284
|
+
'--pr',
|
|
285
|
+
'1',
|
|
286
|
+
'--accessToken',
|
|
287
|
+
devAccessToken,
|
|
288
|
+
], { waitForString: "is invalid or doesn't exist" });
|
|
289
|
+
expect(output).toMatchInlineSnapshot(`
|
|
290
|
+
"
|
|
291
|
+
Backporting to foo:
|
|
292
|
+
The branch \\"foo\\" is invalid or doesn't exist"
|
|
293
|
+
`);
|
|
294
|
+
});
|
|
295
|
+
it('should attempt to backport by commit sha', async () => {
|
|
296
|
+
const output = await runBackportViaCli([
|
|
297
|
+
'--branch',
|
|
298
|
+
'foo',
|
|
299
|
+
'--repo',
|
|
300
|
+
'backport-org/repo-with-backportrc-removed',
|
|
301
|
+
'--sha',
|
|
302
|
+
'be59df6912a550c8cb49ba3e18be3e512f3d608c',
|
|
303
|
+
'--accessToken',
|
|
304
|
+
devAccessToken,
|
|
305
|
+
], { waitForString: `Backporting to foo:` });
|
|
306
|
+
expect(output).toMatchInlineSnapshot(`
|
|
307
|
+
"
|
|
308
|
+
Backporting to foo:"
|
|
309
|
+
`);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
describe('repo: different-merge-strategies', () => {
|
|
313
|
+
it('list all commits regardless how they were merged', async () => {
|
|
314
|
+
const output = await runBackportViaCli([
|
|
315
|
+
'--branch',
|
|
316
|
+
'foo',
|
|
317
|
+
'--repo-owner',
|
|
318
|
+
'backport-org',
|
|
319
|
+
'--repo-name',
|
|
320
|
+
'different-merge-strategies',
|
|
321
|
+
'--accessToken',
|
|
322
|
+
devAccessToken,
|
|
323
|
+
'-n',
|
|
324
|
+
'20',
|
|
325
|
+
], { waitForString: 'Select commit' });
|
|
326
|
+
expect(output).toMatchInlineSnapshot(`
|
|
327
|
+
"? Select commit (Use arrow keys)
|
|
328
|
+
❯ 1. Merge pull request #9 from backport-org/many-merge-commits
|
|
329
|
+
2. Merge strategy: Eighth of many merges
|
|
330
|
+
3. Merge strategy: Seventh of many merges
|
|
331
|
+
4. Merge strategy: Sixth of many merges
|
|
332
|
+
5. Merge strategy: Fifth of many merges
|
|
333
|
+
6. Merge strategy: Fourth of many merges
|
|
334
|
+
7. Merge strategy: Third of many merges
|
|
335
|
+
8. Merge strategy: Second of many merges
|
|
336
|
+
9. Merge strategy: First of many merges
|
|
337
|
+
10.Using squash to merge commits (#3) 7.x
|
|
338
|
+
11.Rebase strategy: Second commit 7.x
|
|
339
|
+
12.Rebase strategy: First commit
|
|
340
|
+
13.Merge pull request #1 from backport-org/merge-strategy
|
|
341
|
+
14.Merge strategy: Second commit
|
|
342
|
+
15.Merge strategy: First commit
|
|
343
|
+
16.Initial commit"
|
|
344
|
+
`);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
describe('repo: test-that-repo-can-be-cloned', () => {
|
|
348
|
+
let sandboxPath;
|
|
349
|
+
beforeAll(async () => {
|
|
350
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
351
|
+
filename: __filename,
|
|
352
|
+
specname: 'test-cloning',
|
|
353
|
+
});
|
|
354
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
355
|
+
});
|
|
356
|
+
function run() {
|
|
357
|
+
return runBackportViaCli([
|
|
358
|
+
'--repo',
|
|
359
|
+
'backport-org/test-that-repo-can-be-cloned',
|
|
360
|
+
'--branch',
|
|
361
|
+
'foo',
|
|
362
|
+
'--pr',
|
|
363
|
+
'1',
|
|
364
|
+
'--dir',
|
|
365
|
+
sandboxPath,
|
|
366
|
+
'--dry-run',
|
|
367
|
+
'--accessToken',
|
|
368
|
+
devAccessToken,
|
|
369
|
+
], { showLoadingSpinner: true, waitForString: 'Backporting to foo:' });
|
|
370
|
+
}
|
|
371
|
+
it('clones the repo on the very first run', async () => {
|
|
372
|
+
const output = await run();
|
|
373
|
+
expect(output).toContain('Cloning repository from github.com');
|
|
374
|
+
expect(output).toMatchInlineSnapshot(`
|
|
375
|
+
"- Initializing...
|
|
376
|
+
? Select pull request Beginning of a beautiful repo (#1)
|
|
377
|
+
✔ 100% Cloning repository from github.com (one-time operation)
|
|
378
|
+
Backporting to foo:"
|
|
379
|
+
`);
|
|
380
|
+
});
|
|
381
|
+
it('does not clone the repo on subsequent runs', async () => {
|
|
382
|
+
const output = await run();
|
|
383
|
+
expect(output).not.toContain('Cloning repository from github.com');
|
|
384
|
+
expect(output).toMatchInlineSnapshot(`
|
|
385
|
+
"- Initializing...
|
|
386
|
+
? Select pull request Beginning of a beautiful repo (#1)
|
|
387
|
+
Backporting to foo:"
|
|
388
|
+
`);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
function runBackportViaCli(cliArgs, { showLoadingSpinner, waitForString, cwd, } = {}) {
|
|
393
|
+
const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
|
|
394
|
+
const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
|
|
395
|
+
const proc = (0, child_process_1.spawn)(tsNodeBinary, [
|
|
396
|
+
'--transpile-only',
|
|
397
|
+
entrypointFile,
|
|
398
|
+
'--log-file-path',
|
|
399
|
+
'/dev/null',
|
|
400
|
+
...cliArgs,
|
|
401
|
+
], { cwd });
|
|
402
|
+
const p = new Promise((resolve, reject) => {
|
|
403
|
+
let data = '';
|
|
404
|
+
// fail if expectations hasn't been found within 10 seconds
|
|
405
|
+
const timeout = setTimeout(() => {
|
|
406
|
+
reject(`Expectation '${waitForString}' not found within ${TIMEOUT_IN_SECONDS} seconds in:
|
|
407
|
+
'${data.toString()}'`);
|
|
408
|
+
}, TIMEOUT_IN_SECONDS * 1000);
|
|
409
|
+
proc.stdout.on('data', (chunk) => {
|
|
410
|
+
data += chunk;
|
|
411
|
+
const rawOutput = data.toString();
|
|
412
|
+
// remove ansi codes and whitespace
|
|
413
|
+
const output = (0, strip_ansi_1.default)(rawOutput).replace(/\s+$/gm, '');
|
|
414
|
+
if (!waitForString || output.includes(waitForString)) {
|
|
415
|
+
clearTimeout(timeout);
|
|
416
|
+
resolve(output);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
// ora (loading spinner) is redirected to stderr
|
|
420
|
+
if (showLoadingSpinner) {
|
|
421
|
+
proc.stderr.on('data', (chunk) => {
|
|
422
|
+
data += chunk;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
proc.on('error', (err) => {
|
|
426
|
+
reject(`runBackportViaCli failed with: ${err}`);
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
// kill child process
|
|
430
|
+
return p.finally(() => {
|
|
431
|
+
proc.kill();
|
|
432
|
+
});
|
|
433
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|