backport 8.5.0 → 8.5.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.js +1 -5
- package/dist/entrypoint.module.d.ts +1 -1
- package/dist/entrypoint.module.js +1 -1
- package/dist/entrypoint.module.private.test.js +7 -3
- package/dist/lib/BackportError.d.ts +3 -0
- package/dist/lib/BackportError.js +2 -0
- package/dist/lib/author.d.ts +4 -7
- package/dist/lib/author.js +4 -16
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +11 -13
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +18 -0
- package/dist/lib/getCommits.js +1 -1
- package/dist/lib/getTargetBranches.test.js +0 -4
- package/dist/lib/git.d.ts +0 -4
- package/dist/lib/git.js +10 -14
- package/dist/lib/git.private.test.js +0 -26
- package/dist/lib/github/v4/validateTargetBranch.d.ts +15 -0
- package/dist/lib/github/v4/{validateTargetBranches.js → validateTargetBranch.js} +13 -17
- package/dist/lib/github/v4/{validateTargetBranches.private.test.d.ts → validateTargetBranch.private.test.d.ts} +0 -0
- package/dist/lib/github/v4/validateTargetBranch.private.test.js +23 -0
- package/dist/lib/setupRepo.test.js +0 -3
- package/dist/options/options.js +1 -1
- package/dist/runSequentially.js +9 -3
- package/dist/test/e2e/cli/commit-author.private.test.js +49 -67
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -2
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +10 -8
- package/dist/test/nockHelpers.js +1 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +1 -1
- package/dist/lib/github/v4/validateTargetBranches.d.ts +0 -9
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +0 -51
package/dist/backportRun.js
CHANGED
|
@@ -11,7 +11,6 @@ const getCommits_1 = require("./lib/getCommits");
|
|
|
11
11
|
const getTargetBranches_1 = require("./lib/getTargetBranches");
|
|
12
12
|
const createStatusComment_1 = require("./lib/github/v3/createStatusComment");
|
|
13
13
|
const apiRequestV4_1 = require("./lib/github/v4/apiRequestV4");
|
|
14
|
-
const validateTargetBranches_1 = require("./lib/github/v4/validateTargetBranches");
|
|
15
14
|
const logger_1 = require("./lib/logger");
|
|
16
15
|
const ora_1 = require("./lib/ora");
|
|
17
16
|
const setupRepo_1 = require("./lib/setupRepo");
|
|
@@ -52,10 +51,7 @@ async function backportRun({ processArgs, optionsFromModule = {}, exitCodeOnFail
|
|
|
52
51
|
}
|
|
53
52
|
const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
54
53
|
logger.info('Target branches', targetBranches);
|
|
55
|
-
await
|
|
56
|
-
(0, setupRepo_1.setupRepo)(options),
|
|
57
|
-
(0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches),
|
|
58
|
-
]);
|
|
54
|
+
await (0, setupRepo_1.setupRepo)(options);
|
|
59
55
|
const results = await (0, runSequentially_1.runSequentially)({
|
|
60
56
|
options,
|
|
61
57
|
commits,
|
|
@@ -10,7 +10,7 @@ export type { ConfigFileOptions } from './options/ConfigOptions';
|
|
|
10
10
|
export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './lib/github/v4/fetchRemoteProjectConfig';
|
|
11
11
|
export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
|
|
12
12
|
export declare function backportRun({ options, processArgs, exitCodeOnFailure, }: {
|
|
13
|
-
options
|
|
13
|
+
options?: ConfigFileOptions;
|
|
14
14
|
processArgs?: string[];
|
|
15
15
|
exitCodeOnFailure?: boolean;
|
|
16
16
|
}): Promise<BackportResponse>;
|
|
@@ -15,7 +15,7 @@ var fetchRemoteProjectConfig_1 = require("./lib/github/v4/fetchRemoteProjectConf
|
|
|
15
15
|
Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
|
|
16
16
|
var globalConfig_1 = require("./options/config/globalConfig");
|
|
17
17
|
Object.defineProperty(exports, "getLocalGlobalConfig", { enumerable: true, get: function () { return globalConfig_1.getGlobalConfig; } });
|
|
18
|
-
function backportRun({ options, processArgs = [], exitCodeOnFailure = true, }) {
|
|
18
|
+
function backportRun({ options = {}, processArgs = [], exitCodeOnFailure = true, }) {
|
|
19
19
|
return (0, backportRun_1.backportRun)({
|
|
20
20
|
optionsFromModule: (0, excludeUndefined_1.excludeUndefined)(options),
|
|
21
21
|
processArgs,
|
|
@@ -56,9 +56,13 @@ describe('entrypoint.module', () => {
|
|
|
56
56
|
},
|
|
57
57
|
}));
|
|
58
58
|
});
|
|
59
|
-
it('should
|
|
60
|
-
expect(response.status).toBe('
|
|
61
|
-
expect
|
|
59
|
+
it('should return handled error', async () => {
|
|
60
|
+
expect(response.status).toBe('success');
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
expect(response.results[0].error.errorContext).toEqual({
|
|
63
|
+
code: 'invalid-branch-exception',
|
|
64
|
+
branchName: '--foo',
|
|
65
|
+
});
|
|
62
66
|
});
|
|
63
67
|
});
|
|
64
68
|
describe('when missing branches to backport to', () => {
|
|
@@ -9,6 +9,8 @@ function getMessage(errorContext) {
|
|
|
9
9
|
return 'There are no branches to backport to. Aborting.';
|
|
10
10
|
case 'abort-conflict-resolution-exception':
|
|
11
11
|
return 'Conflict resolution was aborted by the user';
|
|
12
|
+
case 'invalid-branch-exception':
|
|
13
|
+
return `The branch "${errorContext.branchName}" does not exist`;
|
|
12
14
|
case 'message-only-exception':
|
|
13
15
|
return errorContext.message;
|
|
14
16
|
}
|
package/dist/lib/author.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { Commit } from '../entrypoint.module';
|
|
2
2
|
import { ValidConfigOptions } from '../options/options';
|
|
3
|
-
export declare type
|
|
4
|
-
name
|
|
5
|
-
email
|
|
3
|
+
export declare type CommitAuthor = {
|
|
4
|
+
name: string;
|
|
5
|
+
email: string;
|
|
6
6
|
};
|
|
7
|
-
export declare function
|
|
8
|
-
export declare type CommitAuthor = Required<GitConfigAuthor>;
|
|
9
|
-
export declare function getCommitAuthor({ options, commit, gitConfigAuthor, }: {
|
|
7
|
+
export declare function getCommitAuthor({ options, commit, }: {
|
|
10
8
|
options: ValidConfigOptions;
|
|
11
9
|
commit: Commit;
|
|
12
|
-
gitConfigAuthor?: GitConfigAuthor;
|
|
13
10
|
}): CommitAuthor;
|
package/dist/lib/author.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCommitAuthor =
|
|
4
|
-
|
|
5
|
-
async function getGitConfigAuthor(options) {
|
|
6
|
-
const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
|
|
7
|
-
if (!localRepoPath) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
return {
|
|
11
|
-
name: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' }),
|
|
12
|
-
email: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' }),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
exports.getGitConfigAuthor = getGitConfigAuthor;
|
|
16
|
-
function getCommitAuthor({ options, commit, gitConfigAuthor, }) {
|
|
3
|
+
exports.getCommitAuthor = void 0;
|
|
4
|
+
function getCommitAuthor({ options, commit, }) {
|
|
17
5
|
if (options.resetAuthor) {
|
|
18
6
|
return {
|
|
19
7
|
name: options.authenticatedUsername,
|
|
@@ -21,8 +9,8 @@ function getCommitAuthor({ options, commit, gitConfigAuthor, }) {
|
|
|
21
9
|
};
|
|
22
10
|
}
|
|
23
11
|
return {
|
|
24
|
-
name: options.gitAuthorName ??
|
|
25
|
-
email: options.gitAuthorEmail ??
|
|
12
|
+
name: options.gitAuthorName ?? commit.author.name,
|
|
13
|
+
email: options.gitAuthorEmail ?? commit.author.email,
|
|
26
14
|
};
|
|
27
15
|
}
|
|
28
16
|
exports.getCommitAuthor = getCommitAuthor;
|
|
@@ -19,6 +19,7 @@ const addReviewersToPullRequest_1 = require("./github/v3/addReviewersToPullReque
|
|
|
19
19
|
const createPullRequest_1 = require("./github/v3/createPullRequest");
|
|
20
20
|
const enablePullRequestAutoMerge_1 = require("./github/v4/enablePullRequestAutoMerge");
|
|
21
21
|
const fetchCommitBySha_1 = require("./github/v4/fetchCommits/fetchCommitBySha");
|
|
22
|
+
const validateTargetBranch_1 = require("./github/v4/validateTargetBranch");
|
|
22
23
|
const logger_1 = require("./logger");
|
|
23
24
|
const ora_1 = require("./ora");
|
|
24
25
|
const prompts_1 = require("./prompts");
|
|
@@ -33,18 +34,15 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
33
34
|
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
34
35
|
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
35
36
|
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
backportBranch,
|
|
44
|
-
}),
|
|
45
|
-
]);
|
|
37
|
+
await (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: targetBranch });
|
|
38
|
+
await (0, git_1.createBackportBranch)({
|
|
39
|
+
options,
|
|
40
|
+
sourceBranch: getSourceBranchFromCommits(commits),
|
|
41
|
+
targetBranch,
|
|
42
|
+
backportBranch,
|
|
43
|
+
});
|
|
46
44
|
const commitsFlattened = (0, lodash_1.flatten)(await Promise.all(commits.map((c) => getMergeCommits(options, c))));
|
|
47
|
-
await (0, sequentially_1.sequentially)(commitsFlattened, (commit) => waitForCherrypick(options, commit, targetBranch
|
|
45
|
+
await (0, sequentially_1.sequentially)(commitsFlattened, (commit) => waitForCherrypick(options, commit, targetBranch));
|
|
48
46
|
if (options.dryRun) {
|
|
49
47
|
(0, ora_1.ora)(options.interactive).succeed('Dry run complete');
|
|
50
48
|
return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
|
|
@@ -120,10 +118,10 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
120
118
|
.slice(0, 200);
|
|
121
119
|
return `backport/${targetBranch}/${refValues}`;
|
|
122
120
|
}
|
|
123
|
-
async function waitForCherrypick(options, commit, targetBranch
|
|
121
|
+
async function waitForCherrypick(options, commit, targetBranch) {
|
|
124
122
|
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
125
123
|
const cherrypickSpinner = (0, ora_1.ora)(options.interactive, spinnerText).start();
|
|
126
|
-
const commitAuthor = (0, author_1.getCommitAuthor)({ options, commit
|
|
124
|
+
const commitAuthor = (0, author_1.getCommitAuthor)({ options, commit });
|
|
127
125
|
await cherrypickAndHandleConflicts({
|
|
128
126
|
options,
|
|
129
127
|
commit,
|
|
@@ -76,6 +76,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
76
76
|
sourceBranch: 'myDefaultSourceBranch',
|
|
77
77
|
sourcePRLabels: [],
|
|
78
78
|
targetPRLabels: ['backport'],
|
|
79
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
79
80
|
};
|
|
80
81
|
const commits = [
|
|
81
82
|
{
|
|
@@ -125,6 +126,11 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
125
126
|
pullRequestStates: [],
|
|
126
127
|
},
|
|
127
128
|
];
|
|
129
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
130
|
+
name: 'GetBranchId',
|
|
131
|
+
statusCode: 200,
|
|
132
|
+
body: { data: { repository: { ref: { id: 'foo' } } } },
|
|
133
|
+
});
|
|
128
134
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
129
135
|
.post('/repos/elastic/kibana/pulls')
|
|
130
136
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
@@ -176,6 +182,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
176
182
|
expect(ora_1.default.mock.calls.map((call) => call[0].text))
|
|
177
183
|
.toMatchInlineSnapshot(`
|
|
178
184
|
Array [
|
|
185
|
+
"",
|
|
179
186
|
"Pulling latest changes",
|
|
180
187
|
"Cherry-picking: My original commit message (#1000)",
|
|
181
188
|
"Cherry-picking: My other commit message (#2000)",
|
|
@@ -203,6 +210,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
203
210
|
reviewers: [],
|
|
204
211
|
sourcePRLabels: [],
|
|
205
212
|
targetPRLabels: ['backport'],
|
|
213
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
206
214
|
};
|
|
207
215
|
const commits = [
|
|
208
216
|
{
|
|
@@ -221,6 +229,11 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
221
229
|
pullRequestStates: [],
|
|
222
230
|
},
|
|
223
231
|
];
|
|
232
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
233
|
+
name: 'GetBranchId',
|
|
234
|
+
statusCode: 200,
|
|
235
|
+
body: { data: { repository: { ref: { id: 'foo' } } } },
|
|
236
|
+
});
|
|
224
237
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
225
238
|
.post('/repos/elastic/kibana/pulls')
|
|
226
239
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
@@ -276,6 +289,11 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
276
289
|
sourcePRLabels: [],
|
|
277
290
|
targetPRLabels: ['backport'],
|
|
278
291
|
};
|
|
292
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
293
|
+
name: 'GetBranchId',
|
|
294
|
+
statusCode: 200,
|
|
295
|
+
body: { data: { repository: { ref: { id: 'foo' } } } },
|
|
296
|
+
});
|
|
279
297
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
280
298
|
.post('/repos/elastic/kibana/pulls')
|
|
281
299
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
package/dist/lib/getCommits.js
CHANGED
|
@@ -35,7 +35,7 @@ async function getCommits(options) {
|
|
|
35
35
|
const pullNumbers = Array.isArray(options.pullNumber)
|
|
36
36
|
? options.pullNumber
|
|
37
37
|
: [options.pullNumber];
|
|
38
|
-
spinner.text = `Loading pull request
|
|
38
|
+
spinner.text = `Loading pull request ${pullNumbers
|
|
39
39
|
.map((pullNumber) => `#${pullNumber}`)
|
|
40
40
|
.join(', ')}`;
|
|
41
41
|
const commits = await Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({ ...options, pullNumber })));
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const getTargetBranches_1 = require("./getTargetBranches");
|
|
27
|
-
const validateTargetBranches = __importStar(require("./github/v4/validateTargetBranches"));
|
|
28
27
|
const prompts = __importStar(require("./prompts"));
|
|
29
28
|
describe('getTargetBranches', () => {
|
|
30
29
|
let promptSpy;
|
|
@@ -80,9 +79,6 @@ describe('getTargetBranches', () => {
|
|
|
80
79
|
describe('when `options.targetBranches` is not empty', () => {
|
|
81
80
|
let branches;
|
|
82
81
|
beforeEach(async () => {
|
|
83
|
-
jest
|
|
84
|
-
.spyOn(validateTargetBranches, 'validateTargetBranches')
|
|
85
|
-
.mockResolvedValueOnce();
|
|
86
82
|
branches = await (0, getTargetBranches_1.getTargetBranches)({
|
|
87
83
|
targetBranches: ['branchA', 'branchB'],
|
|
88
84
|
targetBranchChoices: [],
|
package/dist/lib/git.d.ts
CHANGED
|
@@ -53,10 +53,6 @@ export declare function getConflictingFiles(options: ValidConfigOptions): Promis
|
|
|
53
53
|
relative: string;
|
|
54
54
|
}[]>;
|
|
55
55
|
export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
|
|
56
|
-
export declare function getGitConfig({ dir, key, }: {
|
|
57
|
-
dir: string;
|
|
58
|
-
key: 'user.name' | 'user.email';
|
|
59
|
-
}): Promise<string | undefined>;
|
|
60
56
|
export declare function createBackportBranch({ options, sourceBranch, backportBranch, targetBranch, }: {
|
|
61
57
|
options: ValidConfigOptions;
|
|
62
58
|
sourceBranch: string;
|
package/dist/lib/git.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.
|
|
3
|
+
exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getShasInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
6
|
const ora_1 = require("../lib/ora");
|
|
@@ -176,8 +176,15 @@ async function fetchBranch(options, branch) {
|
|
|
176
176
|
exports.fetchBranch = fetchBranch;
|
|
177
177
|
async function getIsMergeCommit(options, sha) {
|
|
178
178
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
try {
|
|
180
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['rev-list', '-1', '--merges', `${sha}~1..${sha}`], cwd);
|
|
181
|
+
return res.stdout !== '';
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
185
|
+
logger_1.logger.info(`Could not determine if ${shortSha} is a merge commit. Will assume it is not`, e);
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
181
188
|
}
|
|
182
189
|
exports.getIsMergeCommit = getIsMergeCommit;
|
|
183
190
|
async function getShasInMergeCommit(options, sha) {
|
|
@@ -332,17 +339,6 @@ async function getUnstagedFiles(options) {
|
|
|
332
339
|
return (0, lodash_1.uniq)(files);
|
|
333
340
|
}
|
|
334
341
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
335
|
-
async function getGitConfig({ dir, key, }) {
|
|
336
|
-
try {
|
|
337
|
-
const cwd = dir;
|
|
338
|
-
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['config', key], cwd);
|
|
339
|
-
return res.stdout.trim();
|
|
340
|
-
}
|
|
341
|
-
catch (e) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
exports.getGitConfig = getGitConfig;
|
|
346
342
|
// How the commit flows:
|
|
347
343
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
348
344
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
@@ -97,32 +97,6 @@ describe('git.private', () => {
|
|
|
97
97
|
expect(res).toBe(undefined);
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
|
-
describe('getGitConfig', () => {
|
|
101
|
-
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
102
|
-
filename: __filename,
|
|
103
|
-
specname: 'getGitConfig',
|
|
104
|
-
});
|
|
105
|
-
beforeEach(async () => {
|
|
106
|
-
await (0, sandbox_1.resetSandbox)(cwd);
|
|
107
|
-
await gitInit(cwd);
|
|
108
|
-
await childProcess.exec(`git config user.name "John Doe"`, { cwd });
|
|
109
|
-
await childProcess.exec(`git config user.email "john@jubii.dk"`, { cwd });
|
|
110
|
-
});
|
|
111
|
-
it('should retrive name', async () => {
|
|
112
|
-
const name = await (0, git_1.getGitConfig)({
|
|
113
|
-
dir: cwd,
|
|
114
|
-
key: 'user.name',
|
|
115
|
-
});
|
|
116
|
-
expect(name).toEqual('John Doe');
|
|
117
|
-
});
|
|
118
|
-
it('should retrive email', async () => {
|
|
119
|
-
const email = await (0, git_1.getGitConfig)({
|
|
120
|
-
dir: cwd,
|
|
121
|
-
key: 'user.email',
|
|
122
|
-
});
|
|
123
|
-
expect(email).toEqual('john@jubii.dk');
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
100
|
describe('createBackportBranch', () => {
|
|
127
101
|
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
128
102
|
filename: __filename,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface TargetBranchResponse {
|
|
2
|
+
repository: {
|
|
3
|
+
ref: {
|
|
4
|
+
id: string;
|
|
5
|
+
} | null;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function validateTargetBranch({ accessToken, repoName, repoOwner, branchName, githubApiBaseUrlV4, interactive, }: {
|
|
9
|
+
accessToken: string;
|
|
10
|
+
repoOwner: string;
|
|
11
|
+
repoName: string;
|
|
12
|
+
branchName: string;
|
|
13
|
+
githubApiBaseUrlV4?: string;
|
|
14
|
+
interactive: boolean;
|
|
15
|
+
}): Promise<void>;
|
|
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.validateTargetBranch = void 0;
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
8
|
const BackportError_1 = require("../../BackportError");
|
|
9
|
+
const ora_1 = require("../../ora");
|
|
9
10
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
10
|
-
async function
|
|
11
|
+
async function validateTargetBranch({ accessToken, repoName, repoOwner, branchName, githubApiBaseUrlV4 = 'https://api.github.com/graphql', interactive, }) {
|
|
11
12
|
const query = (0, graphql_tag_1.default) `
|
|
12
|
-
query
|
|
13
|
+
query GetBranchId(
|
|
13
14
|
$repoOwner: String!
|
|
14
15
|
$repoName: String!
|
|
15
16
|
$branchName: String!
|
|
@@ -21,6 +22,7 @@ async function fetchTargetBranch({ accessToken, repoName, repoOwner, branchName,
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
`;
|
|
25
|
+
const spinner = (0, ora_1.ora)(interactive, '').start();
|
|
24
26
|
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
25
27
|
githubApiBaseUrlV4,
|
|
26
28
|
accessToken,
|
|
@@ -28,19 +30,13 @@ async function fetchTargetBranch({ accessToken, repoName, repoOwner, branchName,
|
|
|
28
30
|
variables: { repoOwner, repoName, branchName },
|
|
29
31
|
});
|
|
30
32
|
if (!res.repository.ref) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
async function validateTargetBranches({ accessToken, repoName, repoOwner, githubApiBaseUrlV4 }, targetBranches) {
|
|
36
|
-
await Promise.all(targetBranches.map((targetBranch) => {
|
|
37
|
-
return fetchTargetBranch({
|
|
38
|
-
accessToken,
|
|
39
|
-
repoName,
|
|
40
|
-
repoOwner,
|
|
41
|
-
branchName: targetBranch,
|
|
42
|
-
githubApiBaseUrlV4,
|
|
33
|
+
spinner.fail(`The branch "${branchName}" does not exist`);
|
|
34
|
+
throw new BackportError_1.BackportError({
|
|
35
|
+
code: 'invalid-branch-exception',
|
|
36
|
+
branchName: branchName,
|
|
43
37
|
});
|
|
44
|
-
}
|
|
38
|
+
}
|
|
39
|
+
spinner.stop();
|
|
40
|
+
return;
|
|
45
41
|
}
|
|
46
|
-
exports.
|
|
42
|
+
exports.validateTargetBranch = validateTargetBranch;
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const validateTargetBranch_1 = require("./validateTargetBranch");
|
|
5
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
describe('validateTargetBranch', () => {
|
|
7
|
+
it('throws when branch is invalid', async () => {
|
|
8
|
+
const options = {
|
|
9
|
+
repoOwner: 'backport-org',
|
|
10
|
+
repoName: 'repo-with-target-branches',
|
|
11
|
+
accessToken,
|
|
12
|
+
};
|
|
13
|
+
await expect(() => (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: 'foo' })).rejects.toThrowError('The branch "foo" does not exist');
|
|
14
|
+
});
|
|
15
|
+
it('resolves when branch is valid', async () => {
|
|
16
|
+
const options = {
|
|
17
|
+
repoOwner: 'backport-org',
|
|
18
|
+
repoName: 'repo-with-target-branches',
|
|
19
|
+
accessToken,
|
|
20
|
+
};
|
|
21
|
+
expect(await (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: 'production' })).toEqual(undefined);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -243,9 +243,6 @@ describe('setupRepo', () => {
|
|
|
243
243
|
jest
|
|
244
244
|
.spyOn(gitModule, 'getLocalSourceRepoPath')
|
|
245
245
|
.mockResolvedValue('/path/to/source/repo');
|
|
246
|
-
jest
|
|
247
|
-
.spyOn(gitModule, 'getGitConfig')
|
|
248
|
-
.mockResolvedValue('email-or-username');
|
|
249
246
|
mockGitClone();
|
|
250
247
|
await (0, setupRepo_1.setupRepo)({
|
|
251
248
|
repoName: 'kibana',
|
package/dist/options/options.js
CHANGED
|
@@ -61,7 +61,7 @@ async function getOptions({ optionsFromCliArgs, optionsFromModule, }) {
|
|
|
61
61
|
repoOwner,
|
|
62
62
|
});
|
|
63
63
|
const options = {
|
|
64
|
-
// default author
|
|
64
|
+
// default author to filter commits by
|
|
65
65
|
author: optionsFromGithub.authenticatedUsername,
|
|
66
66
|
// default fork owner
|
|
67
67
|
repoForkOwner: optionsFromGithub.authenticatedUsername,
|
package/dist/runSequentially.js
CHANGED
|
@@ -43,10 +43,16 @@ async function runSequentially({ options, commits, targetBranches, }) {
|
|
|
43
43
|
else {
|
|
44
44
|
throw e;
|
|
45
45
|
}
|
|
46
|
-
(0, logger_1.consoleLog)(isHandledError
|
|
47
|
-
? e.message
|
|
48
|
-
: 'An unhandled error occurred while backporting commit. Please see the logs for details');
|
|
49
46
|
logger_1.logger.error('runSequentially failed', e);
|
|
47
|
+
if (isHandledError) {
|
|
48
|
+
// don't output anything. Already handled in application
|
|
49
|
+
if (e.errorContext.code === 'invalid-branch-exception') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
(0, logger_1.consoleLog)(e.message);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
(0, logger_1.consoleLog)('An unhandled error occurred while backporting commit. Please see the logs for details');
|
|
50
56
|
}
|
|
51
57
|
});
|
|
52
58
|
// return the results for consumers to programatically read
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
3
|
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
8
4
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
9
5
|
const sandbox_1 = require("../../sandbox");
|
|
10
6
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
11
7
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
8
|
+
const COMMIT_BY_JOHN_DOE_SHA = 'c3f837226bea3c7a50f2ba16d807fbe846ed3453';
|
|
12
9
|
describe('commit author', () => {
|
|
13
10
|
let sourceRepo;
|
|
14
11
|
let backportRepo;
|
|
@@ -17,76 +14,61 @@ describe('commit author', () => {
|
|
|
17
14
|
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
18
15
|
sourceRepo = `${sandboxPath}/sourceRepo`;
|
|
19
16
|
backportRepo = `${sandboxPath}/backportRepo`;
|
|
20
|
-
await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/
|
|
21
|
-
|
|
22
|
-
repoName: 'commit-author',
|
|
23
|
-
repoOwner: 'backport-org',
|
|
24
|
-
}));
|
|
25
|
-
});
|
|
26
|
-
// eslint-disable-next-line jest/no-commented-out-tests
|
|
27
|
-
// it('use commit author from source commit', async () => {
|
|
28
|
-
// await runBackportViaCli(
|
|
29
|
-
// [
|
|
30
|
-
// `--accessToken=${accessToken}`,
|
|
31
|
-
// `--dir=${backportRepo}`,
|
|
32
|
-
// '--branch=production',
|
|
33
|
-
// '--pr=2',
|
|
34
|
-
// '--dry-run',
|
|
35
|
-
// ],
|
|
36
|
-
// { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true }
|
|
37
|
-
// );
|
|
38
|
-
// const { authorEmail, authorName } = await getCommitAuthor({
|
|
39
|
-
// cwd: backportRepo,
|
|
40
|
-
// });
|
|
41
|
-
// expect(authorName).toEqual('Sonny Long (demo)');
|
|
42
|
-
// expect(authorEmail).toEqual('71195571+sqren-demo@users.noreply.github.com');
|
|
43
|
-
// });
|
|
44
|
-
it('use commit author from git config in source repo', async () => {
|
|
17
|
+
await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/repo-with-different-commits-authors.git ${sourceRepo}`, { cwd: sandboxPath });
|
|
18
|
+
// set dummy git author. This should not have any effect and should never be used
|
|
45
19
|
await (0, child_process_promisified_1.exec)(`git config user.name "Peter Kanin"`, { cwd: sourceRepo });
|
|
46
20
|
await (0, child_process_promisified_1.exec)(`git config user.email "kanin@zoo.dk"`, { cwd: sourceRepo });
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
21
|
+
});
|
|
22
|
+
describe('when nothing is specified (default)', () => {
|
|
23
|
+
it('uses commit author from source commit', async () => {
|
|
24
|
+
await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
25
|
+
`--accessToken=${accessToken}`,
|
|
26
|
+
`--dir=${backportRepo}`,
|
|
27
|
+
'--branch=production',
|
|
28
|
+
`--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
|
|
29
|
+
'--dry-run',
|
|
30
|
+
], { cwd: sourceRepo, showOra: true });
|
|
31
|
+
const { authorEmail, authorName } = await getCommitAuthor({
|
|
32
|
+
cwd: backportRepo,
|
|
33
|
+
});
|
|
34
|
+
expect(authorName).toEqual('John Doe');
|
|
35
|
+
expect(authorEmail).toEqual('john.doe@backport-testing.dk');
|
|
56
36
|
});
|
|
57
|
-
expect(authorName).toEqual('Peter Kanin');
|
|
58
|
-
expect(authorEmail).toEqual('kanin@zoo.dk');
|
|
59
37
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
describe('when setting author via `--gitAuthor*` cli options', () => {
|
|
39
|
+
it('respects the settings', async () => {
|
|
40
|
+
await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
41
|
+
`--accessToken=${accessToken}`,
|
|
42
|
+
`--dir=${backportRepo}`,
|
|
43
|
+
'--branch=production',
|
|
44
|
+
`--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
|
|
45
|
+
'--dry-run',
|
|
46
|
+
'--gitAuthorName="Donald Duck"',
|
|
47
|
+
'--gitAuthorEmail=duck@disney.com',
|
|
48
|
+
], { cwd: sourceRepo, showOra: true });
|
|
49
|
+
const { authorEmail, authorName } = await getCommitAuthor({
|
|
50
|
+
cwd: backportRepo,
|
|
51
|
+
});
|
|
52
|
+
expect(authorName).toEqual('Donald Duck');
|
|
53
|
+
expect(authorEmail).toEqual('duck@disney.com');
|
|
72
54
|
});
|
|
73
|
-
expect(authorName).toEqual('Donald Duck');
|
|
74
|
-
expect(authorEmail).toEqual('duck@disney.com');
|
|
75
55
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
56
|
+
describe('when using `--resetAuthor` option', () => {
|
|
57
|
+
it('sets the current user as author of commit', async () => {
|
|
58
|
+
await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
59
|
+
`--accessToken=${accessToken}`,
|
|
60
|
+
`--dir=${backportRepo}`,
|
|
61
|
+
'--branch=production',
|
|
62
|
+
`--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
|
|
63
|
+
'--dry-run',
|
|
64
|
+
'--reset-author',
|
|
65
|
+
], { cwd: sourceRepo, showOra: true });
|
|
66
|
+
const { authorEmail, authorName } = await getCommitAuthor({
|
|
67
|
+
cwd: backportRepo,
|
|
68
|
+
});
|
|
69
|
+
expect(authorName).toEqual('sqren');
|
|
70
|
+
expect(authorEmail).toEqual('sqren@users.noreply.github.com');
|
|
87
71
|
});
|
|
88
|
-
expect(authorName).toEqual('sqren');
|
|
89
|
-
expect(authorEmail).toEqual('sqren@users.noreply.github.com');
|
|
90
72
|
});
|
|
91
73
|
});
|
|
92
74
|
async function getCommitAuthor({ cwd }) {
|
|
@@ -49,8 +49,8 @@ describe('interactive error handling', () => {
|
|
|
49
49
|
'--repo=backport-org/backport-e2e',
|
|
50
50
|
'--pr=9',
|
|
51
51
|
`--accessToken=${accessToken}`,
|
|
52
|
-
]);
|
|
53
|
-
expect(output).
|
|
52
|
+
], { showOra: true });
|
|
53
|
+
expect(output).toContain('✖ The branch "foo" does not exist');
|
|
54
54
|
});
|
|
55
55
|
it(`when encountering conflicts`, async () => {
|
|
56
56
|
const backportDir = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
@@ -95,12 +95,13 @@ describe('non interactive (json) error handling', () => {
|
|
|
95
95
|
`--accessToken=${accessToken}`,
|
|
96
96
|
]);
|
|
97
97
|
const backportResult = JSON.parse(output);
|
|
98
|
-
expect(backportResult.status).toBe('
|
|
99
|
-
expect
|
|
98
|
+
expect(backportResult.status).toBe('success');
|
|
99
|
+
//@ts-expect-error
|
|
100
|
+
expect(backportResult.results[0].error).toEqual({
|
|
100
101
|
name: 'BackportError',
|
|
101
102
|
errorContext: {
|
|
102
|
-
code: '
|
|
103
|
-
|
|
103
|
+
code: 'invalid-branch-exception',
|
|
104
|
+
branchName: 'foobar',
|
|
104
105
|
},
|
|
105
106
|
});
|
|
106
107
|
});
|
|
@@ -113,12 +114,13 @@ describe('non interactive (json) error handling', () => {
|
|
|
113
114
|
`--accessToken=${accessToken}`,
|
|
114
115
|
]);
|
|
115
116
|
const backportResult = JSON.parse(output);
|
|
116
|
-
expect(backportResult.status).toBe('
|
|
117
|
-
expect
|
|
117
|
+
expect(backportResult.status).toBe('success');
|
|
118
|
+
//@ts-expect-error
|
|
119
|
+
expect(backportResult.results[0].error).toEqual({
|
|
118
120
|
name: 'BackportError',
|
|
119
121
|
errorContext: {
|
|
120
|
-
code: '
|
|
121
|
-
|
|
122
|
+
code: 'invalid-branch-exception',
|
|
123
|
+
branchName: '--foo bar',
|
|
122
124
|
},
|
|
123
125
|
});
|
|
124
126
|
});
|
package/dist/test/nockHelpers.js
CHANGED
|
@@ -12,6 +12,7 @@ const nock_1 = __importDefault(require("nock"));
|
|
|
12
12
|
function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
|
|
13
13
|
const { origin, pathname } = new url_1.URL(
|
|
14
14
|
// default to localhost as host to avoid CORS issues
|
|
15
|
+
// Remember to set `githubApiBaseUrlV4: 'http://localhost/graphql'` in options
|
|
15
16
|
apiBaseUrl ?? 'http://localhost/graphql');
|
|
16
17
|
const scope = (0, nock_1.default)(origin)
|
|
17
18
|
.post(pathname, (body) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "8.5.
|
|
1
|
+
export declare const PACKAGE_VERSION = "8.5.3";
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export interface TargetBranchResponse {
|
|
3
|
-
repository: {
|
|
4
|
-
ref: {
|
|
5
|
-
id: string;
|
|
6
|
-
} | null;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export declare function validateTargetBranches({ accessToken, repoName, repoOwner, githubApiBaseUrlV4 }: ValidConfigOptions, targetBranches: string[]): Promise<void>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
-
const validateTargetBranches_1 = require("./validateTargetBranches");
|
|
5
|
-
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
-
describe('validateTargetBranches', () => {
|
|
7
|
-
describe('no branches', () => {
|
|
8
|
-
it('resolves', async () => {
|
|
9
|
-
const options = {
|
|
10
|
-
repoOwner: 'backport-org',
|
|
11
|
-
repoName: 'repo-with-target-branches',
|
|
12
|
-
accessToken,
|
|
13
|
-
};
|
|
14
|
-
const targetBranches = [];
|
|
15
|
-
expect(await (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).toEqual(undefined);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('one invalid and one valid branch', () => {
|
|
19
|
-
it('throws', async () => {
|
|
20
|
-
const options = {
|
|
21
|
-
repoOwner: 'backport-org',
|
|
22
|
-
repoName: 'repo-with-target-branches',
|
|
23
|
-
accessToken,
|
|
24
|
-
};
|
|
25
|
-
const targetBranches = ['production', 'foo'];
|
|
26
|
-
await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).rejects.toThrowError('The branch "foo" does not exist');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
describe('two valid branches', () => {
|
|
30
|
-
it('resolves', async () => {
|
|
31
|
-
const options = {
|
|
32
|
-
repoOwner: 'backport-org',
|
|
33
|
-
repoName: 'repo-with-target-branches',
|
|
34
|
-
accessToken,
|
|
35
|
-
};
|
|
36
|
-
const targetBranches = ['production', 'staging'];
|
|
37
|
-
expect(await (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).toEqual(undefined);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe('two invalid branches', () => {
|
|
41
|
-
it('throws', async () => {
|
|
42
|
-
const options = {
|
|
43
|
-
repoOwner: 'backport-org',
|
|
44
|
-
repoName: 'repo-with-target-branches',
|
|
45
|
-
accessToken,
|
|
46
|
-
};
|
|
47
|
-
const targetBranches = ['foo', 'bar'];
|
|
48
|
-
await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).rejects.toThrow(/The branch "(foo|bar)" does not exist/);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|