backport 6.0.0 → 6.1.0

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 (98) hide show
  1. package/README.md +158 -42
  2. package/dist/entrypoint.cli.js +2 -0
  3. package/dist/entrypoint.module.d.ts +16 -4
  4. package/dist/entrypoint.module.js +41 -13
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +33 -0
  7. package/dist/main.js +1 -2
  8. package/dist/options/ConfigOptions.d.ts +15 -6
  9. package/dist/options/cliArgs.d.ts +33 -34
  10. package/dist/options/cliArgs.js +19 -19
  11. package/dist/options/cliArgs.test.js +8 -5
  12. package/dist/options/config/config.d.ts +27 -52
  13. package/dist/options/config/config.js +2 -36
  14. package/dist/options/config/config.test.js +10 -27
  15. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -3
  17. package/dist/options/config/globalConfig.js +1 -4
  18. package/dist/options/config/globalConfig.test.js +0 -2
  19. package/dist/options/config/projectConfig.test.js +51 -14
  20. package/dist/options/config/readConfigFile.d.ts +51 -0
  21. package/dist/options/config/readConfigFile.js +28 -2
  22. package/dist/options/options.d.ts +52 -33
  23. package/dist/options/options.js +98 -7
  24. package/dist/options/options.test.js +180 -73
  25. package/dist/options/parseRequiredOptions.d.ts +3 -3
  26. package/dist/options/parseRequiredOptions.js +2 -4
  27. package/dist/options/parseRequiredOptions.test.js +6 -11
  28. package/dist/runSequentially.test.js +35 -78
  29. package/dist/services/git.d.ts +5 -2
  30. package/dist/services/git.js +11 -10
  31. package/dist/services/git.test.js +12 -9
  32. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  33. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
  34. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
  35. package/dist/services/github/v3/createPullRequest.js +10 -13
  36. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  37. package/dist/services/github/v3/createPullRequest.test.js +78 -0
  38. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  39. package/dist/services/github/v4/apiRequestV4.js +1 -1
  40. package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
  41. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
  42. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  43. package/dist/services/github/v4/fetchAuthorId.js +5 -6
  44. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  45. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
  46. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
  48. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
  49. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
  51. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
  52. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
  53. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
  54. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
  55. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  56. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  57. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
  58. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
  59. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
  60. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  61. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  62. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  63. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  64. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  65. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  66. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  67. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  68. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  70. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
  71. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
  72. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
  73. package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
  74. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +15 -15
  75. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
  76. package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
  77. package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
  78. package/dist/test/inquirer.private.test.js +42 -34
  79. package/dist/test/integration/integration.private.test.js +104 -95
  80. package/dist/test/mockConfigFiles.d.ts +5 -0
  81. package/dist/test/mockConfigFiles.js +37 -0
  82. package/dist/test/nockHelpers.d.ts +1 -1
  83. package/dist/test/nockHelpers.js +4 -4
  84. package/dist/test/private/getDevAccessToken.js +1 -1
  85. package/dist/test/setupFiles/automatic-mocks.js +1 -29
  86. package/dist/ui/cherrypickAndCreatePullRequest.test.js +67 -28
  87. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +6 -3
  88. package/dist/ui/getCommits.d.ts +1 -1
  89. package/dist/ui/getTargetBranches.d.ts +2 -1
  90. package/dist/ui/getTargetBranches.js +17 -1
  91. package/dist/ui/maybeSetupRepo.js +4 -3
  92. package/dist/ui/maybeSetupRepo.test.js +49 -3
  93. package/dist/utils/excludeUndefined.d.ts +6 -0
  94. package/dist/utils/excludeUndefined.js +7 -0
  95. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  96. package/dist/utils/excludeUndefined.test.js +24 -0
  97. package/package.json +9 -8
  98. package/yarn.lock +98 -77
@@ -24,156 +24,263 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const nock_1 = __importDefault(require("nock"));
26
26
  const logger = __importStar(require("../services/logger"));
27
+ const mockConfigFiles_1 = require("../test/mockConfigFiles");
27
28
  const nockHelpers_1 = require("../test/nockHelpers");
28
29
  const options_1 = require("./options");
29
- function mockGetGithubConfigOptions({ defaultBranch, refName, }) {
30
+ jest.unmock('../services/fs-promisified');
31
+ function mockGithubConfigOptions({ viewerLogin = 'sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', refName, historicalMappings = [], }) {
30
32
  return (0, nockHelpers_1.mockGqlRequest)({
31
33
  name: 'GithubConfigOptions',
32
34
  statusCode: 200,
33
35
  body: {
34
36
  data: {
37
+ viewer: {
38
+ login: viewerLogin,
39
+ },
35
40
  repository: {
36
41
  isFork: false,
37
42
  parent: null,
38
43
  ref: refName ? { name: refName } : null,
39
44
  defaultBranchRef: {
40
- name: defaultBranch,
41
- target: { history: { edges: [] } },
45
+ name: defaultBranchRef,
46
+ target: {
47
+ history: {
48
+ edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
49
+ return {
50
+ remoteConfig: {
51
+ committedDate,
52
+ file: {
53
+ object: {
54
+ text: JSON.stringify({
55
+ branchLabelMapping,
56
+ }),
57
+ },
58
+ },
59
+ },
60
+ };
61
+ }),
62
+ },
63
+ },
42
64
  },
43
65
  },
44
66
  },
45
67
  },
46
68
  });
47
69
  }
48
- describe('getOptions', () => {
49
- const defaultArgs = [
50
- '--branch',
51
- '6.0',
52
- '--branch',
53
- '6.1',
54
- '--upstream',
55
- 'elastic/kibana',
70
+ const defaultConfigs = {
71
+ projectConfig: {
56
72
  // use localhost to avoid CORS issues with nock
57
- '--github-api-base-url-v4',
58
- 'http://localhost/graphql',
59
- ];
73
+ githubApiBaseUrlV4: 'http://localhost/graphql',
74
+ repoOwner: 'elastic',
75
+ repoName: 'kibana',
76
+ targetBranchChoices: ['7.9', '8.0'],
77
+ },
78
+ globalConfig: { accessToken: 'abc', editor: 'code' },
79
+ };
80
+ describe('getOptions', () => {
60
81
  afterEach(() => {
61
82
  jest.clearAllMocks();
62
83
  nock_1.default.cleanAll();
63
84
  });
64
- it('should use the default repository branch as sourceBranch', async () => {
65
- const mockCalls = mockGetGithubConfigOptions({
66
- defaultBranch: 'my-default-branch',
85
+ beforeEach(() => {
86
+ (0, mockConfigFiles_1.mockConfigFiles)(defaultConfigs);
87
+ });
88
+ describe('should throw', () => {
89
+ beforeEach(() => {
90
+ mockGithubConfigOptions({});
91
+ });
92
+ it('when accessToken is missing', async () => {
93
+ (0, mockConfigFiles_1.mockConfigFiles)({
94
+ projectConfig: defaultConfigs.projectConfig,
95
+ globalConfig: { accessToken: undefined },
96
+ });
97
+ await expect(() => (0, options_1.getOptions)([])).rejects
98
+ .toThrowErrorMatchingInlineSnapshot(`
99
+ "Please update your config file: /Users/sqren/.backport/config.json.
100
+ It must contain a valid \\"accessToken\\".
101
+
102
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
103
+ `);
104
+ });
105
+ it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
106
+ (0, mockConfigFiles_1.mockConfigFiles)({
107
+ projectConfig: {
108
+ ...defaultConfigs.projectConfig,
109
+ targetBranchChoices: undefined,
110
+ branchLabelMapping: undefined,
111
+ },
112
+ globalConfig: { accessToken: 'abc' },
113
+ });
114
+ await expect(() => (0, options_1.getOptions)([])).rejects
115
+ .toThrowErrorMatchingInlineSnapshot(`
116
+ "Please specify a target branch: \\"--branch 6.1\\".
117
+
118
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
119
+ `);
120
+ });
121
+ it('when repoName is missing', async () => {
122
+ (0, mockConfigFiles_1.mockConfigFiles)({
123
+ projectConfig: {
124
+ ...defaultConfigs.projectConfig,
125
+ repoName: '',
126
+ },
127
+ globalConfig: { accessToken: 'abc' },
128
+ });
129
+ await expect(() => (0, options_1.getOptions)([])).rejects
130
+ .toThrowErrorMatchingInlineSnapshot(`
131
+ "Please specify a repo name: \\"--repo-name kibana\\".
132
+
133
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
134
+ `);
135
+ });
136
+ it('when repoOwner is missing', async () => {
137
+ (0, mockConfigFiles_1.mockConfigFiles)({
138
+ projectConfig: {
139
+ ...defaultConfigs.projectConfig,
140
+ repoOwner: '',
141
+ },
142
+ globalConfig: { accessToken: 'abc' },
143
+ });
144
+ await expect(() => (0, options_1.getOptions)([])).rejects
145
+ .toThrowErrorMatchingInlineSnapshot(`
146
+ "Please specify a repo owner: \\"--repo-owner elastic\\".
147
+
148
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
149
+ `);
67
150
  });
68
- const options = await (0, options_1.getOptions)(defaultArgs);
69
- expect(mockCalls.length).toBe(1);
70
- expect(options.sourceBranch).toBe('my-default-branch');
71
151
  });
72
- it('should use explicit sourceBranch instead of defaultBranch', async () => {
73
- const argv = [
74
- '--branch',
75
- '6.0',
76
- '--branch',
77
- '6.1',
78
- '--upstream',
79
- 'elastic/kibana',
80
- '--source-branch',
81
- 'my-source-branch',
82
- '--github-api-base-url-v4',
83
- 'http://localhost/graphql',
84
- ];
85
- mockGetGithubConfigOptions({ defaultBranch: 'my-default-branch' });
86
- const options = await (0, options_1.getOptions)(argv);
87
- expect(options.sourceBranch).toBe('my-source-branch');
152
+ describe('sourceBranch', () => {
153
+ beforeEach(() => {
154
+ mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
155
+ });
156
+ it('uses the `defaultBranchRef` as default', async () => {
157
+ const options = await (0, options_1.getOptions)([]);
158
+ expect(options.sourceBranch).toBe('some-default-branch');
159
+ });
160
+ it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
161
+ const options = await (0, options_1.getOptions)([
162
+ '--source-branch',
163
+ 'cli-source-branch',
164
+ ]);
165
+ expect(options.sourceBranch).toBe('cli-source-branch');
166
+ });
88
167
  });
89
168
  it('should ensure that "backport" branch does not exist', async () => {
90
- mockGetGithubConfigOptions({
91
- defaultBranch: 'my-default-branch',
169
+ mockGithubConfigOptions({
92
170
  refName: 'backport',
93
171
  });
94
- await expect((0, options_1.getOptions)(defaultArgs)).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
172
+ 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');
95
173
  });
96
174
  it('should merge config options and module options', async () => {
97
- mockGetGithubConfigOptions({ defaultBranch: 'my-default-branch' });
175
+ mockGithubConfigOptions({});
98
176
  const myFn = async () => true;
99
- const options = await (0, options_1.getOptions)(defaultArgs, { autoFixConflicts: myFn });
177
+ const options = await (0, options_1.getOptions)([], { autoFixConflicts: myFn });
100
178
  expect(options.autoFixConflicts).toBe(myFn);
101
179
  });
102
180
  it('should call updateLogger', async () => {
103
- mockGetGithubConfigOptions({ defaultBranch: 'my-default-branch' });
104
- await (0, options_1.getOptions)(defaultArgs);
181
+ mockGithubConfigOptions({});
182
+ await (0, options_1.getOptions)([]);
105
183
  expect(logger.updateLogger).toHaveBeenCalledTimes(1);
106
184
  });
107
185
  it('should return options', async () => {
108
- mockGetGithubConfigOptions({ defaultBranch: 'default-branch-from-github' });
109
- const options = await (0, options_1.getOptions)(defaultArgs);
186
+ mockGithubConfigOptions({
187
+ defaultBranchRef: 'default-branch-from-github',
188
+ historicalMappings: [
189
+ {
190
+ committedDate: '2022-01-02T20:52:45.173Z',
191
+ branchLabelMapping: { foo: 'bar' },
192
+ },
193
+ ],
194
+ });
195
+ const options = await (0, options_1.getOptions)([]);
110
196
  expect(options).toEqual({
111
- accessToken: 'myAccessToken',
112
- all: false,
197
+ accessToken: 'abc',
113
198
  assignees: [],
114
- author: 'sqren',
115
199
  autoAssign: false,
116
200
  autoMerge: false,
117
201
  autoMergeMethod: 'merge',
118
- ci: false,
202
+ authenticatedUsername: 'sqren',
203
+ branchLabelMapping: {
204
+ foo: 'bar',
205
+ },
119
206
  cherrypickRef: true,
207
+ ci: false,
208
+ commitPaths: [],
120
209
  details: false,
210
+ editor: 'code',
121
211
  fork: true,
122
- gitHostname: 'github.com',
123
- githubApiBaseUrlV3: 'https://api.github.com',
124
212
  githubApiBaseUrlV4: 'http://localhost/graphql',
125
- commitPaths: [],
213
+ historicalBranchLabelMappings: [
214
+ {
215
+ branchLabelMapping: { foo: 'bar' },
216
+ committedDate: '2022-01-02T20:52:45.173Z',
217
+ },
218
+ ],
126
219
  mainline: 1,
127
220
  maxNumber: 10,
128
221
  multipleBranches: true,
129
222
  multipleCommits: false,
130
223
  noVerify: true,
131
- prTitle: '[{targetBranch}] {commitMessages}',
132
224
  repoName: 'kibana',
133
225
  repoOwner: 'elastic',
134
226
  resetAuthor: false,
135
227
  reviewers: [],
136
228
  sourceBranch: 'default-branch-from-github',
137
229
  sourcePRLabels: [],
138
- targetBranchChoices: [
139
- { checked: false, name: '6.0' },
140
- { checked: false, name: '5.9' },
141
- ],
142
- targetBranches: ['6.0', '6.1'],
230
+ targetBranchChoices: ['7.9', '8.0'],
231
+ targetBranches: [],
143
232
  targetPRLabels: [],
144
- upstream: 'elastic/kibana',
145
- username: 'sqren',
233
+ author: 'sqren',
146
234
  verbose: false,
147
235
  });
148
236
  });
237
+ describe('author', () => {
238
+ beforeEach(() => {
239
+ mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
240
+ });
241
+ it('defaults to authenticated user', async () => {
242
+ const { author } = await (0, options_1.getOptions)([]);
243
+ expect(author).toBe('billy.bob');
244
+ });
245
+ it('can be overridden via cli args', async () => {
246
+ const { author } = await (0, options_1.getOptions)(['--author', 'john.doe']);
247
+ expect(author).toBe('john.doe');
248
+ });
249
+ it('can be overridden via config file', async () => {
250
+ (0, mockConfigFiles_1.mockConfigFiles)({
251
+ globalConfig: { accessToken: 'abc' },
252
+ projectConfig: {
253
+ author: 'jane.doe',
254
+ githubApiBaseUrlV4: 'http://localhost/graphql',
255
+ targetBranchChoices: ['7.9', '8.0'],
256
+ repoName: 'foo',
257
+ repoOwner: 'bar',
258
+ },
259
+ });
260
+ const { author } = await (0, options_1.getOptions)([]);
261
+ expect(author).toBe('jane.doe');
262
+ });
263
+ });
149
264
  describe('cherrypickRef', () => {
150
265
  beforeEach(() => {
151
- mockGetGithubConfigOptions({ defaultBranch: 'my-default-branch' });
266
+ mockGithubConfigOptions({});
152
267
  });
153
- const defaultArgs = [
154
- // use localhost to avoid CORS issues with nock
155
- '--github-api-base-url-v4',
156
- 'http://localhost/graphql',
157
- ];
158
268
  it('should default to true', async () => {
159
- const { cherrypickRef } = await (0, options_1.getOptions)(defaultArgs);
269
+ const { cherrypickRef } = await (0, options_1.getOptions)([]);
160
270
  expect(cherrypickRef).toBe(true);
161
271
  });
162
272
  it('should negate with `noCherrypickRef` cli arg', async () => {
163
- const { cherrypickRef } = await (0, options_1.getOptions)([
164
- ...defaultArgs,
165
- '--no-cherrypick-ref',
166
- ]);
273
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref']);
167
274
  expect(cherrypickRef).toBe(false);
168
275
  });
169
276
  it('should be settable via config file', async () => {
170
- const { cherrypickRef } = await (0, options_1.getOptions)([...defaultArgs], {
277
+ const { cherrypickRef } = await (0, options_1.getOptions)([], {
171
278
  cherrypickRef: false,
172
279
  });
173
280
  expect(cherrypickRef).toBe(false);
174
281
  });
175
282
  it('cli args overwrites config', async () => {
176
- const { cherrypickRef } = await (0, options_1.getOptions)([...defaultArgs, '--cherrypick-ref'], {
283
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref'], {
177
284
  cherrypickRef: false,
178
285
  });
179
286
  expect(cherrypickRef).toBe(true);
@@ -17,7 +17,7 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
17
17
  reviewers: string[];
18
18
  sourcePRLabels: (string[] | undefined) & (string[] | never[]);
19
19
  targetBranches: (string[] | undefined) & (string[] | never[]);
20
- targetPRLabels: string[];
20
+ targetPRLabels: (string[] | undefined) & (string[] | never[]);
21
21
  cherrypickRef: boolean;
22
22
  fork: boolean;
23
23
  noVerify: boolean;
@@ -40,7 +40,6 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
40
40
  resetAuthor: boolean;
41
41
  sha: string | undefined;
42
42
  sourceBranch: string;
43
- upstream: string | undefined;
44
43
  verbose: boolean;
45
44
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
46
45
  files: string[];
@@ -56,6 +55,7 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
56
55
  }) => boolean | Promise<boolean>) | undefined;
57
56
  multiple?: boolean | undefined;
58
57
  branchLabelMapping?: Record<string, string> | undefined;
58
+ upstream?: string | undefined;
59
59
  branches?: TargetBranchChoiceOrString[] | undefined;
60
60
  labels?: string[] | undefined;
61
61
  historicalBranchLabelMappings: {
@@ -63,7 +63,7 @@ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFrom
63
63
  committedDate: string;
64
64
  }[];
65
65
  };
66
- export declare function getRequiredOptions({ accessToken, username, upstream, }: ConfigFileOptions): {
66
+ export declare function getRequiredOptions({ accessToken, username, repoName, repoOwner, }: ConfigFileOptions): {
67
67
  accessToken: string;
68
68
  username: string;
69
69
  repoOwner: string;
@@ -54,16 +54,14 @@ function getTargetBranchChoicesAsObject(targetBranchChoices) {
54
54
  return choice;
55
55
  });
56
56
  }
57
- function getRequiredOptions({ accessToken, username, upstream, }) {
57
+ function getRequiredOptions({ accessToken, username, repoName, repoOwner, }) {
58
58
  // accessToken and username must be supplied in config or via cli args
59
59
  if (!accessToken || !username) {
60
60
  const globalConfigPath = (0, env_1.getGlobalConfigPath)();
61
61
  throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "username" and "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
62
62
  }
63
- // upstream must be specified via config or cli args
64
- const [repoOwner, repoName] = (upstream ?? '').split('/');
65
63
  if (!repoOwner || !repoName) {
66
- throw new HandledError_1.HandledError(`You must specify a valid Github repository\n\nYou can specify it via either:\n - Config file (recommended): ".backportrc.json". Read more: ${PROJECT_CONFIG_DOCS_LINK}\n - CLI: "--upstream elastic/kibana"`);
64
+ throw new HandledError_1.HandledError(`You must specify a valid Github repository\n\nYou can specify it via either:\n - Config file (recommended): ".backportrc.json". Read more: ${PROJECT_CONFIG_DOCS_LINK}\n - CLI: "--repo-owner elastic --repo-name kibana"`);
67
65
  }
68
66
  return { accessToken, username, repoOwner, repoName };
69
67
  }
@@ -14,7 +14,8 @@ describe('parseRequiredOptions', () => {
14
14
  ...config_1.defaultConfigOptions,
15
15
  accessToken: 'myAccessToken',
16
16
  username: 'sqren',
17
- upstream: 'elastic/kibana',
17
+ repoOwner: 'elastic',
18
+ repoName: 'kibana',
18
19
  targetBranches: ['branchA', 'branchB'],
19
20
  };
20
21
  const optionsFromCliArgs = {};
@@ -93,22 +94,16 @@ describe('parseRequiredOptions', () => {
93
94
  branchLabelMapping: {},
94
95
  }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
95
96
  });
96
- it('when upstream is missing', () => {
97
+ it('when repoName is missing', () => {
97
98
  expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
98
99
  ...optionsFromConfigFiles,
99
- upstream: undefined,
100
+ repoName: undefined,
100
101
  }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
101
102
  });
102
- it('when upstream is empty', () => {
103
+ it('when repoOwner is missing', () => {
103
104
  expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
104
105
  ...optionsFromConfigFiles,
105
- upstream: '',
106
- }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
107
- });
108
- it('when upstream is invalid', () => {
109
- expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
110
- ...optionsFromConfigFiles,
111
- upstream: 'foobar',
106
+ repoOwner: undefined,
112
107
  }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
113
108
  });
114
109
  it('when username is missing', () => {
@@ -56,9 +56,8 @@ describe('runSequentially', () => {
56
56
  jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
57
57
  const options = {
58
58
  accessToken: 'myAccessToken',
59
- all: false,
59
+ authenticatedUsername: 'sqren_authenticated',
60
60
  assignees: [],
61
- author: 'sqren',
62
61
  autoAssign: false,
63
62
  autoFixConflicts: undefined,
64
63
  autoMerge: false,
@@ -70,7 +69,7 @@ describe('runSequentially', () => {
70
69
  commitPaths: [],
71
70
  details: false,
72
71
  editor: 'code',
73
- forceLocalConfig: undefined,
72
+ skipRemoteConfig: undefined,
74
73
  fork: true,
75
74
  gitHostname: 'github.com',
76
75
  githubApiBaseUrlV3: 'https://api.github.com',
@@ -92,7 +91,6 @@ describe('runSequentially', () => {
92
91
  sourceBranch: 'my-source-branch-from-options',
93
92
  sourcePRLabels: [],
94
93
  targetBranches: [],
95
- upstream: 'elastic/kibana',
96
94
  targetBranchChoices: [
97
95
  { name: '6.x' },
98
96
  { name: '6.0' },
@@ -101,7 +99,7 @@ describe('runSequentially', () => {
101
99
  { name: '5.4' },
102
100
  ],
103
101
  targetPRLabels: [],
104
- username: 'sqren',
102
+ author: 'sqren',
105
103
  verbose: false,
106
104
  };
107
105
  rpcExecMock = jest
@@ -114,7 +112,7 @@ describe('runSequentially', () => {
114
112
  number: 1337,
115
113
  html_url: 'myHtmlUrl',
116
114
  });
117
- createPullRequestCalls = (0, nockHelpers_1.getNockCallsForScope)(scope);
115
+ createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
118
116
  const commits = [
119
117
  {
120
118
  sha: 'abcd',
@@ -141,82 +139,41 @@ describe('runSequentially', () => {
141
139
  ]);
142
140
  });
143
141
  it('creates pull request', () => {
144
- expect(createPullRequestCalls).toEqual([
145
- {
146
- base: '7.x',
147
- body: 'Backports the following commits to 7.x:\n - #55\n\nmyPrDescription',
148
- head: 'sqren:backport/7.x/pr-55',
149
- title: 'myPrTitle 7.x My commit message',
150
- },
151
- ]);
152
- });
153
- it('exec should be called with correct args', () => {
154
- expect(rpcExecMock).toHaveBeenCalledTimes(10);
155
- expect(rpcExecMock.mock.calls).toMatchInlineSnapshot(`
142
+ expect(createPullRequestCalls).toMatchInlineSnapshot(`
156
143
  Array [
157
- Array [
158
- "git remote rm origin",
159
- Object {
160
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
161
- },
162
- ],
163
- Array [
164
- "git remote rm sqren",
165
- Object {
166
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
167
- },
168
- ],
169
- Array [
170
- "git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git",
171
- Object {
172
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
173
- },
174
- ],
175
- Array [
176
- "git remote rm elastic",
177
- Object {
178
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
179
- },
180
- ],
181
- Array [
182
- "git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git",
183
- Object {
184
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
185
- },
186
- ],
187
- Array [
188
- "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",
189
- Object {
190
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
191
- },
192
- ],
193
- Array [
194
- "git fetch elastic master:master --force",
195
- Object {
196
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
197
- },
198
- ],
199
- Array [
200
- "git cherry-pick -x abcd",
201
- Object {
202
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
203
- },
204
- ],
205
- Array [
206
- "git push sqren backport/7.x/pr-55:backport/7.x/pr-55 --force",
207
- Object {
208
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
209
- },
210
- ],
211
- Array [
212
- "git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55",
213
- Object {
214
- "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
215
- },
216
- ],
144
+ Object {
145
+ "base": "7.x",
146
+ "body": "This is an automatic backport of pull request #55 to 7.x.
147
+
148
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport) for additional information
149
+
150
+ myPrDescription",
151
+ "head": "sqren_authenticated:backport/7.x/pr-55",
152
+ "title": "myPrTitle 7.x My commit message",
153
+ },
217
154
  ]
218
155
  `);
219
156
  });
157
+ it('should run all commands in the correct directory', () => {
158
+ expect(rpcExecMock.mock.calls.every(
159
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
160
+ ([cmd, opts]) => opts.cwd === '/myHomeDir/.backport/repositories/elastic/kibana')).toBe(true);
161
+ });
162
+ it('exec should be called with correct args', () => {
163
+ expect(rpcExecMock).toHaveBeenCalledTimes(10);
164
+ expect(rpcExecMock.mock.calls.map(([cmd]) => cmd)).toEqual([
165
+ 'git remote rm origin',
166
+ 'git remote rm sqren_authenticated',
167
+ 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
168
+ 'git remote rm elastic',
169
+ 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
170
+ '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',
171
+ 'git fetch elastic master:master --force',
172
+ 'git cherry-pick -x abcd',
173
+ 'git push sqren_authenticated backport/7.x/pr-55:backport/7.x/pr-55 --force',
174
+ 'git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55',
175
+ ]);
176
+ });
220
177
  it('git clone should be called with correct args', () => {
221
178
  expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
222
179
  expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
@@ -7,7 +7,10 @@ export declare function cloneRepo(options: ValidConfigOptions, callback: (progre
7
7
  export declare function getLocalConfigFileCommitDate(): Promise<number | undefined>;
8
8
  export declare function isLocalConfigFileUntracked(): Promise<boolean | undefined>;
9
9
  export declare function isLocalConfigFileModified(): Promise<boolean | undefined>;
10
- export declare function getUpstreamFromGitRemote(): Promise<string | undefined>;
10
+ export declare function getRepoOwnerAndNameFromGitRemote(): Promise<{
11
+ repoOwner: string;
12
+ repoName: string;
13
+ } | undefined>;
11
14
  export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
12
15
  export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
13
16
  export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
@@ -27,7 +30,7 @@ export declare function getConflictingFiles(options: ValidConfigOptions): Promis
27
30
  relative: string;
28
31
  }[]>;
29
32
  export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
30
- export declare function setCommitAuthor(options: ValidConfigOptions, username: string): Promise<{
33
+ export declare function setCommitAuthor(options: ValidConfigOptions, author: string): Promise<{
31
34
  stdout: string;
32
35
  stderr: string;
33
36
  }>;