backport 7.0.1-beta.1 → 7.2.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/dist/backportRun.d.ts +1 -0
- package/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.e2e.private.test.js +74 -7
- package/dist/entrypoint.cli.js +12 -1
- package/dist/options/cliArgs.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +1 -5
- package/dist/options/options.test.js +26 -28
- package/dist/runSequentially.js +1 -0
- package/dist/runSequentially.test.js +3 -2
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.d.ts +2 -0
- package/dist/services/git.integration.test.js +66 -13
- package/dist/services/git.js +47 -10
- 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/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +6 -2
- package/dist/services/github/v4/apiRequestV4.js +8 -8
- 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 +23 -12
- 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 +23 -12
- 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 +19 -9
- 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 +19 -8
- 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 +0 -4
- 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 +5 -0
- 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/getMockSourceCommit.d.ts +4 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +20 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
- package/dist/services/sourceCommit/parseSourceCommit.js +73 -71
- package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
- package/dist/test/nockHelpers.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +4 -0
- package/dist/ui/getCommits.js +2 -2
- 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 +3 -3
- package/dist/services/github/v3/index.d.ts +0 -1
- package/dist/services/github/v3/index.js +0 -61
package/dist/backportRun.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export declare type BackportResponse = {
|
|
|
10
10
|
status: 'failure';
|
|
11
11
|
commits: Commit[];
|
|
12
12
|
error: Error | HandledError;
|
|
13
|
+
errorMessage: string;
|
|
13
14
|
};
|
|
14
15
|
export declare function backportRun(processArgs: string[], optionsFromModule?: ConfigFileOptions): Promise<BackportResponse>;
|
package/dist/backportRun.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.backportRun = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const ora_1 = __importDefault(require("ora"));
|
|
9
8
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
10
9
|
const options_1 = require("./options/options");
|
|
11
10
|
const runSequentially_1 = require("./runSequentially");
|
|
@@ -16,13 +15,14 @@ const apiRequestV4_1 = require("./services/github/v4/apiRequestV4");
|
|
|
16
15
|
const logger_1 = require("./services/logger");
|
|
17
16
|
const getCommits_1 = require("./ui/getCommits");
|
|
18
17
|
const getTargetBranches_1 = require("./ui/getTargetBranches");
|
|
18
|
+
const ora_1 = require("./ui/ora");
|
|
19
19
|
async function backportRun(processArgs, optionsFromModule = {}) {
|
|
20
20
|
const argv = (0, yargs_parser_1.default)(processArgs);
|
|
21
21
|
const ci = argv.ci ?? optionsFromModule.ci;
|
|
22
22
|
const logFilePath = argv.logFilePath ?? optionsFromModule.logFilePath;
|
|
23
23
|
(0, logger_1.initLogger)({ ci, logFilePath });
|
|
24
24
|
// don't show spinner for yargs commands that exit the process without stopping the spinner first
|
|
25
|
-
const spinner = (0, ora_1.
|
|
25
|
+
const spinner = (0, ora_1.ora)(ci);
|
|
26
26
|
if (!argv.help && !argv.version && !argv.v) {
|
|
27
27
|
spinner.start('Initializing...');
|
|
28
28
|
}
|
|
@@ -55,6 +55,7 @@ async function backportRun(processArgs, optionsFromModule = {}) {
|
|
|
55
55
|
status: 'failure',
|
|
56
56
|
commits,
|
|
57
57
|
error: e,
|
|
58
|
+
errorMessage: e.message,
|
|
58
59
|
};
|
|
59
60
|
if (options) {
|
|
60
61
|
await (0, createStatusComment_1.createStatusComment)({
|
|
@@ -251,6 +251,62 @@ describe('inquirer cli', () => {
|
|
|
251
251
|
6. Bump to 8.0.0"
|
|
252
252
|
`);
|
|
253
253
|
});
|
|
254
|
+
describe('repo: repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
|
|
255
|
+
it('should list commits', async () => {
|
|
256
|
+
const output = await runBackportAsync([
|
|
257
|
+
'--branch',
|
|
258
|
+
'foo',
|
|
259
|
+
'--repo',
|
|
260
|
+
'backport-org/repo-with-backportrc-removed',
|
|
261
|
+
'--accessToken',
|
|
262
|
+
devAccessToken,
|
|
263
|
+
], { waitForString: 'Select commit' });
|
|
264
|
+
expect(output).toMatchInlineSnapshot(`
|
|
265
|
+
"? Select commit (Use arrow keys)
|
|
266
|
+
❯ 1. Rename README.me to README.md
|
|
267
|
+
2. Merge pull request #1 from backport-org/add-readme
|
|
268
|
+
3. Create README.me
|
|
269
|
+
4. Delete .backportrc.json
|
|
270
|
+
5. Create .backportrc.json
|
|
271
|
+
6. Delete .backportrc.json
|
|
272
|
+
7. Create .backportrc.json"
|
|
273
|
+
`);
|
|
274
|
+
});
|
|
275
|
+
it('should attempt to backport by PR', async () => {
|
|
276
|
+
const output = await runBackportAsync([
|
|
277
|
+
'--branch',
|
|
278
|
+
'foo',
|
|
279
|
+
'--repo',
|
|
280
|
+
'backport-org/repo-with-backportrc-removed',
|
|
281
|
+
'--pr',
|
|
282
|
+
'1',
|
|
283
|
+
'--accessToken',
|
|
284
|
+
devAccessToken,
|
|
285
|
+
], { waitForString: "is invalid or doesn't exist" });
|
|
286
|
+
expect(output).toMatchInlineSnapshot(`
|
|
287
|
+
"
|
|
288
|
+
Backporting to foo:
|
|
289
|
+
The branch \\"foo\\" is invalid or doesn't exist"
|
|
290
|
+
`);
|
|
291
|
+
});
|
|
292
|
+
it('should attempt to backport by commit sha', async () => {
|
|
293
|
+
const output = await runBackportAsync([
|
|
294
|
+
'--branch',
|
|
295
|
+
'foo',
|
|
296
|
+
'--repo',
|
|
297
|
+
'backport-org/repo-with-backportrc-removed',
|
|
298
|
+
'--sha',
|
|
299
|
+
'be59df6912a550c8cb49ba3e18be3e512f3d608c',
|
|
300
|
+
'--accessToken',
|
|
301
|
+
devAccessToken,
|
|
302
|
+
], { waitForString: "is invalid or doesn't exist" });
|
|
303
|
+
expect(output).toMatchInlineSnapshot(`
|
|
304
|
+
"
|
|
305
|
+
Backporting to foo:
|
|
306
|
+
The branch \\"foo\\" is invalid or doesn't exist"
|
|
307
|
+
`);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
254
310
|
describe('repo: different-merge-strategies', () => {
|
|
255
311
|
it('list all commits regardless how they were merged', async () => {
|
|
256
312
|
jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
|
|
@@ -263,16 +319,27 @@ describe('inquirer cli', () => {
|
|
|
263
319
|
'different-merge-strategies',
|
|
264
320
|
'--accessToken',
|
|
265
321
|
devAccessToken,
|
|
322
|
+
'-n',
|
|
323
|
+
'20',
|
|
266
324
|
], { waitForString: 'Select commit' });
|
|
267
325
|
expect(output).toMatchInlineSnapshot(`
|
|
268
326
|
"? Select commit (Use arrow keys)
|
|
269
|
-
❯ 1.
|
|
270
|
-
2.
|
|
271
|
-
3.
|
|
272
|
-
4. Merge
|
|
273
|
-
5. Merge strategy:
|
|
274
|
-
6. Merge strategy:
|
|
275
|
-
7.
|
|
327
|
+
❯ 1. Merge pull request #9 from backport-org/many-merge-commits
|
|
328
|
+
2. Merge strategy: Eighth of many merges
|
|
329
|
+
3. Merge strategy: Seventh of many merges
|
|
330
|
+
4. Merge strategy: Sixth of many merges
|
|
331
|
+
5. Merge strategy: Fifth of many merges
|
|
332
|
+
6. Merge strategy: Fourth of many merges
|
|
333
|
+
7. Merge strategy: Third of many merges
|
|
334
|
+
8. Merge strategy: Second of many merges
|
|
335
|
+
9. Merge strategy: First of many merges
|
|
336
|
+
10.Using squash to merge commits (#3) 7.x
|
|
337
|
+
11.Rebase strategy: Second commit 7.x
|
|
338
|
+
12.Rebase strategy: First commit
|
|
339
|
+
13.Merge pull request #1 from backport-org/merge-strategy
|
|
340
|
+
14.Merge strategy: Second commit
|
|
341
|
+
15.Merge strategy: First commit
|
|
342
|
+
16.Initial commit"
|
|
276
343
|
`);
|
|
277
344
|
});
|
|
278
345
|
});
|
package/dist/entrypoint.cli.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
4
8
|
const backportRun_1 = require("./backportRun");
|
|
5
9
|
const processArgs = process.argv.slice(2);
|
|
6
10
|
// this is the entrypoint when running from command line
|
|
7
|
-
(0, backportRun_1.backportRun)(processArgs)
|
|
11
|
+
(0, backportRun_1.backportRun)(processArgs).then((backportResponse) => {
|
|
12
|
+
const argv = (0, yargs_parser_1.default)(processArgs);
|
|
13
|
+
const ci = argv.ci;
|
|
14
|
+
if (ci) {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.log(JSON.stringify(backportResponse));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
@@ -5,6 +5,7 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
|
|
|
5
5
|
fork?: boolean | undefined;
|
|
6
6
|
dir?: string | undefined;
|
|
7
7
|
verbose?: boolean | undefined;
|
|
8
|
+
logFilePath?: string | undefined;
|
|
8
9
|
accessToken?: string | undefined;
|
|
9
10
|
author?: string | null | undefined;
|
|
10
11
|
autoAssign?: boolean | undefined;
|
|
@@ -20,7 +21,6 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
|
|
|
20
21
|
gitHostname?: string | undefined;
|
|
21
22
|
githubApiBaseUrlV3?: string | undefined;
|
|
22
23
|
githubApiBaseUrlV4?: string | undefined;
|
|
23
|
-
logFilePath?: string | undefined;
|
|
24
24
|
mainline?: number | undefined;
|
|
25
25
|
maxNumber?: number | undefined;
|
|
26
26
|
multipleBranches?: boolean | undefined;
|
|
@@ -5,6 +5,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
5
5
|
dir?: string | undefined;
|
|
6
6
|
help?: boolean | undefined;
|
|
7
7
|
verbose?: boolean | undefined;
|
|
8
|
+
logFilePath?: string | undefined;
|
|
8
9
|
accessToken?: string | undefined;
|
|
9
10
|
author?: string | null | undefined;
|
|
10
11
|
autoAssign?: boolean | undefined;
|
|
@@ -20,7 +21,6 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
20
21
|
gitHostname?: string | undefined;
|
|
21
22
|
githubApiBaseUrlV3?: string | undefined;
|
|
22
23
|
githubApiBaseUrlV4?: string | undefined;
|
|
23
|
-
logFilePath?: string | undefined;
|
|
24
24
|
maxNumber?: number | undefined;
|
|
25
25
|
multiple?: boolean | undefined;
|
|
26
26
|
multipleBranches?: boolean | undefined;
|
|
@@ -7,6 +7,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
7
7
|
fork: boolean;
|
|
8
8
|
dir?: string | undefined;
|
|
9
9
|
verbose: boolean;
|
|
10
|
+
logFilePath?: string | undefined;
|
|
10
11
|
author: string | null;
|
|
11
12
|
autoAssign: boolean;
|
|
12
13
|
assignees: string[];
|
|
@@ -21,7 +22,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
21
22
|
gitHostname: string;
|
|
22
23
|
githubApiBaseUrlV3?: string | undefined;
|
|
23
24
|
githubApiBaseUrlV4?: string | undefined;
|
|
24
|
-
logFilePath?: string | undefined;
|
|
25
25
|
mainline?: number | undefined;
|
|
26
26
|
maxNumber: number;
|
|
27
27
|
multipleBranches: boolean;
|
|
@@ -44,10 +44,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
44
44
|
targetBranches: string[];
|
|
45
45
|
targetPRLabels: string[];
|
|
46
46
|
publishStatusComment: boolean;
|
|
47
|
-
historicalBranchLabelMappings: {
|
|
48
|
-
branchLabelMapping: Record<string, string>;
|
|
49
|
-
committedDate: string;
|
|
50
|
-
}[];
|
|
51
47
|
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
52
48
|
files: string[];
|
|
53
49
|
directory: string;
|
|
@@ -126,6 +126,14 @@ describe('getOptions', () => {
|
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
|
+
it('reads options from remote config', async () => {
|
|
130
|
+
mockGithubConfigOptions({ hasRemoteConfig: true });
|
|
131
|
+
const options = await (0, options_1.getOptions)([], {});
|
|
132
|
+
expect(options.branchLabelMapping).toEqual({
|
|
133
|
+
'^v8.2.0$': 'option-from-remote',
|
|
134
|
+
});
|
|
135
|
+
expect(options.autoMergeMethod).toEqual('rebase');
|
|
136
|
+
});
|
|
129
137
|
it('should ensure that "backport" branch does not exist', async () => {
|
|
130
138
|
mockGithubConfigOptions({ hasBackportBranch: true });
|
|
131
139
|
await expect((0, options_1.getOptions)([], {})).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
@@ -145,12 +153,6 @@ describe('getOptions', () => {
|
|
|
145
153
|
mockGithubConfigOptions({
|
|
146
154
|
viewerLogin: 'john.diller',
|
|
147
155
|
defaultBranchRef: 'default-branch-from-github',
|
|
148
|
-
historicalMappings: [
|
|
149
|
-
{
|
|
150
|
-
committedDate: '2022-01-02T20:52:45.173Z',
|
|
151
|
-
branchLabelMapping: { foo: 'bar' },
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
156
|
});
|
|
155
157
|
const options = await (0, options_1.getOptions)([], {});
|
|
156
158
|
expect(options).toEqual({
|
|
@@ -162,9 +164,6 @@ describe('getOptions', () => {
|
|
|
162
164
|
autoMerge: false,
|
|
163
165
|
autoMergeMethod: 'merge',
|
|
164
166
|
backportBinary: 'backport',
|
|
165
|
-
branchLabelMapping: {
|
|
166
|
-
foo: 'bar',
|
|
167
|
-
},
|
|
168
167
|
cherrypickRef: true,
|
|
169
168
|
ci: false,
|
|
170
169
|
commitPaths: [],
|
|
@@ -176,12 +175,6 @@ describe('getOptions', () => {
|
|
|
176
175
|
fork: true,
|
|
177
176
|
gitHostname: 'github.com',
|
|
178
177
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
179
|
-
historicalBranchLabelMappings: [
|
|
180
|
-
{
|
|
181
|
-
branchLabelMapping: { foo: 'bar' },
|
|
182
|
-
committedDate: '2022-01-02T20:52:45.173Z',
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
178
|
maxNumber: 10,
|
|
186
179
|
multipleBranches: true,
|
|
187
180
|
multipleCommits: false,
|
|
@@ -325,7 +318,7 @@ function mockProjectConfig(projectConfig) {
|
|
|
325
318
|
},
|
|
326
319
|
});
|
|
327
320
|
}
|
|
328
|
-
function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch,
|
|
321
|
+
function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch, hasRemoteConfig, }) {
|
|
329
322
|
return (0, nockHelpers_1.mockGqlRequest)({
|
|
330
323
|
name: 'GithubConfigOptions',
|
|
331
324
|
statusCode: 200,
|
|
@@ -339,21 +332,26 @@ function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBran
|
|
|
339
332
|
defaultBranchRef: {
|
|
340
333
|
name: defaultBranchRef,
|
|
341
334
|
target: {
|
|
342
|
-
|
|
343
|
-
edges:
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
335
|
+
remoteConfigHistory: {
|
|
336
|
+
edges: hasRemoteConfig
|
|
337
|
+
? [
|
|
338
|
+
{
|
|
339
|
+
remoteConfig: {
|
|
340
|
+
committedDate: '2020-08-15T00:00:00.000Z',
|
|
341
|
+
file: {
|
|
342
|
+
object: {
|
|
343
|
+
text: JSON.stringify({
|
|
344
|
+
autoMergeMethod: 'rebase',
|
|
345
|
+
branchLabelMapping: {
|
|
346
|
+
'^v8.2.0$': 'option-from-remote',
|
|
347
|
+
},
|
|
348
|
+
}),
|
|
349
|
+
},
|
|
352
350
|
},
|
|
353
351
|
},
|
|
354
352
|
},
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
]
|
|
354
|
+
: [],
|
|
357
355
|
},
|
|
358
356
|
},
|
|
359
357
|
},
|
package/dist/runSequentially.js
CHANGED
|
@@ -77,7 +77,6 @@ describe('runSequentially', () => {
|
|
|
77
77
|
gitHostname: 'github.com',
|
|
78
78
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
79
79
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
80
|
-
historicalBranchLabelMappings: [],
|
|
81
80
|
mainline: undefined,
|
|
82
81
|
maxNumber: 10,
|
|
83
82
|
multipleBranches: false,
|
|
@@ -107,7 +106,7 @@ describe('runSequentially', () => {
|
|
|
107
106
|
};
|
|
108
107
|
rpcExecMock = jest
|
|
109
108
|
.spyOn(childProcess, 'exec')
|
|
110
|
-
.mockResolvedValue({ stdout: '
|
|
109
|
+
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
111
110
|
rpcExecOriginalMock = jest.spyOn(childProcess, 'execAsCallback');
|
|
112
111
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
113
112
|
.post('/repos/elastic/kibana/pulls')
|
|
@@ -184,6 +183,7 @@ describe('runSequentially', () => {
|
|
|
184
183
|
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
185
184
|
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
186
185
|
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
186
|
+
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
187
187
|
]);
|
|
188
188
|
});
|
|
189
189
|
it('exec commands should be called with correct args', () => {
|
|
@@ -196,6 +196,7 @@ describe('runSequentially', () => {
|
|
|
196
196
|
'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
197
197
|
'git reset --hard && git clean -d --force && git fetch elastic 7.x && git checkout -B backport/7.x/pr-55 elastic/7.x --no-track',
|
|
198
198
|
'git fetch elastic master:master --force',
|
|
199
|
+
'git rev-list -1 --merges abcd~1..abcd',
|
|
199
200
|
'git cherry-pick -x abcd',
|
|
200
201
|
'git push sqren_authenticated backport/7.x/pr-55:backport/7.x/pr-55 --force',
|
|
201
202
|
'git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55',
|
|
@@ -16,9 +16,11 @@ function getMessage(errorContext) {
|
|
|
16
16
|
}
|
|
17
17
|
class HandledError extends Error {
|
|
18
18
|
constructor(errorContext) {
|
|
19
|
-
|
|
19
|
+
const message = getMessage(errorContext);
|
|
20
|
+
super(message);
|
|
20
21
|
Error.captureStackTrace(this, HandledError);
|
|
21
22
|
this.name = 'HandledError';
|
|
23
|
+
this.message = message;
|
|
22
24
|
if (typeof errorContext !== 'string') {
|
|
23
25
|
this.errorContext = errorContext;
|
|
24
26
|
}
|
package/dist/services/git.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare function getIsCommitInBranch(options: ValidConfigOptions, commitS
|
|
|
28
28
|
export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
29
29
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
30
30
|
export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
|
|
31
|
+
export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
|
|
32
|
+
export declare function getCommitsInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
|
|
31
33
|
export declare function cherrypick(options: ValidConfigOptions, sha: string, mergedTargetPullRequest?: ExpectedTargetPullRequest): Promise<{
|
|
32
34
|
conflictingFiles: {
|
|
33
35
|
absolute: string;
|
|
@@ -31,19 +31,6 @@ const git_1 = require("./git");
|
|
|
31
31
|
const commitFormatters_1 = require("./github/commitFormatters");
|
|
32
32
|
jest.unmock('del');
|
|
33
33
|
jest.unmock('make-dir');
|
|
34
|
-
async function createAndCommitFile({ filename, content, execOpts, }) {
|
|
35
|
-
await childProcess.exec(`echo "${content}" > "${filename}"`, execOpts);
|
|
36
|
-
await childProcess.exec(`git add -A && git commit -m 'Update ${filename}'`, execOpts);
|
|
37
|
-
return getCurrentSha(execOpts);
|
|
38
|
-
}
|
|
39
|
-
async function getCurrentSha(execOpts) {
|
|
40
|
-
const { stdout } = await childProcess.exec('git rev-parse HEAD', execOpts);
|
|
41
|
-
return stdout.trim();
|
|
42
|
-
}
|
|
43
|
-
async function getCurrentMessage(execOpts) {
|
|
44
|
-
const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
|
|
45
|
-
return stdout.trim();
|
|
46
|
-
}
|
|
47
34
|
describe('git.integration', () => {
|
|
48
35
|
describe('getIsCommitInBranch', () => {
|
|
49
36
|
let firstSha;
|
|
@@ -239,7 +226,73 @@ describe('git.integration', () => {
|
|
|
239
226
|
expect(await (0, git_1.getSourceRepoPath)(options)).toBe('https://x-access-token:verysecret@github.com/not-a-match/kibana.git');
|
|
240
227
|
});
|
|
241
228
|
});
|
|
229
|
+
describe('when cloning "backport-org/different-merge-strategies"', () => {
|
|
230
|
+
const MERGE_COMMIT_HASH_1 = 'bdc5a17f81e5f32129e27b05c742e055c650bc54';
|
|
231
|
+
const MERGE_COMMIT_HASH_2 = '0db7f1ac1233461563d8708511d1c14adbab46da';
|
|
232
|
+
const SQUASH_COMMIT_HASH = '74a76fa64b34e3ffe8f2a3f73840e1b42fd07299';
|
|
233
|
+
const REBASE_COMMIT_HASH = '9059ae0ca31caa2eebc035f2542842d6c2fde83b';
|
|
234
|
+
let sandboxPath;
|
|
235
|
+
beforeAll(async () => {
|
|
236
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
237
|
+
filename: __filename,
|
|
238
|
+
specname: 'different-merge-strategies',
|
|
239
|
+
});
|
|
240
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
241
|
+
await childProcess.exec('git clone https://github.com/backport-org/different-merge-strategies.git ./', { cwd: sandboxPath });
|
|
242
|
+
});
|
|
243
|
+
describe('getIsMergeCommit', () => {
|
|
244
|
+
it('returns true for first merge commit', async () => {
|
|
245
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_1);
|
|
246
|
+
expect(res).toBe(true);
|
|
247
|
+
});
|
|
248
|
+
it('returns true for second merge commit', async () => {
|
|
249
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_2);
|
|
250
|
+
expect(res).toBe(true);
|
|
251
|
+
});
|
|
252
|
+
it('returns false for rebased commits', async () => {
|
|
253
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, REBASE_COMMIT_HASH);
|
|
254
|
+
expect(res).toBe(false);
|
|
255
|
+
});
|
|
256
|
+
it('returns false for squashed commits', async () => {
|
|
257
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, SQUASH_COMMIT_HASH);
|
|
258
|
+
expect(res).toBe(false);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
describe('getCommitsInMergeCommit', () => {
|
|
262
|
+
it('returns a list of commit hashes - excluding the merge hash itself', async () => {
|
|
263
|
+
const res = await (0, git_1.getCommitsInMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_1);
|
|
264
|
+
expect(res).not.toContain(MERGE_COMMIT_HASH_1);
|
|
265
|
+
expect(res).toEqual([
|
|
266
|
+
'f9a760e0d9eb3ebcc64f8cb75ce885714b836496',
|
|
267
|
+
'7b92e29e88266004485ce0fae0260605b01df887',
|
|
268
|
+
'a1facf8c006fb815d6a6ecd1b2907e6e64f29576',
|
|
269
|
+
'b8d4bcfb0fd875be4ab0230f6db40ddf72f45378',
|
|
270
|
+
'6f224054db5f7772b04f23f17659070216bae84c',
|
|
271
|
+
'7fed54cbd1ba9cb973462670ff82ac80bf8a79f8',
|
|
272
|
+
'78c24d0058859e7d511d10ce91ebf279c7b58ac2',
|
|
273
|
+
'709ccf707d443dd8c001b3c3ae40fdf037bb43f5',
|
|
274
|
+
]);
|
|
275
|
+
});
|
|
276
|
+
it('returns empty for squash commits', async () => {
|
|
277
|
+
const res = await (0, git_1.getCommitsInMergeCommit)({ dir: sandboxPath }, SQUASH_COMMIT_HASH);
|
|
278
|
+
expect(res).toEqual([]);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
});
|
|
242
282
|
});
|
|
283
|
+
async function createAndCommitFile({ filename, content, execOpts, }) {
|
|
284
|
+
await childProcess.exec(`echo "${content}" > "${filename}"`, execOpts);
|
|
285
|
+
await childProcess.exec(`git add -A && git commit -m 'Update ${filename}'`, execOpts);
|
|
286
|
+
return getCurrentSha(execOpts);
|
|
287
|
+
}
|
|
288
|
+
async function getCurrentSha(execOpts) {
|
|
289
|
+
const { stdout } = await childProcess.exec('git rev-parse HEAD', execOpts);
|
|
290
|
+
return stdout.trim();
|
|
291
|
+
}
|
|
292
|
+
async function getCurrentMessage(execOpts) {
|
|
293
|
+
const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
|
|
294
|
+
return stdout.trim();
|
|
295
|
+
}
|
|
243
296
|
function mockRepoOwnerAndName({ repoName, parentRepoOwner, childRepoOwner, }) {
|
|
244
297
|
return (0, nockHelpers_1.mockGqlRequest)({
|
|
245
298
|
name: 'RepoOwnerAndName',
|
package/dist/services/git.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
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
|
-
exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
|
|
3
|
+
exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
|
|
7
4
|
const path_1 = require("path");
|
|
8
5
|
const lodash_1 = require("lodash");
|
|
9
|
-
const ora_1 =
|
|
6
|
+
const ora_1 = require("../ui/ora");
|
|
10
7
|
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
11
8
|
const HandledError_1 = require("./HandledError");
|
|
12
9
|
const child_process_promisified_1 = require("./child-process-promisified");
|
|
@@ -159,10 +156,50 @@ async function fetchBranch(options, branch) {
|
|
|
159
156
|
});
|
|
160
157
|
}
|
|
161
158
|
exports.fetchBranch = fetchBranch;
|
|
159
|
+
async function getIsMergeCommit(options, sha) {
|
|
160
|
+
const res = await (0, child_process_promisified_1.exec)(`git rev-list -1 --merges ${sha}~1..${sha}`, {
|
|
161
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
162
|
+
});
|
|
163
|
+
return res.stdout !== '';
|
|
164
|
+
}
|
|
165
|
+
exports.getIsMergeCommit = getIsMergeCommit;
|
|
166
|
+
async function getCommitsInMergeCommit(options, sha) {
|
|
167
|
+
try {
|
|
168
|
+
const res = await (0, child_process_promisified_1.exec)(`git --no-pager log ${sha}^1..${sha}^2 --pretty=format:"%H"`, {
|
|
169
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
170
|
+
});
|
|
171
|
+
return res.stdout.split('\n');
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
// swallow error
|
|
175
|
+
if (e.code === 128) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
throw e;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
|
|
162
182
|
async function cherrypick(options, sha, mergedTargetPullRequest) {
|
|
163
183
|
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
164
184
|
const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
|
|
165
|
-
|
|
185
|
+
let shaOrRange = sha;
|
|
186
|
+
if (!options.mainline) {
|
|
187
|
+
try {
|
|
188
|
+
const isMergeCommit = await getIsMergeCommit(options, sha);
|
|
189
|
+
if (isMergeCommit) {
|
|
190
|
+
const shas = await getCommitsInMergeCommit(options, sha);
|
|
191
|
+
shaOrRange = `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
// swallow error if it's a known error
|
|
196
|
+
// exit 128 will happen for many things, among others when the cherrypicked commit is empty
|
|
197
|
+
if (e.code !== 128) {
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
|
|
166
203
|
try {
|
|
167
204
|
await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
|
|
168
205
|
return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
|
|
@@ -269,7 +306,7 @@ async function getUnstagedFiles(options) {
|
|
|
269
306
|
}
|
|
270
307
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
271
308
|
async function setCommitAuthor(options, author) {
|
|
272
|
-
const spinner = (0, ora_1.
|
|
309
|
+
const spinner = (0, ora_1.ora)(options.ci, `Changing author to "${author}"`).start();
|
|
273
310
|
try {
|
|
274
311
|
const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${author} <${author}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
275
312
|
spinner.succeed();
|
|
@@ -285,7 +322,7 @@ exports.setCommitAuthor = setCommitAuthor;
|
|
|
285
322
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
286
323
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
287
324
|
async function createBackportBranch({ options, targetBranch, backportBranch, }) {
|
|
288
|
-
const spinner = (0, ora_1.
|
|
325
|
+
const spinner = (0, ora_1.ora)(options.ci, 'Pulling latest changes').start();
|
|
289
326
|
try {
|
|
290
327
|
const res = await (0, child_process_promisified_1.exec)(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
291
328
|
spinner.succeed();
|
|
@@ -303,7 +340,7 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
303
340
|
}
|
|
304
341
|
exports.createBackportBranch = createBackportBranch;
|
|
305
342
|
async function deleteBackportBranch({ options, backportBranch, }) {
|
|
306
|
-
const spinner = (0, ora_1.
|
|
343
|
+
const spinner = (0, ora_1.ora)(options.ci).start();
|
|
307
344
|
await (0, child_process_promisified_1.exec)(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
308
345
|
spinner.stop();
|
|
309
346
|
}
|
|
@@ -317,7 +354,7 @@ function getRepoForkOwner(options) {
|
|
|
317
354
|
exports.getRepoForkOwner = getRepoForkOwner;
|
|
318
355
|
async function pushBackportBranch({ options, backportBranch, }) {
|
|
319
356
|
const repoForkOwner = getRepoForkOwner(options);
|
|
320
|
-
const spinner = (0, ora_1.
|
|
357
|
+
const spinner = (0, ora_1.ora)(options.ci, `Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
|
|
321
358
|
try {
|
|
322
359
|
const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
323
360
|
spinner.succeed();
|
|
@@ -275,7 +275,9 @@ describe('cherrypick', () => {
|
|
|
275
275
|
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
276
276
|
jest
|
|
277
277
|
.spyOn(childProcess, 'exec')
|
|
278
|
-
// mock
|
|
278
|
+
// mock getIsMergeCommit(...)
|
|
279
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
280
|
+
// mock cherrypick(...)
|
|
279
281
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
280
282
|
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
281
283
|
conflictingFiles: [],
|
|
@@ -286,6 +288,8 @@ describe('cherrypick', () => {
|
|
|
286
288
|
it('should use mainline option when specified', async () => {
|
|
287
289
|
const execSpy = jest
|
|
288
290
|
.spyOn(childProcess, 'exec')
|
|
291
|
+
// mock getIsMergeCommit(...)
|
|
292
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
289
293
|
// mock cherry pick command
|
|
290
294
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
291
295
|
await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
|
|
@@ -294,6 +298,8 @@ describe('cherrypick', () => {
|
|
|
294
298
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
295
299
|
jest
|
|
296
300
|
.spyOn(childProcess, 'exec')
|
|
301
|
+
// mock getIsMergeCommit(...)
|
|
302
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
297
303
|
// mock cherry pick command
|
|
298
304
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
299
305
|
killed: false,
|
|
@@ -325,6 +331,8 @@ describe('cherrypick', () => {
|
|
|
325
331
|
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
326
332
|
jest
|
|
327
333
|
.spyOn(childProcess, 'exec')
|
|
334
|
+
// mock getIsMergeCommit(...)
|
|
335
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
328
336
|
// mock cherry pick command
|
|
329
337
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
330
338
|
killed: false,
|
|
@@ -348,6 +356,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
348
356
|
it('should gracefully handle empty commits', async () => {
|
|
349
357
|
jest
|
|
350
358
|
.spyOn(childProcess, 'exec')
|
|
359
|
+
// mock getIsMergeCommit(...)
|
|
360
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
351
361
|
// mock cherry pick command
|
|
352
362
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
353
363
|
killed: false,
|
|
@@ -362,6 +372,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
362
372
|
it('gracefully handles missing git info', async () => {
|
|
363
373
|
jest
|
|
364
374
|
.spyOn(childProcess, 'exec')
|
|
375
|
+
// mock getIsMergeCommit(...)
|
|
376
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
365
377
|
// mock cherry pick command
|
|
366
378
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
367
379
|
killed: false,
|
|
@@ -392,6 +404,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
392
404
|
it('should re-throw non-cherrypick errors', async () => {
|
|
393
405
|
jest
|
|
394
406
|
.spyOn(childProcess, 'exec')
|
|
407
|
+
// mock getIsMergeCommit(...)
|
|
408
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
395
409
|
// mock cherry pick command
|
|
396
410
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
397
411
|
// getConflictingFiles
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
|
|
2
|
+
export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, ci, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
|