backport 7.0.1 → 7.2.0-beta.3
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/dist/backportRun.d.ts +1 -0
- package/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.js +12 -1
- package/dist/entrypoint.module.d.ts +4 -3
- package/dist/entrypoint.module.js +2 -7
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/cliArgs.d.ts +2 -1
- package/dist/options/cliArgs.js +4 -0
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/options.d.ts +3 -6
- package/dist/options/options.test.js +26 -28
- package/dist/runSequentially.js +1 -0
- package/dist/runSequentially.test.js +55 -30
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.d.ts +3 -3
- package/dist/services/git.integration.test.js +66 -13
- package/dist/services/git.js +52 -13
- package/dist/services/git.test.js +15 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
- package/dist/services/github/v3/createPullRequest.js +2 -5
- package/dist/services/github/v3/createStatusComment.js +1 -1
- package/dist/services/github/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
- package/dist/services/github/v4/apiRequestV4.js +22 -21
- package/dist/services/github/v4/apiRequestV4.test.js +38 -11
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
- package/dist/services/github/v4/fetchAuthorId.js +5 -1
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +24 -13
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +3 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +24 -13
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -11
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +20 -10
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +7 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +20 -9
- package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -5
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -19
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +2 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/logger.d.ts +5 -5
- package/dist/services/logger.js +24 -23
- package/dist/services/remoteConfig.d.ts +20 -0
- package/dist/services/remoteConfig.js +52 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +73 -39
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
- package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
- package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
- package/dist/{entrypoint.cli.e2e.private.test.d.ts → test/e2e/cli.e2e.private.test.d.ts} +0 -0
- package/dist/{entrypoint.cli.e2e.private.test.js → test/e2e/cli.e2e.private.test.js} +153 -39
- package/dist/{services/github/v3/index.d.ts → test/e2e/module.e2e.private.test.d.ts} +0 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -2
- package/dist/test/nockHelpers.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -2
- package/dist/ui/getCommits.js +8 -6
- package/dist/ui/maybeSetupRepo.js +13 -16
- package/dist/ui/maybeSetupRepo.test.js +50 -16
- package/dist/ui/ora.d.ts +9 -0
- package/dist/ui/ora.js +21 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +10 -10
- package/yarn.lock +121 -114
- package/dist/services/github/v3/index.js +0 -61
- package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
- package/dist/test/backport-e2e.mutation.test.js +0 -347
package/dist/test/nockHelpers.js
CHANGED
|
@@ -6,18 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.listenForCallsToNockScope = exports.mockGqlRequest = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
9
|
+
const graphql_tag_2 = require("graphql-tag");
|
|
9
10
|
const nock_1 = __importDefault(require("nock"));
|
|
11
|
+
(0, graphql_tag_2.disableFragmentWarnings)();
|
|
10
12
|
function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
|
|
11
13
|
const { origin, pathname } = new url_1.URL(
|
|
12
14
|
// default to localhost as host to avoid CORS issues
|
|
13
15
|
apiBaseUrl ?? 'http://localhost/graphql');
|
|
14
16
|
const scope = (0, nock_1.default)(origin)
|
|
15
|
-
.post(pathname, (body) =>
|
|
17
|
+
.post(pathname, (body) => {
|
|
18
|
+
return getQueryNameFromString(body.query) === name;
|
|
19
|
+
})
|
|
16
20
|
.reply(statusCode, body, headers);
|
|
17
21
|
return listenForCallsToNockScope(scope);
|
|
18
22
|
}
|
|
19
23
|
exports.mockGqlRequest = mockGqlRequest;
|
|
20
|
-
function
|
|
24
|
+
function getQueryNameFromString(query) {
|
|
21
25
|
const obj = (0, graphql_tag_1.default)(query);
|
|
22
26
|
// @ts-expect-error
|
|
23
27
|
return obj.definitions[0].name.value;
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.cherrypickAndCreateTargetPullRequest = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
|
-
const ora = require("ora");
|
|
10
9
|
const HandledError_1 = require("../services/HandledError");
|
|
11
10
|
const child_process_promisified_1 = require("../services/child-process-promisified");
|
|
12
11
|
const env_1 = require("../services/env");
|
|
@@ -21,10 +20,22 @@ const logger_1 = require("../services/logger");
|
|
|
21
20
|
const prompts_1 = require("../services/prompts");
|
|
22
21
|
const sequentially_1 = require("../services/sequentially");
|
|
23
22
|
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
23
|
+
const ora_1 = require("./ora");
|
|
24
24
|
async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
|
|
25
25
|
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
26
26
|
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
27
27
|
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
28
|
+
await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
|
|
29
|
+
await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
|
|
30
|
+
if (options.resetAuthor) {
|
|
31
|
+
await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
|
|
32
|
+
}
|
|
33
|
+
if (options.dryRun) {
|
|
34
|
+
(0, ora_1.ora)(options.ci).succeed('Dry run');
|
|
35
|
+
return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
|
|
36
|
+
}
|
|
37
|
+
await (0, git_1.pushBackportBranch)({ options, backportBranch });
|
|
38
|
+
await (0, git_1.deleteBackportBranch)({ options, backportBranch });
|
|
28
39
|
const prPayload = {
|
|
29
40
|
owner: options.repoOwner,
|
|
30
41
|
repo: options.repoName,
|
|
@@ -33,13 +44,7 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
33
44
|
head: `${repoForkOwner}:${backportBranch}`,
|
|
34
45
|
base: targetBranch, // eg. 7.x
|
|
35
46
|
};
|
|
36
|
-
const targetPullRequest = await
|
|
37
|
-
options,
|
|
38
|
-
prPayload,
|
|
39
|
-
targetBranch,
|
|
40
|
-
backportBranch,
|
|
41
|
-
commits,
|
|
42
|
-
});
|
|
47
|
+
const targetPullRequest = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
43
48
|
// add assignees to target pull request
|
|
44
49
|
const assignees = options.autoAssign
|
|
45
50
|
? [options.authenticatedUsername]
|
|
@@ -72,17 +77,6 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
72
77
|
return targetPullRequest;
|
|
73
78
|
}
|
|
74
79
|
exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequest;
|
|
75
|
-
async function backportViaFilesystem({ options, prPayload, commits, targetBranch, backportBranch, }) {
|
|
76
|
-
logger_1.logger.info('Backporting via filesystem');
|
|
77
|
-
await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
|
|
78
|
-
await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
|
|
79
|
-
if (options.resetAuthor) {
|
|
80
|
-
await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
|
|
81
|
-
}
|
|
82
|
-
await (0, git_1.pushBackportBranch)({ options, backportBranch });
|
|
83
|
-
await (0, git_1.deleteBackportBranch)({ options, backportBranch });
|
|
84
|
-
return (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
85
|
-
}
|
|
86
80
|
/*
|
|
87
81
|
* Returns the name of the backport branch without remote name
|
|
88
82
|
*
|
|
@@ -103,7 +97,7 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
103
97
|
async function waitForCherrypick(options, commit, targetBranch) {
|
|
104
98
|
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
105
99
|
const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
106
|
-
const cherrypickSpinner = ora(spinnerText).start();
|
|
100
|
+
const cherrypickSpinner = (0, ora_1.ora)(options.ci, spinnerText).start();
|
|
107
101
|
let conflictingFiles;
|
|
108
102
|
let unstagedFiles;
|
|
109
103
|
let needsResolving;
|
|
@@ -124,7 +118,7 @@ async function waitForCherrypick(options, commit, targetBranch) {
|
|
|
124
118
|
}
|
|
125
119
|
// resolve conflicts automatically
|
|
126
120
|
if (options.autoFixConflicts) {
|
|
127
|
-
const autoResolveSpinner = ora('Attempting to resolve conflicts automatically').start();
|
|
121
|
+
const autoResolveSpinner = (0, ora_1.ora)(options.ci, 'Attempting to resolve conflicts automatically').start();
|
|
128
122
|
const repoPath = (0, env_1.getRepoPath)(options);
|
|
129
123
|
const didAutoFix = await options.autoFixConflicts({
|
|
130
124
|
files: conflictingFiles.map((f) => f.absolute),
|
|
@@ -171,7 +165,7 @@ async function waitForCherrypick(options, commit, targetBranch) {
|
|
|
171
165
|
unstagedFiles,
|
|
172
166
|
});
|
|
173
167
|
// Conflicts should be resolved and files staged at this point
|
|
174
|
-
const stagingSpinner = ora(`Finalizing cherrypick`).start();
|
|
168
|
+
const stagingSpinner = (0, ora_1.ora)(options.ci, `Finalizing cherrypick`).start();
|
|
175
169
|
try {
|
|
176
170
|
// Run `git commit`
|
|
177
171
|
await (0, git_1.commitChanges)(commit, options);
|
|
@@ -156,7 +156,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
156
156
|
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`"View pull request: myHtmlUrl"`);
|
|
157
157
|
});
|
|
158
158
|
it('should start the spinner with the correct text', () => {
|
|
159
|
-
expect(ora_1.default.mock.calls.map((call) => call[0]))
|
|
159
|
+
expect(ora_1.default.mock.calls.map((call) => call[0].text))
|
|
160
160
|
.toMatchInlineSnapshot(`
|
|
161
161
|
Array [
|
|
162
162
|
"Pulling latest changes",
|
|
@@ -356,7 +356,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
356
356
|
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
357
357
|
});
|
|
358
358
|
it('calls ora correctly', () => {
|
|
359
|
-
expect(ora_1.default.mock.calls.map((call) => call[0]))
|
|
359
|
+
expect(ora_1.default.mock.calls.map((call) => call[0].text))
|
|
360
360
|
.toMatchInlineSnapshot(`
|
|
361
361
|
Array [
|
|
362
362
|
"Pulling latest changes",
|
|
@@ -450,6 +450,10 @@ function setupExecSpyForCherryPick() {
|
|
|
450
450
|
if (cmd.includes('git branch -D ')) {
|
|
451
451
|
return { stdout: ``, stderr: '' };
|
|
452
452
|
}
|
|
453
|
+
// getIsMergeCommit
|
|
454
|
+
if (cmd.startsWith('git rev-list -1 --merges')) {
|
|
455
|
+
return { stdout: ``, stderr: '' };
|
|
456
|
+
}
|
|
453
457
|
throw new Error(`Missing exec mock for "${cmd}"`);
|
|
454
458
|
});
|
|
455
459
|
}
|
package/dist/ui/getCommits.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getCommits = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const ora_1 = __importDefault(require("ora"));
|
|
9
8
|
const HandledError_1 = require("../services/HandledError");
|
|
10
9
|
const commitFormatters_1 = require("../services/github/commitFormatters");
|
|
11
10
|
const fetchCommitByPullNumber_1 = require("../services/github/v4/fetchCommits/fetchCommitByPullNumber");
|
|
@@ -13,6 +12,7 @@ const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchComm
|
|
|
13
12
|
const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
|
|
14
13
|
const fetchPullRequestBySearchQuery_1 = require("../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
|
|
15
14
|
const prompts_1 = require("../services/prompts");
|
|
15
|
+
const ora_1 = require("./ora");
|
|
16
16
|
function getOraPersistsOption(question, answer) {
|
|
17
17
|
return {
|
|
18
18
|
symbol: chalk_1.default.green('?'),
|
|
@@ -20,13 +20,15 @@ function getOraPersistsOption(question, answer) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
async function getCommits(options) {
|
|
23
|
-
const spinner = (0, ora_1.
|
|
23
|
+
const spinner = (0, ora_1.ora)(options.ci).start();
|
|
24
24
|
try {
|
|
25
25
|
if (options.sha) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
spinner.
|
|
29
|
-
|
|
26
|
+
const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
|
|
27
|
+
// TODO: use Intl.ListFormat to format the sha's
|
|
28
|
+
spinner.text = `Loading commit "${shas.map(commitFormatters_1.getShortSha)}"`;
|
|
29
|
+
const commits = await Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
|
|
30
|
+
spinner.stopAndPersist(getOraPersistsOption('Select commit', commits.map((commit) => commit.sourceCommit.message).join(', ')));
|
|
31
|
+
return commits;
|
|
30
32
|
}
|
|
31
33
|
if (options.pullNumber) {
|
|
32
34
|
spinner.text = `Loading pull request #${options.pullNumber}`;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.maybeSetupRepo = void 0;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
4
|
const del = require("del");
|
|
6
|
-
const
|
|
5
|
+
const HandledError_1 = require("../services/HandledError");
|
|
7
6
|
const env_1 = require("../services/env");
|
|
8
7
|
const git_1 = require("../services/git");
|
|
8
|
+
const ora_1 = require("./ora");
|
|
9
9
|
async function maybeSetupRepo(options) {
|
|
10
10
|
const repoPath = (0, env_1.getRepoPath)(options);
|
|
11
|
-
const isAlreadyCloned = await getIsRepoCloned(
|
|
11
|
+
const isAlreadyCloned = await getIsRepoCloned(options);
|
|
12
|
+
if (options.cwd.includes(repoPath)) {
|
|
13
|
+
throw new HandledError_1.HandledError(`Refusing to clone repo into "${repoPath}" when current working directory is "${options.cwd}". Please change backport directory via \`--dir\` option or run backport from another location`);
|
|
14
|
+
}
|
|
12
15
|
// clone repo if folder does not already exists
|
|
13
16
|
if (!isAlreadyCloned) {
|
|
14
|
-
const spinner = ora().start();
|
|
17
|
+
const spinner = (0, ora_1.ora)(options.ci).start();
|
|
15
18
|
try {
|
|
16
19
|
const sourcePath = await (0, git_1.getSourceRepoPath)(options);
|
|
17
20
|
const sourcePathHumanReadable = sourcePath.includes(options.gitHostname)
|
|
@@ -19,6 +22,7 @@ async function maybeSetupRepo(options) {
|
|
|
19
22
|
: sourcePath;
|
|
20
23
|
const spinnerCloneText = `Cloning repository from ${sourcePathHumanReadable} (one-time operation)`;
|
|
21
24
|
spinner.text = `0% ${spinnerCloneText}`;
|
|
25
|
+
await del(repoPath, { force: true });
|
|
22
26
|
await (0, git_1.cloneRepo)({ sourcePath, targetPath: repoPath }, (progress) => {
|
|
23
27
|
spinner.text = `${progress}% ${spinnerCloneText}`;
|
|
24
28
|
});
|
|
@@ -26,7 +30,7 @@ async function maybeSetupRepo(options) {
|
|
|
26
30
|
}
|
|
27
31
|
catch (e) {
|
|
28
32
|
spinner.fail();
|
|
29
|
-
await del(repoPath);
|
|
33
|
+
await del(repoPath, { force: true });
|
|
30
34
|
throw e;
|
|
31
35
|
}
|
|
32
36
|
}
|
|
@@ -42,15 +46,8 @@ async function maybeSetupRepo(options) {
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
exports.maybeSetupRepo = maybeSetupRepo;
|
|
45
|
-
async function getIsRepoCloned(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
if (e.code === 'ENOENT') {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
throw e;
|
|
55
|
-
}
|
|
49
|
+
async function getIsRepoCloned(options) {
|
|
50
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
51
|
+
const projectRoot = await (0, git_1.getGitProjectRoot)(repoPath);
|
|
52
|
+
return repoPath === projectRoot;
|
|
56
53
|
}
|
|
@@ -22,14 +22,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const promises_1 = require("fs/promises");
|
|
26
25
|
const os_1 = __importDefault(require("os"));
|
|
27
26
|
const del_1 = __importDefault(require("del"));
|
|
28
27
|
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
29
28
|
const git = __importStar(require("../services/git"));
|
|
30
29
|
const mocks_1 = require("../test/mocks");
|
|
31
30
|
const maybeSetupRepo_1 = require("./maybeSetupRepo");
|
|
32
|
-
const fs = { stat: promises_1.stat };
|
|
33
31
|
describe('maybeSetupRepo', () => {
|
|
34
32
|
let execSpy;
|
|
35
33
|
beforeEach(() => {
|
|
@@ -55,8 +53,9 @@ describe('maybeSetupRepo', () => {
|
|
|
55
53
|
await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
56
54
|
repoName: 'kibana',
|
|
57
55
|
repoOwner: 'elastic',
|
|
56
|
+
cwd: '/path/to/source/repo',
|
|
58
57
|
})).rejects.toThrowError('Simulated git clone failure');
|
|
59
|
-
expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
|
|
58
|
+
expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana', { force: true });
|
|
60
59
|
});
|
|
61
60
|
});
|
|
62
61
|
describe('while cloning the repo', () => {
|
|
@@ -100,6 +99,7 @@ describe('maybeSetupRepo', () => {
|
|
|
100
99
|
await (0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
101
100
|
repoName: 'kibana',
|
|
102
101
|
repoOwner: 'elastic',
|
|
102
|
+
cwd: '/path/to/source/repo',
|
|
103
103
|
});
|
|
104
104
|
expect(spinnerTextSpy.mock.calls.map((call) => call[0]))
|
|
105
105
|
.toMatchInlineSnapshot(`
|
|
@@ -120,8 +120,6 @@ describe('maybeSetupRepo', () => {
|
|
|
120
120
|
});
|
|
121
121
|
describe('if repo already exists', () => {
|
|
122
122
|
beforeEach(() => {
|
|
123
|
-
// @ts-expect-error
|
|
124
|
-
jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
|
|
125
123
|
jest
|
|
126
124
|
.spyOn(childProcess, 'execAsCallback')
|
|
127
125
|
//@ts-expect-error
|
|
@@ -139,21 +137,42 @@ describe('maybeSetupRepo', () => {
|
|
|
139
137
|
authenticatedUsername: 'sqren_authenticated',
|
|
140
138
|
repoName: 'kibana',
|
|
141
139
|
repoOwner: 'elastic',
|
|
140
|
+
cwd: '/path/to/source/repo',
|
|
142
141
|
});
|
|
143
|
-
expect(execSpy.mock.calls.map(([cmd]) => cmd)).toEqual([
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
expect(execSpy.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
|
|
143
|
+
{
|
|
144
|
+
cmd: 'git rev-parse --show-toplevel',
|
|
145
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
cmd: 'git remote --verbose',
|
|
149
|
+
cwd: '/path/to/source/repo',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
cmd: 'git remote rm origin',
|
|
153
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
cmd: 'git remote rm sqren_authenticated',
|
|
157
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
cmd: 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
|
|
161
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
cmd: 'git remote rm elastic',
|
|
165
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
169
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
170
|
+
},
|
|
150
171
|
]);
|
|
151
172
|
});
|
|
152
173
|
});
|
|
153
174
|
describe('if repo does not exists locally', () => {
|
|
154
175
|
beforeEach(() => {
|
|
155
|
-
// @ts-expect-error
|
|
156
|
-
jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
|
|
157
176
|
jest
|
|
158
177
|
.spyOn(childProcess, 'execAsCallback')
|
|
159
178
|
//@ts-expect-error
|
|
@@ -171,14 +190,13 @@ describe('maybeSetupRepo', () => {
|
|
|
171
190
|
gitHostname: 'github.com',
|
|
172
191
|
repoName: 'kibana',
|
|
173
192
|
repoOwner: 'elastic',
|
|
193
|
+
cwd: '/path/to/source/repo',
|
|
174
194
|
});
|
|
175
195
|
expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
|
|
176
196
|
});
|
|
177
197
|
});
|
|
178
198
|
describe('if repo does exist locally', () => {
|
|
179
199
|
beforeEach(() => {
|
|
180
|
-
// @ts-expect-error
|
|
181
|
-
jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
|
|
182
200
|
jest
|
|
183
201
|
.spyOn(git, 'getSourceRepoPath')
|
|
184
202
|
.mockResolvedValue('/path/to/source/repo');
|
|
@@ -197,8 +215,24 @@ describe('maybeSetupRepo', () => {
|
|
|
197
215
|
await (0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
198
216
|
repoName: 'kibana',
|
|
199
217
|
repoOwner: 'elastic',
|
|
218
|
+
cwd: '/path/to/source/repo',
|
|
200
219
|
});
|
|
201
220
|
expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone /path/to/source/repo /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
|
|
202
221
|
});
|
|
203
222
|
});
|
|
223
|
+
describe('if `repoPath` is a parent of current working directory (cwd)', () => {
|
|
224
|
+
beforeEach(() => {
|
|
225
|
+
jest
|
|
226
|
+
.spyOn(git, 'getSourceRepoPath')
|
|
227
|
+
.mockResolvedValue('/path/to/source/repo');
|
|
228
|
+
jest.spyOn(childProcess, 'execAsCallback');
|
|
229
|
+
});
|
|
230
|
+
it('should clone it from local folder', async () => {
|
|
231
|
+
await expect(() => (0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
232
|
+
repoName: 'kibana',
|
|
233
|
+
repoOwner: 'elastic',
|
|
234
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana/foo',
|
|
235
|
+
})).rejects.toThrowError('Refusing to clone repo into "/myHomeDir/.backport/repositories/elastic/kibana" when current working directory is "/myHomeDir/.backport/repositories/elastic/kibana/foo". Please change backport directory via `--dir` option or run backport from another location');
|
|
236
|
+
});
|
|
237
|
+
});
|
|
204
238
|
});
|
package/dist/ui/ora.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import oraOriginal from 'ora';
|
|
2
|
+
export declare function ora(ci: boolean | undefined, text?: string | undefined): oraOriginal.Ora | {
|
|
3
|
+
start: (text?: string | undefined) => any;
|
|
4
|
+
succeed: () => void;
|
|
5
|
+
stop: () => void;
|
|
6
|
+
fail: () => void;
|
|
7
|
+
stopAndPersist: () => void;
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
package/dist/ui/ora.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.ora = void 0;
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
9
|
+
const oraMock = {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
start: (text) => oraMock,
|
|
12
|
+
succeed: () => { },
|
|
13
|
+
stop: () => { },
|
|
14
|
+
fail: () => { },
|
|
15
|
+
stopAndPersist: () => { },
|
|
16
|
+
set text(value) { },
|
|
17
|
+
};
|
|
18
|
+
function ora(ci, text) {
|
|
19
|
+
return ci ? oraMock : (0, ora_1.default)({ text });
|
|
20
|
+
}
|
|
21
|
+
exports.ora = ora;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "7.0.
|
|
1
|
+
export declare const PACKAGE_VERSION = "7.2.0-beta.3";
|
package/package.json
CHANGED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"branches",
|
|
15
15
|
"branching"
|
|
16
16
|
],
|
|
17
|
-
"version": "7.0.
|
|
17
|
+
"version": "7.2.0-beta.3",
|
|
18
18
|
"main": "./dist/entrypoint.module.js",
|
|
19
19
|
"types": "dist/entrypoint.module.d.ts",
|
|
20
20
|
"bin": {
|
|
21
|
-
"backport": "./
|
|
21
|
+
"backport": "./bin/backport"
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"scripts": {
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"strip-json-comments": "^3.1.1",
|
|
79
79
|
"terminal-link": "^2.1.1",
|
|
80
80
|
"utility-types": "^3.10.0",
|
|
81
|
-
"winston": "^3.
|
|
81
|
+
"winston": "^3.6.0",
|
|
82
82
|
"yargs": "^17.3.1",
|
|
83
83
|
"yargs-parser": "^21.0.0"
|
|
84
84
|
},
|
|
@@ -88,22 +88,22 @@
|
|
|
88
88
|
"@types/inquirer": "^8.2.0",
|
|
89
89
|
"@types/jest": "^27.4.0",
|
|
90
90
|
"@types/lodash": "^4.14.178",
|
|
91
|
-
"@types/node": "^17.0.
|
|
91
|
+
"@types/node": "^17.0.18",
|
|
92
92
|
"@types/safe-json-stringify": "^1.1.2",
|
|
93
93
|
"@types/yargs": "^17.0.8",
|
|
94
94
|
"@types/yargs-parser": "^20.2.1",
|
|
95
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
96
|
-
"@typescript-eslint/parser": "^5.
|
|
97
|
-
"eslint": "^8.
|
|
98
|
-
"eslint-config-prettier": "^8.
|
|
95
|
+
"@typescript-eslint/eslint-plugin": "^5.12.0",
|
|
96
|
+
"@typescript-eslint/parser": "^5.12.0",
|
|
97
|
+
"eslint": "^8.9.0",
|
|
98
|
+
"eslint-config-prettier": "^8.4.0",
|
|
99
99
|
"eslint-plugin-import": "^2.25.4",
|
|
100
|
-
"eslint-plugin-jest": "^26.1.
|
|
100
|
+
"eslint-plugin-jest": "^26.1.1",
|
|
101
101
|
"eslint-plugin-prettier": "^4.0.0",
|
|
102
102
|
"graphql-config": "^4.1.0",
|
|
103
103
|
"husky": "^7.0.4",
|
|
104
104
|
"jest": "^27.5.1",
|
|
105
105
|
"jest-snapshot-serializer-ansi": "^1.0.0",
|
|
106
|
-
"lint-staged": "^12.3.
|
|
106
|
+
"lint-staged": "^12.3.4",
|
|
107
107
|
"nock": "^13.2.4",
|
|
108
108
|
"prettier": "^2.5.1",
|
|
109
109
|
"strip-ansi": "^6.0.1",
|