backport 7.2.0 → 7.3.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.
Files changed (54) hide show
  1. package/README.md +10 -5
  2. package/dist/entrypoint.cli.d.ts +0 -1
  3. package/dist/entrypoint.cli.js +0 -1
  4. package/dist/entrypoint.cli.private.test.js +1 -0
  5. package/dist/options/ConfigOptions.d.ts +2 -0
  6. package/dist/options/config/config.d.ts +2 -0
  7. package/dist/options/config/readConfigFile.d.ts +2 -0
  8. package/dist/options/options.d.ts +2 -0
  9. package/dist/runSequentially.js +2 -2
  10. package/dist/services/git.d.ts +11 -2
  11. package/dist/services/git.integration.test.js +12 -46
  12. package/dist/services/git.js +31 -15
  13. package/dist/services/git.test.js +12 -1
  14. package/dist/services/github/v3/createPullRequest.test.js +52 -0
  15. package/dist/services/github/v3/createStatusComment.test.js +12 -2
  16. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
  17. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +1 -0
  18. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +1 -0
  19. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -0
  20. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -0
  21. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
  22. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
  23. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +20 -0
  24. package/dist/services/prompt.test.js +5 -0
  25. package/dist/services/sourceCommit/getMockSourceCommit.js +1 -0
  26. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -0
  27. package/dist/services/sourceCommit/parseSourceCommit.js +6 -0
  28. package/dist/services/sourceCommit/parseSourceCommit.test.js +1 -0
  29. package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
  30. package/dist/test/e2e/cli/cli.private.test.js +215 -0
  31. package/dist/test/e2e/cli/different-merge-strategies.private.test.d.ts +1 -0
  32. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +108 -0
  33. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.d.ts +1 -0
  34. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +49 -0
  35. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -0
  36. package/dist/test/e2e/cli/runBackportViaCli.js +53 -0
  37. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.d.ts +1 -0
  38. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +73 -0
  39. package/dist/test/e2e/module.e2e.mutation.test.d.ts +1 -0
  40. package/dist/test/e2e/module.e2e.mutation.test.js +369 -0
  41. package/dist/test/e2e/module.e2e.private.test.js +6 -0
  42. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -0
  43. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  44. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +24 -14
  45. package/dist/ui/getCommitsWithoutBackports.test.js +20 -0
  46. package/dist/ui/getTargetBranches.test.js +2 -0
  47. package/dist/ui/setupRepo.d.ts +3 -0
  48. package/dist/ui/setupRepo.js +88 -0
  49. package/dist/ui/setupRepo.test.d.ts +1 -0
  50. package/dist/ui/setupRepo.test.js +288 -0
  51. package/dist/utils/packageVersion.d.ts +1 -1
  52. package/dist/utils/packageVersion.js +1 -1
  53. package/package.json +6 -6
  54. package/yarn.lock +3 -3
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const child_process_promisified_1 = require("../../../services/child-process-promisified");
4
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
5
+ const sandbox_1 = require("../../sandbox");
6
+ const runBackportViaCli_1 = require("./runBackportViaCli");
7
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
8
+ describe('test-that-repo-can-be-cloned', () => {
9
+ describe('when local repo does not exist', () => {
10
+ let sandboxPath;
11
+ beforeAll(async () => {
12
+ sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
13
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
14
+ });
15
+ function run() {
16
+ return (0, runBackportViaCli_1.runBackportViaCli)([
17
+ '--repo=backport-org/test-that-repo-can-be-cloned',
18
+ '--branch=foo',
19
+ '--pr=1',
20
+ `--dir=${sandboxPath}`,
21
+ '--dry-run',
22
+ `--accessToken=${accessToken}`,
23
+ ], { showOra: true, waitForString: 'Backporting to foo:' });
24
+ }
25
+ it('clones the repo remote repo', async () => {
26
+ const output = await run();
27
+ expect(output).toContain('Cloning repository from github.com');
28
+ expect(output).toMatchInlineSnapshot(`
29
+ "- Initializing...
30
+ ? Select pull request Beginning of a beautiful repo (#1)
31
+ ✔ 100% Cloning repository from github.com (one-time operation)
32
+ Backporting to foo:"
33
+ `);
34
+ });
35
+ it('does not clone again on subsequent runs', async () => {
36
+ const output = await run();
37
+ expect(output).not.toContain('Cloning repository from github.com');
38
+ expect(output).toMatchInlineSnapshot(`
39
+ "- Initializing...
40
+ ? Select pull request Beginning of a beautiful repo (#1)
41
+ Backporting to foo:"
42
+ `);
43
+ });
44
+ });
45
+ describe('when local repo exists', () => {
46
+ let sourceRepo;
47
+ let backportRepo;
48
+ beforeEach(async () => {
49
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
50
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
51
+ sourceRepo = `${sandboxPath}/source`;
52
+ backportRepo = `${sandboxPath}/backport`;
53
+ await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/test-that-repo-can-be-cloned.git ${sourceRepo}`, { cwd: sandboxPath });
54
+ });
55
+ function run() {
56
+ return (0, runBackportViaCli_1.runBackportViaCli)([
57
+ '--branch=foo',
58
+ '--pr=1',
59
+ `--dir=${backportRepo}`,
60
+ '--dry-run',
61
+ `--accessToken=${accessToken}`,
62
+ ], {
63
+ cwd: sourceRepo,
64
+ showOra: true,
65
+ waitForString: 'Backporting to foo:',
66
+ });
67
+ }
68
+ it('clones using the local repo', async () => {
69
+ const output = await run();
70
+ expect(output).toEqual(expect.stringMatching(/100% Cloning repository from .*\/src\/test\/_tmp_sandbox_\/test-that-repo-can-be-cloned.private.test\/source \(one-time operation\)/gm));
71
+ });
72
+ });
73
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,369 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rest_1 = require("@octokit/rest");
4
+ const entrypoint_module_1 = require("../../entrypoint.module");
5
+ const commitFormatters_1 = require("../../services/github/commitFormatters");
6
+ const getDevAccessToken_1 = require("../private/getDevAccessToken");
7
+ const sandbox_1 = require("../sandbox");
8
+ jest.unmock('find-up');
9
+ jest.unmock('del');
10
+ jest.unmock('make-dir');
11
+ jest.setTimeout(15000);
12
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
13
+ const octokit = new rest_1.Octokit({ auth: accessToken });
14
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
15
+ // repo
16
+ const REPO_OWNER = 'backport-org';
17
+ const REPO_NAME = 'integration-test';
18
+ const AUTHOR = 'sqren';
19
+ // commit 1
20
+ const COMMIT_SHA_1 = '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad';
21
+ const BRANCH_WITH_ONE_COMMIT = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}`;
22
+ // commit 2
23
+ const COMMIT_SHA_2 = '59d6ff1ca90a4ce210c0a4f0e159214875c19d60';
24
+ const BRANCH_WITH_TWO_COMMITS = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}_commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_2)}`;
25
+ describe('backport e2e', () => {
26
+ describe('when a single commit is backported', () => {
27
+ let res;
28
+ let pullRequestResponse;
29
+ beforeAll(async () => {
30
+ await resetState(accessToken);
31
+ res = await (0, entrypoint_module_1.backportRun)({
32
+ dir: sandboxPath,
33
+ accessToken,
34
+ repoOwner: 'backport-org',
35
+ repoName: 'integration-test',
36
+ sha: COMMIT_SHA_1,
37
+ targetBranches: ['7.x'],
38
+ });
39
+ // @ts-expect-error
40
+ const pullRequestNumber = res.results[0].pullRequestNumber;
41
+ pullRequestResponse = await octokit.pulls.get({
42
+ owner: REPO_OWNER,
43
+ repo: REPO_NAME,
44
+ pull_number: pullRequestNumber,
45
+ });
46
+ });
47
+ it('returns the backport result', () => {
48
+ expect(res).toEqual({
49
+ commits: [
50
+ {
51
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
52
+ expectedTargetPullRequests: [],
53
+ sourceBranch: 'master',
54
+ sourceCommit: {
55
+ committedDate: '2020-08-15T10:37:41Z',
56
+ message: 'Add ❤️ emoji',
57
+ sha: COMMIT_SHA_1,
58
+ },
59
+ sourcePullRequest: undefined,
60
+ },
61
+ ],
62
+ results: [
63
+ {
64
+ didUpdate: false,
65
+ pullRequestNumber: expect.any(Number),
66
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
67
+ status: 'success',
68
+ targetBranch: '7.x',
69
+ },
70
+ ],
71
+ status: 'success',
72
+ });
73
+ });
74
+ it('pull request: status code', async () => {
75
+ expect(pullRequestResponse.status).toEqual(200);
76
+ });
77
+ it('pull request: title', async () => {
78
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
79
+ });
80
+ it('pull request: body', async () => {
81
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
82
+ "# Backport
83
+
84
+ This will backport the following commits from \`master\` to \`7.x\`:
85
+ - Add ❤️ emoji (5bf29b7d)
86
+
87
+ <!--- Backport version: 1.2.3-mocked -->
88
+
89
+ ### Questions ?
90
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
91
+ `);
92
+ });
93
+ it('pull request: head branch is in fork repo', async () => {
94
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_ONE_COMMIT}`);
95
+ });
96
+ it('pull request: base branch', async () => {
97
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
98
+ });
99
+ it('does not create any new branches in origin (backport-org/integration-test)', async () => {
100
+ const branches = await getBranchesOnGithub({
101
+ accessToken,
102
+ repoOwner: REPO_OWNER,
103
+ repoName: REPO_NAME,
104
+ });
105
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
106
+ });
107
+ it('creates a branch in the fork (sqren/integration-test)', async () => {
108
+ const branches = await getBranchesOnGithub({
109
+ accessToken,
110
+ repoOwner: AUTHOR,
111
+ repoName: REPO_NAME,
112
+ });
113
+ expect(branches.map((b) => b.name)).toEqual([
114
+ '7.x',
115
+ BRANCH_WITH_ONE_COMMIT,
116
+ 'master',
117
+ ]);
118
+ });
119
+ });
120
+ describe('when two commits are backported', () => {
121
+ let res;
122
+ let pullRequestResponse;
123
+ beforeAll(async () => {
124
+ await resetState(accessToken);
125
+ res = await (0, entrypoint_module_1.backportRun)({
126
+ dir: sandboxPath,
127
+ accessToken,
128
+ repoOwner: 'backport-org',
129
+ repoName: 'integration-test',
130
+ sha: [COMMIT_SHA_1, COMMIT_SHA_2],
131
+ targetBranches: ['7.x'],
132
+ });
133
+ // @ts-expect-error
134
+ const pullRequestNumber = res.results[0].pullRequestNumber;
135
+ pullRequestResponse = await octokit.pulls.get({
136
+ owner: REPO_OWNER,
137
+ repo: REPO_NAME,
138
+ pull_number: pullRequestNumber,
139
+ });
140
+ });
141
+ it('returns the backport result containing both commits', () => {
142
+ expect(res).toEqual({
143
+ commits: [
144
+ {
145
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
146
+ expectedTargetPullRequests: [],
147
+ sourceBranch: 'master',
148
+ sourceCommit: {
149
+ committedDate: '2020-08-15T10:37:41Z',
150
+ message: 'Add ❤️ emoji',
151
+ sha: COMMIT_SHA_1,
152
+ },
153
+ sourcePullRequest: undefined,
154
+ },
155
+ {
156
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
157
+ expectedTargetPullRequests: [],
158
+ sourceBranch: 'master',
159
+ sourceCommit: {
160
+ committedDate: '2020-08-15T10:44:04Z',
161
+ message: 'Add family emoji (#2)',
162
+ sha: COMMIT_SHA_2,
163
+ },
164
+ sourcePullRequest: undefined,
165
+ },
166
+ ],
167
+ results: [
168
+ {
169
+ didUpdate: false,
170
+ pullRequestNumber: expect.any(Number),
171
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
172
+ status: 'success',
173
+ targetBranch: '7.x',
174
+ },
175
+ ],
176
+ status: 'success',
177
+ });
178
+ });
179
+ it('pull request: status code', async () => {
180
+ expect(pullRequestResponse.status).toEqual(200);
181
+ });
182
+ it('pull request: title', async () => {
183
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji | Add family emoji (#2)');
184
+ });
185
+ it('pull request: body', async () => {
186
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
187
+ "# Backport
188
+
189
+ This will backport the following commits from \`master\` to \`7.x\`:
190
+ - Add ❤️ emoji (5bf29b7d)
191
+ - Add family emoji (#2) (59d6ff1c)
192
+
193
+ <!--- Backport version: 1.2.3-mocked -->
194
+
195
+ ### Questions ?
196
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
197
+ `);
198
+ });
199
+ it('pull request: head branch contains both commits in name', async () => {
200
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_TWO_COMMITS}`);
201
+ });
202
+ it('pull request: base branch', async () => {
203
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
204
+ });
205
+ });
206
+ describe('when disabling fork mode', () => {
207
+ let res;
208
+ let pullRequestResponse;
209
+ beforeAll(async () => {
210
+ await resetState(accessToken);
211
+ res = await (0, entrypoint_module_1.backportRun)({
212
+ fork: false,
213
+ dir: sandboxPath,
214
+ accessToken,
215
+ repoOwner: 'backport-org',
216
+ repoName: 'integration-test',
217
+ sha: COMMIT_SHA_1,
218
+ targetBranches: ['7.x'],
219
+ });
220
+ // @ts-expect-error
221
+ const pullRequestNumber = res.results[0].pullRequestNumber;
222
+ pullRequestResponse = await octokit.pulls.get({
223
+ owner: REPO_OWNER,
224
+ repo: REPO_NAME,
225
+ pull_number: pullRequestNumber,
226
+ });
227
+ });
228
+ it('pull request: title', async () => {
229
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
230
+ });
231
+ it('pull request: body', async () => {
232
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
233
+ "# Backport
234
+
235
+ This will backport the following commits from \`master\` to \`7.x\`:
236
+ - Add ❤️ emoji (5bf29b7d)
237
+
238
+ <!--- Backport version: 1.2.3-mocked -->
239
+
240
+ ### Questions ?
241
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
242
+ `);
243
+ });
244
+ it('pull request: head branch is in origin (non-fork) repo', async () => {
245
+ expect(pullRequestResponse.data.head.label).toEqual(`backport-org:${BRANCH_WITH_ONE_COMMIT}`);
246
+ });
247
+ it('pull request: base branch', async () => {
248
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
249
+ });
250
+ it('returns pull request', () => {
251
+ expect(res).toEqual({
252
+ commits: [
253
+ {
254
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
255
+ expectedTargetPullRequests: [],
256
+ sourceBranch: 'master',
257
+ sourceCommit: {
258
+ committedDate: '2020-08-15T10:37:41Z',
259
+ message: 'Add ❤️ emoji',
260
+ sha: COMMIT_SHA_1,
261
+ },
262
+ sourcePullRequest: undefined,
263
+ },
264
+ ],
265
+ results: [
266
+ {
267
+ didUpdate: false,
268
+ pullRequestNumber: expect.any(Number),
269
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
270
+ status: 'success',
271
+ targetBranch: '7.x',
272
+ },
273
+ ],
274
+ status: 'success',
275
+ });
276
+ });
277
+ it('creates a new branch in origin (backport-org/integration-test)', async () => {
278
+ const branches = await getBranchesOnGithub({
279
+ accessToken,
280
+ repoOwner: REPO_OWNER,
281
+ repoName: REPO_NAME,
282
+ });
283
+ expect(branches.map((b) => b.name)).toEqual([
284
+ '7.x',
285
+ BRANCH_WITH_ONE_COMMIT,
286
+ 'master',
287
+ ]);
288
+ });
289
+ it('does not create branches in the fork (sqren/integration-test)', async () => {
290
+ const branches = await getBranchesOnGithub({
291
+ accessToken,
292
+ repoOwner: AUTHOR,
293
+ repoName: REPO_NAME,
294
+ });
295
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
296
+ });
297
+ });
298
+ });
299
+ async function getBranchesOnGithub({ accessToken, repoOwner, repoName, }) {
300
+ // console.log(`fetch branches for ${repoOwner}`);
301
+ const octokit = new rest_1.Octokit({
302
+ auth: accessToken,
303
+ });
304
+ const res = await octokit.repos.listBranches({
305
+ owner: repoOwner,
306
+ repo: repoName,
307
+ });
308
+ return res.data;
309
+ }
310
+ async function deleteBranchOnGithub({ accessToken, repoOwner, repoName, branchName, }) {
311
+ try {
312
+ const octokit = new rest_1.Octokit({
313
+ auth: accessToken,
314
+ });
315
+ // console.log({ accessToken });
316
+ const opts = {
317
+ owner: repoOwner,
318
+ repo: repoName,
319
+ ref: `heads/${branchName}`,
320
+ };
321
+ const res = await octokit.git.deleteRef(opts);
322
+ // console.log(`Deleted ${repoOwner}:heads/${branchName}`);
323
+ return res.data;
324
+ }
325
+ catch (e) {
326
+ // console.log(
327
+ // `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
328
+ // );
329
+ if (e.message === 'Reference does not exist') {
330
+ return;
331
+ }
332
+ throw e;
333
+ }
334
+ }
335
+ async function resetState(accessToken) {
336
+ const ownerBranches = await getBranchesOnGithub({
337
+ accessToken,
338
+ repoOwner: REPO_OWNER,
339
+ repoName: REPO_NAME,
340
+ });
341
+ // delete all branches except master and 7.x
342
+ await Promise.all(ownerBranches
343
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
344
+ .map((b) => {
345
+ return deleteBranchOnGithub({
346
+ accessToken,
347
+ repoOwner: REPO_OWNER,
348
+ repoName: REPO_NAME,
349
+ branchName: b.name,
350
+ });
351
+ }));
352
+ const forkBranches = await getBranchesOnGithub({
353
+ accessToken,
354
+ repoOwner: AUTHOR,
355
+ repoName: REPO_NAME,
356
+ });
357
+ // delete all branches except master and 7.x
358
+ await Promise.all(forkBranches
359
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
360
+ .map((b) => {
361
+ return deleteBranchOnGithub({
362
+ accessToken,
363
+ repoOwner: AUTHOR,
364
+ repoName: REPO_NAME,
365
+ branchName: b.name,
366
+ });
367
+ }));
368
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
369
+ }
@@ -6,6 +6,8 @@ const commitFormatters_1 = require("../../services/github/commitFormatters");
6
6
  const getDevAccessToken_1 = require("../private/getDevAccessToken");
7
7
  const sandbox_1 = require("../sandbox");
8
8
  jest.unmock('find-up');
9
+ jest.unmock('del');
10
+ jest.unmock('make-dir');
9
11
  jest.setTimeout(15000);
10
12
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
11
13
  const octokit = new rest_1.Octokit({ auth: accessToken });
@@ -46,6 +48,7 @@ describe('backport e2e', () => {
46
48
  expect(res).toEqual({
47
49
  commits: [
48
50
  {
51
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
49
52
  expectedTargetPullRequests: [],
50
53
  sourceBranch: 'master',
51
54
  sourceCommit: {
@@ -139,6 +142,7 @@ describe('backport e2e', () => {
139
142
  expect(res).toEqual({
140
143
  commits: [
141
144
  {
145
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
142
146
  expectedTargetPullRequests: [],
143
147
  sourceBranch: 'master',
144
148
  sourceCommit: {
@@ -149,6 +153,7 @@ describe('backport e2e', () => {
149
153
  sourcePullRequest: undefined,
150
154
  },
151
155
  {
156
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
152
157
  expectedTargetPullRequests: [],
153
158
  sourceBranch: 'master',
154
159
  sourceCommit: {
@@ -246,6 +251,7 @@ describe('backport e2e', () => {
246
251
  expect(res).toEqual({
247
252
  commits: [
248
253
  {
254
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
249
255
  expectedTargetPullRequests: [],
250
256
  sourceBranch: 'master',
251
257
  sourceCommit: {
@@ -15,6 +15,7 @@ describe('Handle unbackported pull requests', () => {
15
15
  pullNumber: 8,
16
16
  });
17
17
  const expectedCommit = {
18
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
18
19
  sourceCommit: {
19
20
  committedDate: '2021-12-16T00:03:34Z',
20
21
  message: 'Change Barca to Braithwaite (#8)',
@@ -31,7 +31,7 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
31
31
  await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
32
32
  }
33
33
  if (options.dryRun) {
34
- (0, ora_1.ora)(options.ci).succeed('Dry run');
34
+ (0, ora_1.ora)(options.ci).succeed('Dry run complete');
35
35
  return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
36
36
  }
37
37
  await (0, git_1.pushBackportBranch)({ options, backportBranch });
@@ -116,10 +116,10 @@ async function waitForCherrypick(options, commit, targetBranch) {
116
116
  cherrypickSpinner.fail();
117
117
  throw e;
118
118
  }
119
+ const repoPath = (0, env_1.getRepoPath)(options);
119
120
  // resolve conflicts automatically
120
121
  if (options.autoFixConflicts) {
121
122
  const autoResolveSpinner = (0, ora_1.ora)(options.ci, 'Attempting to resolve conflicts automatically').start();
122
- const repoPath = (0, env_1.getRepoPath)(options);
123
123
  const didAutoFix = await options.autoFixConflicts({
124
124
  files: conflictingFiles.map((f) => f.absolute),
125
125
  directory: repoPath,
@@ -146,6 +146,7 @@ async function waitForCherrypick(options, commit, targetBranch) {
146
146
  });
147
147
  }
148
148
  (0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
149
+ (0, logger_1.consoleLog)(`Please fix the conflicts in ${repoPath}`);
149
150
  if (commitsWithoutBackports.length > 0) {
150
151
  (0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to "${targetBranch}":`));
151
152
  (0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
@@ -154,7 +155,6 @@ async function waitForCherrypick(options, commit, targetBranch) {
154
155
  * Commit could not be cleanly cherrypicked: Initiating conflict resolution
155
156
  */
156
157
  if (options.editor) {
157
- const repoPath = (0, env_1.getRepoPath)(options);
158
158
  await (0, child_process_promisified_1.exec)(`${options.editor} ${repoPath}`, { cwd: options.cwd });
159
159
  }
160
160
  // list files with conflict markers + unstaged files and require user to resolve them
@@ -74,6 +74,10 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
74
74
  };
75
75
  const commits = [
76
76
  {
77
+ author: {
78
+ email: 'soren.louv@elastic.co',
79
+ name: 'Søren Louv-Jansen',
80
+ },
77
81
  sourceBranch: '7.x',
78
82
  sourceCommit: {
79
83
  committedDate: 'fff',
@@ -91,6 +95,10 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
91
95
  expectedTargetPullRequests: [],
92
96
  },
93
97
  {
98
+ author: {
99
+ email: 'soren.louv@elastic.co',
100
+ name: 'Søren Louv-Jansen',
101
+ },
94
102
  sourceBranch: '7.x',
95
103
  sourceCommit: {
96
104
  committedDate: 'ggg',
@@ -188,6 +196,10 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
188
196
  };
189
197
  const commits = [
190
198
  {
199
+ author: {
200
+ email: 'soren.louv@elastic.co',
201
+ name: 'Søren Louv-Jansen',
202
+ },
191
203
  sourceCommit: {
192
204
  committedDate: 'hhh',
193
205
  sha: 'mySha',
@@ -271,6 +283,10 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
271
283
  options,
272
284
  commits: [
273
285
  {
286
+ author: {
287
+ email: 'soren.louv@elastic.co',
288
+ name: 'Søren Louv-Jansen',
289
+ },
274
290
  sourceCommit: {
275
291
  committedDate: '2021-08-18T16:11:38Z',
276
292
  sha: 'mySha',
@@ -370,24 +386,18 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
370
386
  `);
371
387
  });
372
388
  it('logs correctly', async () => {
373
- expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
374
- "
375
- Backporting to 6.x:"
376
- `);
377
- expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
389
+ expect(consoleLogSpy.mock.calls.map((call) => call[0]).join(''))
390
+ .toMatchInlineSnapshot(`
378
391
  "
392
+ Backporting to 6.x:
379
393
  The commit could not be backported due to conflicts
380
- "
381
- `);
382
- expect(consoleLogSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
383
- "
394
+ Please fix the conflicts in /myHomeDir/.backport/repositories/elastic/kibana
384
395
  ----------------------------------------
385
- "
386
- `);
387
- expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
388
- "
396
+
389
397
  ----------------------------------------
390
- "
398
+
399
+ ----------------------------------------
400
+ View pull request: myHtmlUrl"
391
401
  `);
392
402
  });
393
403
  });
@@ -37,6 +37,10 @@ describe('getCommitsWithoutBackports', () => {
37
37
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
38
38
  .mockResolvedValueOnce([
39
39
  {
40
+ author: {
41
+ email: 'soren.louv@elastic.co',
42
+ name: 'Søren Louv-Jansen',
43
+ },
40
44
  sourceCommit: {
41
45
  committedDate: '10',
42
46
  message: 'First commit (#1)',
@@ -59,6 +63,7 @@ describe('getCommitsWithoutBackports', () => {
59
63
  return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
60
64
  options: {},
61
65
  commit: {
66
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
62
67
  sourceCommit: {
63
68
  committedDate: '100',
64
69
  message: 'Second commit (#2)',
@@ -130,6 +135,10 @@ describe('getCommitsWithoutBackports', () => {
130
135
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
131
136
  .mockResolvedValueOnce([
132
137
  {
138
+ author: {
139
+ email: 'soren.louv@elastic.co',
140
+ name: 'Søren Louv-Jansen',
141
+ },
133
142
  sourceCommit: {
134
143
  committedDate: offendingCommitDate,
135
144
  message: 'First commit (#1)',
@@ -159,6 +168,7 @@ describe('getCommitsWithoutBackports', () => {
159
168
  return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
160
169
  options: {},
161
170
  commit: {
171
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
162
172
  sourceCommit: {
163
173
  committedDate: currentCommitDate,
164
174
  message: 'Second commit (#2)',
@@ -201,6 +211,10 @@ describe('getCommitsWithoutBackports', () => {
201
211
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
202
212
  .mockResolvedValueOnce([
203
213
  {
214
+ author: {
215
+ email: 'soren.louv@elastic.co',
216
+ name: 'Søren Louv-Jansen',
217
+ },
204
218
  sourceCommit: {
205
219
  committedDate: '10',
206
220
  message: 'First commit (#1)',
@@ -231,6 +245,7 @@ describe('getCommitsWithoutBackports', () => {
231
245
  options: {},
232
246
  // commit that is being backported
233
247
  commit: {
248
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
234
249
  sourceCommit: {
235
250
  committedDate: '100',
236
251
  message: 'Second commit (#2)',
@@ -272,6 +287,10 @@ describe('getCommitsWithoutBackports', () => {
272
287
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
273
288
  .mockResolvedValueOnce([
274
289
  {
290
+ author: {
291
+ email: 'soren.louv@elastic.co',
292
+ name: 'Søren Louv-Jansen',
293
+ },
275
294
  sourceCommit: {
276
295
  committedDate: '10',
277
296
  sha: 'xyz',
@@ -286,6 +305,7 @@ describe('getCommitsWithoutBackports', () => {
286
305
  const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
287
306
  options: {},
288
307
  commit: {
308
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
289
309
  sourceCommit: {
290
310
  committedDate: '100',
291
311
  message: 'Second commit (#2)',