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.
Files changed (91) hide show
  1. package/dist/backportRun.d.ts +1 -0
  2. package/dist/backportRun.js +3 -2
  3. package/dist/entrypoint.cli.js +12 -1
  4. package/dist/entrypoint.module.d.ts +4 -3
  5. package/dist/entrypoint.module.js +2 -7
  6. package/dist/options/ConfigOptions.d.ts +1 -1
  7. package/dist/options/cliArgs.d.ts +2 -1
  8. package/dist/options/cliArgs.js +4 -0
  9. package/dist/options/config/config.d.ts +1 -1
  10. package/dist/options/config/readConfigFile.d.ts +2 -2
  11. package/dist/options/options.d.ts +3 -6
  12. package/dist/options/options.test.js +26 -28
  13. package/dist/runSequentially.js +1 -0
  14. package/dist/runSequentially.test.js +55 -30
  15. package/dist/services/HandledError.js +3 -1
  16. package/dist/services/git.d.ts +3 -3
  17. package/dist/services/git.integration.test.js +66 -13
  18. package/dist/services/git.js +52 -13
  19. package/dist/services/git.test.js +15 -1
  20. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  21. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
  22. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  23. package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
  24. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
  25. package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
  26. package/dist/services/github/v3/createPullRequest.js +2 -5
  27. package/dist/services/github/v3/createStatusComment.js +1 -1
  28. package/dist/services/github/v4/FetchPullRequestId.js +5 -1
  29. package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
  30. package/dist/services/github/v4/apiRequestV4.js +22 -21
  31. package/dist/services/github/v4/apiRequestV4.test.js +38 -11
  32. package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
  33. package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
  34. package/dist/services/github/v4/fetchAuthorId.js +5 -1
  35. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -3
  36. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
  37. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +24 -13
  38. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +3 -12
  39. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
  40. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +24 -13
  41. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -11
  42. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
  43. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +20 -10
  44. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +7 -12
  45. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -1
  46. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +20 -9
  47. package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
  48. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
  49. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
  50. package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
  51. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -5
  52. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
  53. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -19
  54. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
  55. package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
  56. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
  57. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +2 -0
  58. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  59. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
  60. package/dist/services/logger.d.ts +5 -5
  61. package/dist/services/logger.js +24 -23
  62. package/dist/services/remoteConfig.d.ts +20 -0
  63. package/dist/services/remoteConfig.js +52 -0
  64. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  65. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  66. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +73 -39
  67. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
  68. package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
  69. package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
  70. package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
  71. package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
  72. package/dist/{entrypoint.cli.e2e.private.test.d.ts → test/e2e/cli.e2e.private.test.d.ts} +0 -0
  73. package/dist/{entrypoint.cli.e2e.private.test.js → test/e2e/cli.e2e.private.test.js} +153 -39
  74. package/dist/{services/github/v3/index.d.ts → test/e2e/module.e2e.private.test.d.ts} +0 -0
  75. package/dist/test/e2e/module.e2e.private.test.js +363 -0
  76. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -2
  77. package/dist/test/nockHelpers.js +6 -2
  78. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
  79. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -2
  80. package/dist/ui/getCommits.js +8 -6
  81. package/dist/ui/maybeSetupRepo.js +13 -16
  82. package/dist/ui/maybeSetupRepo.test.js +50 -16
  83. package/dist/ui/ora.d.ts +9 -0
  84. package/dist/ui/ora.js +21 -0
  85. package/dist/utils/packageVersion.d.ts +1 -1
  86. package/dist/utils/packageVersion.js +1 -1
  87. package/package.json +10 -10
  88. package/yarn.lock +121 -114
  89. package/dist/services/github/v3/index.js +0 -61
  90. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  91. package/dist/test/backport-e2e.mutation.test.js +0 -347
@@ -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>;
@@ -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.default)();
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)({
@@ -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
+ });
@@ -1,8 +1,9 @@
1
1
  import { ConfigFileOptions } from './options/ConfigOptions';
2
2
  import { ValidConfigOptions } from './options/options';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
3
4
  export { BackportResponse } from './backportRun';
4
5
  export { ConfigFileOptions } from './options/ConfigOptions';
5
- export { Commit } from './services/sourceCommit/parseSourceCommit';
6
+ export { Commit };
6
7
  export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
7
8
  export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
8
9
  export declare function backportRun(options: ConfigFileOptions, processArgs?: string[]): Promise<import("./backportRun").BackportResponse>;
@@ -14,9 +15,9 @@ export declare function getCommits(options: {
14
15
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
15
16
  githubApiBaseUrlV4?: string;
16
17
  pullNumber?: number;
17
- sha?: string;
18
+ sha?: string | string[];
18
19
  skipRemoteConfig?: boolean;
19
20
  sourceBranch?: string;
20
21
  dateUntil?: string;
21
22
  dateSince?: string;
22
- }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
23
+ }): Promise<Commit[]>;
@@ -37,13 +37,8 @@ async function getCommits(options) {
37
37
  ];
38
38
  }
39
39
  if (options.sha) {
40
- return [
41
- await (0, fetchCommitBySha_1.fetchCommitBySha)({
42
- ...optionsFromGithub,
43
- ...options,
44
- sha: options.sha,
45
- }),
46
- ];
40
+ const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
41
+ return Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...optionsFromGithub, ...options, sha })));
47
42
  }
48
43
  return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
49
44
  ...optionsFromGithub,
@@ -45,7 +45,7 @@ declare type Options = Partial<{
45
45
  repoOwner: string;
46
46
  resetAuthor: boolean;
47
47
  reviewers: string[];
48
- sha: string;
48
+ sha: string | string[];
49
49
  skipRemoteConfig: boolean;
50
50
  sourceBranch: string;
51
51
  sourcePRLabels: string[];
@@ -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;
@@ -15,12 +16,12 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
15
16
  cherrypickRef?: boolean | undefined;
16
17
  configFile?: string | undefined;
17
18
  details?: boolean | undefined;
19
+ dryRun?: boolean | undefined;
18
20
  editor?: string | undefined;
19
21
  skipRemoteConfig?: boolean | undefined;
20
22
  gitHostname?: string | undefined;
21
23
  githubApiBaseUrlV3?: string | undefined;
22
24
  githubApiBaseUrlV4?: string | undefined;
23
- logFilePath?: string | undefined;
24
25
  mainline?: number | undefined;
25
26
  maxNumber?: number | undefined;
26
27
  multipleBranches?: boolean | undefined;
@@ -83,6 +83,10 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
83
83
  .option('details', {
84
84
  description: 'Show details about each commit',
85
85
  type: 'boolean',
86
+ })
87
+ .option('dryRun', {
88
+ description: 'Run backport locally without pushing to Github',
89
+ type: 'boolean',
86
90
  })
87
91
  .option('editor', {
88
92
  description: 'Editor to be opened during conflict resolution',
@@ -45,7 +45,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
45
45
  repoOwner?: string | undefined;
46
46
  resetAuthor?: boolean | undefined;
47
47
  reviewers?: string[] | undefined;
48
- sha?: string | undefined;
48
+ sha?: string | string[] | undefined;
49
49
  skipRemoteConfig?: boolean | undefined;
50
50
  sourceBranch?: string | undefined;
51
51
  sourcePRLabels?: string[] | 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;
@@ -30,7 +30,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
30
30
  prTitle?: string | undefined;
31
31
  prFilter?: string | undefined;
32
32
  pullNumber?: number | undefined;
33
- sha?: string | undefined;
33
+ sha?: string | string[] | undefined;
34
34
  resetAuthor?: boolean | undefined;
35
35
  repoOwner?: string | undefined;
36
36
  repoName?: string | 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[];
@@ -16,12 +17,12 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
16
17
  cherrypickRef: boolean;
17
18
  configFile?: string | undefined;
18
19
  details: boolean;
20
+ dryRun?: boolean | undefined;
19
21
  editor?: string | undefined;
20
22
  skipRemoteConfig?: boolean | undefined;
21
23
  gitHostname: string;
22
24
  githubApiBaseUrlV3?: string | undefined;
23
25
  githubApiBaseUrlV4?: string | undefined;
24
- logFilePath?: string | undefined;
25
26
  mainline?: number | undefined;
26
27
  maxNumber: number;
27
28
  multipleBranches: boolean;
@@ -31,7 +32,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
31
32
  prTitle?: string | undefined;
32
33
  prFilter?: string | undefined;
33
34
  pullNumber?: number | undefined;
34
- sha?: string | undefined;
35
+ sha?: string | string[] | undefined;
35
36
  resetAuthor: boolean;
36
37
  sourceBranch: string;
37
38
  username?: string | undefined;
@@ -44,10 +45,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
44
45
  targetBranches: string[];
45
46
  targetPRLabels: string[];
46
47
  publishStatusComment: boolean;
47
- historicalBranchLabelMappings: {
48
- branchLabelMapping: Record<string, string>;
49
- committedDate: string;
50
- }[];
51
48
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
52
49
  files: string[];
53
50
  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, historicalMappings = [], }) {
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
- history: {
343
- edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
344
- return {
345
- remoteConfig: {
346
- committedDate,
347
- file: {
348
- object: {
349
- text: JSON.stringify({
350
- branchLabelMapping,
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
  },
@@ -26,6 +26,7 @@ async function runSequentially({ options, commits, targetBranches, }) {
26
26
  });
27
27
  }
28
28
  catch (e) {
29
+ process.exitCode = 1;
29
30
  results.push({
30
31
  targetBranch,
31
32
  status: 'failure',
@@ -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: 'success', stderr: '' });
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')
@@ -170,35 +169,61 @@ describe('runSequentially', () => {
170
169
  ]
171
170
  `);
172
171
  });
173
- it('should run all exec commands in the either source or backport directory', () => {
172
+ it('should run commands in correct folders', () => {
174
173
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
175
- expect(rpcExecMock.mock.calls.map(([cmd, opts]) => opts.cwd)).toEqual([
176
- '/path/to/source/repo',
177
- '/myHomeDir/.backport/repositories/elastic/kibana',
178
- '/myHomeDir/.backport/repositories/elastic/kibana',
179
- '/myHomeDir/.backport/repositories/elastic/kibana',
180
- '/myHomeDir/.backport/repositories/elastic/kibana',
181
- '/myHomeDir/.backport/repositories/elastic/kibana',
182
- '/myHomeDir/.backport/repositories/elastic/kibana',
183
- '/myHomeDir/.backport/repositories/elastic/kibana',
184
- '/myHomeDir/.backport/repositories/elastic/kibana',
185
- '/myHomeDir/.backport/repositories/elastic/kibana',
186
- '/myHomeDir/.backport/repositories/elastic/kibana',
187
- ]);
188
- });
189
- it('exec commands should be called with correct args', () => {
190
- expect(rpcExecMock.mock.calls.map(([cmd]) => cmd)).toEqual([
191
- 'git remote --verbose',
192
- 'git remote rm origin',
193
- 'git remote rm sqren_authenticated',
194
- 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
195
- 'git remote rm elastic',
196
- 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
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
- 'git fetch elastic master:master --force',
199
- 'git cherry-pick -x abcd',
200
- 'git push sqren_authenticated backport/7.x/pr-55:backport/7.x/pr-55 --force',
201
- 'git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55',
174
+ expect(rpcExecMock.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
175
+ {
176
+ cmd: 'git rev-parse --show-toplevel',
177
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
178
+ },
179
+ {
180
+ cmd: 'git remote --verbose',
181
+ cwd: '/path/to/source/repo',
182
+ },
183
+ {
184
+ cmd: 'git remote rm origin',
185
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
186
+ },
187
+ {
188
+ cmd: 'git remote rm sqren_authenticated',
189
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
190
+ },
191
+ {
192
+ cmd: 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
193
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
194
+ },
195
+ {
196
+ cmd: 'git remote rm elastic',
197
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
198
+ },
199
+ {
200
+ cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
201
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
202
+ },
203
+ {
204
+ cmd: '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',
205
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
206
+ },
207
+ {
208
+ cmd: 'git fetch elastic master:master --force',
209
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
210
+ },
211
+ {
212
+ cmd: 'git rev-list -1 --merges abcd~1..abcd',
213
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
214
+ },
215
+ {
216
+ cmd: 'git cherry-pick -x abcd',
217
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
218
+ },
219
+ {
220
+ cmd: 'git push sqren_authenticated backport/7.x/pr-55:backport/7.x/pr-55 --force',
221
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
222
+ },
223
+ {
224
+ cmd: 'git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55',
225
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
226
+ },
202
227
  ]);
203
228
  });
204
229
  it('git clone should be called with correct args', () => {
@@ -16,9 +16,11 @@ function getMessage(errorContext) {
16
16
  }
17
17
  class HandledError extends Error {
18
18
  constructor(errorContext) {
19
- super(getMessage(errorContext));
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
  }
@@ -21,13 +21,13 @@ export declare function getRepoInfoFromGitRemotes({ cwd }: {
21
21
  repoOwner: string;
22
22
  repoName: string;
23
23
  }[]>;
24
- export declare function getGitProjectRoot({ cwd }: {
25
- cwd: string;
26
- }): Promise<string | undefined>;
24
+ export declare function getGitProjectRoot(dir: string): Promise<string | undefined>;
27
25
  export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
28
26
  export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
29
27
  export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
30
28
  export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
29
+ export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
30
+ export declare function getCommitsInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
31
31
  export declare function cherrypick(options: ValidConfigOptions, sha: string, mergedTargetPullRequest?: ExpectedTargetPullRequest): Promise<{
32
32
  conflictingFiles: {
33
33
  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',