backport 7.3.5 → 8.0.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 (87) hide show
  1. package/README.md +13 -18
  2. package/dist/backportRun.d.ts +14 -3
  3. package/dist/backportRun.js +59 -37
  4. package/dist/entrypoint.cli.js +1 -1
  5. package/dist/entrypoint.module.d.ts +8 -3
  6. package/dist/entrypoint.module.js +6 -10
  7. package/dist/entrypoint.module.private.test.js +129 -330
  8. package/dist/options/ConfigOptions.d.ts +2 -2
  9. package/dist/options/cliArgs.d.ts +10 -6
  10. package/dist/options/cliArgs.js +32 -21
  11. package/dist/options/cliArgs.test.js +3 -3
  12. package/dist/options/config/config.d.ts +2 -2
  13. package/dist/options/config/config.js +2 -2
  14. package/dist/options/config/globalConfig.d.ts +2 -2
  15. package/dist/options/config/globalConfig.js +13 -10
  16. package/dist/options/config/projectConfig.d.ts +2 -2
  17. package/dist/options/config/projectConfig.js +3 -3
  18. package/dist/options/config/projectConfig.test.js +19 -7
  19. package/dist/options/config/readConfigFile.d.ts +4 -4
  20. package/dist/options/options.d.ts +4 -5
  21. package/dist/options/options.js +2 -3
  22. package/dist/options/options.test.js +7 -4
  23. package/dist/runSequentially.d.ts +5 -1
  24. package/dist/runSequentially.js +23 -8
  25. package/dist/scripts/postinstall.js +1 -0
  26. package/dist/scripts/postinstall.test.js +5 -1
  27. package/dist/services/HandledError.d.ts +6 -2
  28. package/dist/services/HandledError.js +8 -8
  29. package/dist/services/child-process-promisified.d.ts +19 -3
  30. package/dist/services/child-process-promisified.js +46 -17
  31. package/dist/services/git.d.ts +6 -7
  32. package/dist/services/git.integration.test.js +381 -65
  33. package/dist/services/git.js +188 -126
  34. package/dist/services/git.private.test.d.ts +1 -0
  35. package/dist/services/git.private.test.js +618 -0
  36. package/dist/services/git.test.js +167 -158
  37. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  38. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  39. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  40. package/dist/services/github/v3/createPullRequest.js +3 -1
  41. package/dist/services/github/v3/createStatusComment.js +16 -16
  42. package/dist/services/github/v3/createStatusComment.test.js +17 -5
  43. package/dist/services/github/v4/apiRequestV4.js +6 -9
  44. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  45. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  46. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
  49. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
  51. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
  52. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
  53. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
  54. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
  55. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
  56. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
  57. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
  58. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
  59. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
  60. package/dist/services/logger.d.ts +1 -4
  61. package/dist/services/logger.js +14 -19
  62. package/dist/services/test.d.ts +1 -0
  63. package/dist/services/test.js +23 -0
  64. package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
  65. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +401 -0
  66. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
  67. package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
  68. package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
  69. package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
  70. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
  71. package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -10
  72. package/dist/test/sandbox.js +5 -1
  73. package/dist/test/setupFiles/automatic-mocks.js +16 -12
  74. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +8 -4
  75. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  76. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  77. package/dist/ui/getGitConfigAuthor.js +1 -1
  78. package/dist/ui/getTargetBranches.test.js +5 -1
  79. package/dist/ui/ora.d.ts +1 -8
  80. package/dist/ui/setupRepo.js +1 -1
  81. package/dist/ui/setupRepo.test.js +98 -61
  82. package/dist/utils/isErrnoError.d.ts +2 -0
  83. package/dist/utils/isErrnoError.js +7 -0
  84. package/dist/utils/packageVersion.d.ts +1 -1
  85. package/dist/utils/packageVersion.js +1 -1
  86. package/package.json +13 -13
  87. package/yarn.lock +414 -695
@@ -4,7 +4,7 @@ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
4
4
  const runBackportViaCli_1 = require("./runBackportViaCli");
5
5
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
6
  describe('repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
7
- it('should list commits', async () => {
7
+ it('lists commits', async () => {
8
8
  const output = await (0, runBackportViaCli_1.runBackportViaCli)([
9
9
  '--branch=foo',
10
10
  '--repo=backport-org/repo-with-backportrc-removed',
@@ -21,29 +21,30 @@ describe('repo-with-backportrc-removed (missing .backportrc.json config file)',
21
21
  7. Create .backportrc.json"
22
22
  `);
23
23
  });
24
- it('should attempt to backport by PR', async () => {
24
+ it('backports via pr', async () => {
25
25
  const output = await (0, runBackportViaCli_1.runBackportViaCli)([
26
- '--branch=foo',
26
+ '--branch=production',
27
27
  '--repo=backport-org/repo-with-backportrc-removed',
28
28
  '--pr=1',
29
29
  `--accessToken=${accessToken}`,
30
- ], { waitForString: "is invalid or doesn't exist" });
31
- expect(output).toMatchInlineSnapshot(`
32
- "
33
- Backporting to foo:
34
- The branch \\"foo\\" is invalid or doesn't exist"
35
- `);
30
+ '--dry-run',
31
+ ], {
32
+ waitForString: `Dry run complete`,
33
+ showOra: true,
34
+ });
35
+ expect(output).toContain('Cherry-picking: Merge pull request #1 from backport-org/add-readme');
36
36
  });
37
- it('should attempt to backport by commit sha', async () => {
37
+ it('backport by commit sha', async () => {
38
38
  const output = await (0, runBackportViaCli_1.runBackportViaCli)([
39
- '--branch=foo',
39
+ '--branch=production',
40
40
  '--repo=backport-org/repo-with-backportrc-removed',
41
41
  '--sha=be59df6912a550c8cb49ba3e18be3e512f3d608c',
42
42
  `--accessToken=${accessToken}`,
43
- ], { waitForString: `Backporting to foo:` });
44
- expect(output).toMatchInlineSnapshot(`
45
- "
46
- Backporting to foo:"
47
- `);
43
+ '--dry-run',
44
+ ], {
45
+ waitForString: `Dry run complete`,
46
+ showOra: true,
47
+ });
48
+ expect(output).toContain('Cherry-picking: Create README.me');
48
49
  });
49
50
  });
@@ -1,4 +1,5 @@
1
- export declare function runBackportViaCli(cliArgs: string[], { showOra, waitForString, cwd, }?: {
1
+ export declare function runBackportViaCli(cliArgs: string[], { timeoutSeconds, showOra, waitForString, cwd, }?: {
2
+ timeoutSeconds?: number;
2
3
  showOra?: boolean;
3
4
  waitForString?: string;
4
5
  cwd?: string;
@@ -10,7 +10,7 @@ const lodash_1 = require("lodash");
10
10
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
11
11
  const TIMEOUT_IN_SECONDS = 15;
12
12
  jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
13
- function runBackportViaCli(cliArgs, { showOra, waitForString, cwd, } = {}) {
13
+ function runBackportViaCli(cliArgs, { timeoutSeconds = 2, showOra, waitForString, cwd, } = {}) {
14
14
  const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
15
15
  const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
16
16
  const proc = (0, child_process_1.spawn)(tsNodeBinary, [
@@ -22,7 +22,6 @@ function runBackportViaCli(cliArgs, { showOra, waitForString, cwd, } = {}) {
22
22
  ], { cwd });
23
23
  return new Promise((resolve, reject) => {
24
24
  let data = '';
25
- const timeoutSeconds = 2;
26
25
  const rejectOnTimeout = (0, lodash_1.debounce)(() => {
27
26
  reject(`Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${data.toString()}`);
28
27
  }, timeoutSeconds * 1000, { maxWait: 15000 });
@@ -38,6 +37,15 @@ function runBackportViaCli(cliArgs, { showOra, waitForString, cwd, } = {}) {
38
37
  resolve(output);
39
38
  }
40
39
  };
40
+ proc.on('exit', (code) => {
41
+ rejectOnTimeout.cancel();
42
+ if (code !== null && code === 0) {
43
+ resolve(data.toString());
44
+ }
45
+ else {
46
+ reject(code);
47
+ }
48
+ });
41
49
  proc.stdout.on('data', onChunk);
42
50
  // ora (loading spinner) is redirected to stderr
43
51
  if (showOra) {
@@ -0,0 +1,376 @@
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('entrypoint.module', () => {
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
+ options: {
33
+ dir: sandboxPath,
34
+ accessToken,
35
+ repoOwner: 'backport-org',
36
+ repoName: 'integration-test',
37
+ sha: COMMIT_SHA_1,
38
+ targetBranches: ['7.x'],
39
+ },
40
+ });
41
+ // @ts-expect-error
42
+ const pullRequestNumber = res.results[0].pullRequestNumber;
43
+ pullRequestResponse = await octokit.pulls.get({
44
+ owner: REPO_OWNER,
45
+ repo: REPO_NAME,
46
+ pull_number: pullRequestNumber,
47
+ });
48
+ });
49
+ it('returns the backport result', () => {
50
+ expect(res).toEqual({
51
+ commits: [
52
+ {
53
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
54
+ expectedTargetPullRequests: [],
55
+ sourceBranch: 'master',
56
+ sourceCommit: {
57
+ committedDate: '2020-08-15T10:37:41Z',
58
+ message: 'Add ❤️ emoji',
59
+ sha: COMMIT_SHA_1,
60
+ },
61
+ sourcePullRequest: undefined,
62
+ },
63
+ ],
64
+ results: [
65
+ {
66
+ didUpdate: false,
67
+ pullRequestNumber: expect.any(Number),
68
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
69
+ status: 'success',
70
+ targetBranch: '7.x',
71
+ },
72
+ ],
73
+ status: 'success',
74
+ });
75
+ });
76
+ it('pull request: status code', async () => {
77
+ expect(pullRequestResponse.status).toEqual(200);
78
+ });
79
+ it('pull request: title', async () => {
80
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
81
+ });
82
+ it('pull request: body', async () => {
83
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
84
+ "# Backport
85
+
86
+ This will backport the following commits from \`master\` to \`7.x\`:
87
+ - Add ❤️ emoji (5bf29b7d)
88
+
89
+ <!--- Backport version: 1.2.3-mocked -->
90
+
91
+ ### Questions ?
92
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
93
+ `);
94
+ });
95
+ it('pull request: head branch is in fork repo', async () => {
96
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_ONE_COMMIT}`);
97
+ });
98
+ it('pull request: base branch', async () => {
99
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
100
+ });
101
+ it('does not create any new branches in origin (backport-org/integration-test)', async () => {
102
+ const branches = await getBranchesOnGithub({
103
+ accessToken,
104
+ repoOwner: REPO_OWNER,
105
+ repoName: REPO_NAME,
106
+ });
107
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
108
+ });
109
+ it('creates a branch in the fork (sqren/integration-test)', async () => {
110
+ const branches = await getBranchesOnGithub({
111
+ accessToken,
112
+ repoOwner: AUTHOR,
113
+ repoName: REPO_NAME,
114
+ });
115
+ expect(branches.map((b) => b.name)).toEqual([
116
+ '7.x',
117
+ BRANCH_WITH_ONE_COMMIT,
118
+ 'master',
119
+ ]);
120
+ });
121
+ });
122
+ describe('when two commits are backported', () => {
123
+ let res;
124
+ let pullRequestResponse;
125
+ beforeAll(async () => {
126
+ await resetState(accessToken);
127
+ res = await (0, entrypoint_module_1.backportRun)({
128
+ options: {
129
+ dir: sandboxPath,
130
+ accessToken,
131
+ repoOwner: 'backport-org',
132
+ repoName: 'integration-test',
133
+ sha: [COMMIT_SHA_1, COMMIT_SHA_2],
134
+ targetBranches: ['7.x'],
135
+ },
136
+ });
137
+ // @ts-expect-error
138
+ const pullRequestNumber = res.results[0].pullRequestNumber;
139
+ pullRequestResponse = await octokit.pulls.get({
140
+ owner: REPO_OWNER,
141
+ repo: REPO_NAME,
142
+ pull_number: pullRequestNumber,
143
+ });
144
+ });
145
+ it('returns the backport result containing both commits', () => {
146
+ expect(res).toEqual({
147
+ commits: [
148
+ {
149
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
150
+ expectedTargetPullRequests: [],
151
+ sourceBranch: 'master',
152
+ sourceCommit: {
153
+ committedDate: '2020-08-15T10:37:41Z',
154
+ message: 'Add ❤️ emoji',
155
+ sha: COMMIT_SHA_1,
156
+ },
157
+ sourcePullRequest: undefined,
158
+ },
159
+ {
160
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
161
+ expectedTargetPullRequests: [],
162
+ sourceBranch: 'master',
163
+ sourceCommit: {
164
+ committedDate: '2020-08-15T10:44:04Z',
165
+ message: 'Add family emoji (#2)',
166
+ sha: COMMIT_SHA_2,
167
+ },
168
+ sourcePullRequest: undefined,
169
+ },
170
+ ],
171
+ results: [
172
+ {
173
+ didUpdate: false,
174
+ pullRequestNumber: expect.any(Number),
175
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
176
+ status: 'success',
177
+ targetBranch: '7.x',
178
+ },
179
+ ],
180
+ status: 'success',
181
+ });
182
+ });
183
+ it('pull request: status code', async () => {
184
+ expect(pullRequestResponse.status).toEqual(200);
185
+ });
186
+ it('pull request: title', async () => {
187
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji | Add family emoji (#2)');
188
+ });
189
+ it('pull request: body', async () => {
190
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
191
+ "# Backport
192
+
193
+ This will backport the following commits from \`master\` to \`7.x\`:
194
+ - Add ❤️ emoji (5bf29b7d)
195
+ - Add family emoji (#2) (59d6ff1c)
196
+
197
+ <!--- Backport version: 1.2.3-mocked -->
198
+
199
+ ### Questions ?
200
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
201
+ `);
202
+ });
203
+ it('pull request: head branch contains both commits in name', async () => {
204
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_TWO_COMMITS}`);
205
+ });
206
+ it('pull request: base branch', async () => {
207
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
208
+ });
209
+ });
210
+ describe('when disabling fork mode', () => {
211
+ let res;
212
+ let pullRequestResponse;
213
+ beforeAll(async () => {
214
+ await resetState(accessToken);
215
+ res = await (0, entrypoint_module_1.backportRun)({
216
+ options: {
217
+ fork: false,
218
+ dir: sandboxPath,
219
+ accessToken,
220
+ repoOwner: 'backport-org',
221
+ repoName: 'integration-test',
222
+ sha: COMMIT_SHA_1,
223
+ targetBranches: ['7.x'],
224
+ },
225
+ });
226
+ // @ts-expect-error
227
+ const pullRequestNumber = res.results[0].pullRequestNumber;
228
+ pullRequestResponse = await octokit.pulls.get({
229
+ owner: REPO_OWNER,
230
+ repo: REPO_NAME,
231
+ pull_number: pullRequestNumber,
232
+ });
233
+ });
234
+ it('pull request: title', async () => {
235
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
236
+ });
237
+ it('pull request: body', async () => {
238
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
239
+ "# Backport
240
+
241
+ This will backport the following commits from \`master\` to \`7.x\`:
242
+ - Add ❤️ emoji (5bf29b7d)
243
+
244
+ <!--- Backport version: 1.2.3-mocked -->
245
+
246
+ ### Questions ?
247
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
248
+ `);
249
+ });
250
+ it('pull request: head branch is in origin (non-fork) repo', async () => {
251
+ expect(pullRequestResponse.data.head.label).toEqual(`backport-org:${BRANCH_WITH_ONE_COMMIT}`);
252
+ });
253
+ it('pull request: base branch', async () => {
254
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
255
+ });
256
+ it('returns pull request', () => {
257
+ expect(res).toEqual({
258
+ commits: [
259
+ {
260
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
261
+ expectedTargetPullRequests: [],
262
+ sourceBranch: 'master',
263
+ sourceCommit: {
264
+ committedDate: '2020-08-15T10:37:41Z',
265
+ message: 'Add ❤️ emoji',
266
+ sha: COMMIT_SHA_1,
267
+ },
268
+ sourcePullRequest: undefined,
269
+ },
270
+ ],
271
+ results: [
272
+ {
273
+ didUpdate: false,
274
+ pullRequestNumber: expect.any(Number),
275
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
276
+ status: 'success',
277
+ targetBranch: '7.x',
278
+ },
279
+ ],
280
+ status: 'success',
281
+ });
282
+ });
283
+ it('creates a new branch in origin (backport-org/integration-test)', async () => {
284
+ const branches = await getBranchesOnGithub({
285
+ accessToken,
286
+ repoOwner: REPO_OWNER,
287
+ repoName: REPO_NAME,
288
+ });
289
+ expect(branches.map((b) => b.name)).toEqual([
290
+ '7.x',
291
+ BRANCH_WITH_ONE_COMMIT,
292
+ 'master',
293
+ ]);
294
+ });
295
+ it('does not create branches in the fork (sqren/integration-test)', async () => {
296
+ const branches = await getBranchesOnGithub({
297
+ accessToken,
298
+ repoOwner: AUTHOR,
299
+ repoName: REPO_NAME,
300
+ });
301
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
302
+ });
303
+ });
304
+ });
305
+ async function getBranchesOnGithub({ accessToken, repoOwner, repoName, }) {
306
+ // console.log(`fetch branches for ${repoOwner}`);
307
+ const octokit = new rest_1.Octokit({
308
+ auth: accessToken,
309
+ });
310
+ const res = await octokit.repos.listBranches({
311
+ owner: repoOwner,
312
+ repo: repoName,
313
+ });
314
+ return res.data;
315
+ }
316
+ async function deleteBranchOnGithub({ accessToken, repoOwner, repoName, branchName, }) {
317
+ try {
318
+ const octokit = new rest_1.Octokit({
319
+ auth: accessToken,
320
+ });
321
+ // console.log({ accessToken });
322
+ const opts = {
323
+ owner: repoOwner,
324
+ repo: repoName,
325
+ ref: `heads/${branchName}`,
326
+ };
327
+ const res = await octokit.git.deleteRef(opts);
328
+ // console.log(`Deleted ${repoOwner}:heads/${branchName}`);
329
+ return res.data;
330
+ }
331
+ catch (e) {
332
+ // console.log(
333
+ // `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
334
+ // );
335
+ //@ts-expect-error
336
+ if (e.message === 'Reference does not exist') {
337
+ return;
338
+ }
339
+ throw e;
340
+ }
341
+ }
342
+ async function resetState(accessToken) {
343
+ const ownerBranches = await getBranchesOnGithub({
344
+ accessToken,
345
+ repoOwner: REPO_OWNER,
346
+ repoName: REPO_NAME,
347
+ });
348
+ // delete all branches except master and 7.x
349
+ await Promise.all(ownerBranches
350
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
351
+ .map((b) => {
352
+ return deleteBranchOnGithub({
353
+ accessToken,
354
+ repoOwner: REPO_OWNER,
355
+ repoName: REPO_NAME,
356
+ branchName: b.name,
357
+ });
358
+ }));
359
+ const forkBranches = await getBranchesOnGithub({
360
+ accessToken,
361
+ repoOwner: AUTHOR,
362
+ repoName: REPO_NAME,
363
+ });
364
+ // delete all branches except master and 7.x
365
+ await Promise.all(forkBranches
366
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
367
+ .map((b) => {
368
+ return deleteBranchOnGithub({
369
+ accessToken,
370
+ repoOwner: AUTHOR,
371
+ repoName: REPO_NAME,
372
+ branchName: b.name,
373
+ });
374
+ }));
375
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
376
+ }
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const entrypoint_module_1 = require("../entrypoint.module");
4
4
  const getDevAccessToken_1 = require("./private/getDevAccessToken");
5
5
  const sandbox_1 = require("./sandbox");
6
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
7
  jest.unmock('find-up');
7
8
  jest.setTimeout(15000);
8
9
  describe('Handle unbackported pull requests', () => {
9
10
  it('shows missing backports for PR number 8', async () => {
10
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
11
11
  const commits = await (0, entrypoint_module_1.getCommits)({
12
12
  accessToken: accessToken,
13
13
  repoOwner: 'backport-org',
@@ -35,18 +35,19 @@ describe('Handle unbackported pull requests', () => {
35
35
  expect(commits[0]).toEqual(expectedCommit);
36
36
  });
37
37
  it('shows that backport failed because PR number 8 was not backported', async () => {
38
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
39
38
  const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
40
39
  await (0, sandbox_1.resetSandbox)(sandboxPath);
41
40
  const result = await (0, entrypoint_module_1.backportRun)({
42
- accessToken: accessToken,
43
- repoOwner: 'backport-org',
44
- repoName: 'repo-with-conflicts',
45
- pullNumber: 12,
46
- targetBranches: ['7.x'],
47
- dir: sandboxPath,
48
- ci: true,
49
- publishStatusComment: false,
41
+ options: {
42
+ accessToken: accessToken,
43
+ repoOwner: 'backport-org',
44
+ repoName: 'repo-with-conflicts',
45
+ pullNumber: 12,
46
+ targetBranches: ['7.x'],
47
+ dir: sandboxPath,
48
+ ci: true,
49
+ publishStatusComment: false,
50
+ },
50
51
  });
51
52
  const commit =
52
53
  //@ts-expect-error
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -5,7 +5,11 @@
5
5
  */
6
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
7
  if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
9
13
  }) : (function(o, m, k, k2) {
10
14
  if (k2 === undefined) k2 = k;
11
15
  o[k2] = m[k];
@@ -43,21 +47,21 @@ jest.mock('del', () => {
43
47
  return jest.fn(async (path) => `Attempted to delete ${path}`);
44
48
  });
45
49
  (0, mocks_1.mockOra)();
46
- // silence logger
47
50
  jest.mock('../../services/logger', () => {
48
51
  const spy = jest.fn();
52
+ const logger = {
53
+ spy: spy,
54
+ info: (msg, meta) => spy(`[INFO] ${msg}`, meta),
55
+ verbose: (msg, meta) => spy(`[VERBOSE] ${msg}`, meta),
56
+ warn: (msg, meta) => spy(`[WARN] ${msg}`, meta),
57
+ error: (msg, meta) => spy(`[ERROR] ${msg}`, meta),
58
+ debug: (msg, meta) => spy(`[DEBUG] ${msg}`, meta),
59
+ };
49
60
  return {
50
- initLogger: jest.fn(),
61
+ initLogger: jest.fn(() => logger),
51
62
  redactAccessToken: jest.fn((str) => str),
52
63
  consoleLog: jest.fn(),
53
- updateLogger: jest.fn(),
54
- logger: {
55
- spy: spy,
56
- info: (msg, meta) => spy(`[INFO] ${msg}`, meta),
57
- verbose: (msg, meta) => spy(`[VERBOSE] ${msg}`, meta),
58
- warn: (msg, meta) => spy(`[WARN] ${msg}`, meta),
59
- error: (msg, meta) => spy(`[ERROR] ${msg}`, meta),
60
- debug: (msg, meta) => spy(`[DEBUG] ${msg}`, meta),
61
- },
64
+ setAccessToken: jest.fn(),
65
+ logger,
62
66
  };
63
67
  });
@@ -140,16 +140,20 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
140
140
  }
141
141
  autoResolveSpinner.fail();
142
142
  }
143
+ const conflictingFilesRelative = conflictingFiles
144
+ .map((f) => f.relative)
145
+ .slice(0, 50);
143
146
  const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
144
147
  options,
145
148
  commit,
146
149
  targetBranch,
147
- conflictingFiles: conflictingFiles.map((f) => f.relative).slice(0, 50),
150
+ conflictingFiles: conflictingFilesRelative,
148
151
  });
149
152
  if (options.ci) {
150
153
  throw new HandledError_1.HandledError({
151
154
  code: 'merge-conflict-exception',
152
155
  commitsWithoutBackports,
156
+ conflictingFiles: conflictingFilesRelative,
153
157
  });
154
158
  }
155
159
  (0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
@@ -162,7 +166,7 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
162
166
  * Commit could not be cleanly cherrypicked: Initiating conflict resolution
163
167
  */
164
168
  if (options.editor) {
165
- await (0, child_process_promisified_1.exec)(`${options.editor} ${repoPath}`, { cwd: options.cwd });
169
+ await (0, child_process_promisified_1.spawnPromise)(options.editor, [repoPath], options.cwd);
166
170
  }
167
171
  // list files with conflict markers + unstaged files and require user to resolve them
168
172
  await listConflictingAndUnstagedFiles({
@@ -201,13 +205,13 @@ async function listConflictingAndUnstagedFiles({ retries, options, conflictingFi
201
205
  const unstagedSection = hasUnstagedFiles
202
206
  ? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
203
207
  : '';
204
- const res = await (0, prompts_1.confirmPrompt)(`${header}
208
+ const didConfirm = await (0, prompts_1.confirmPrompt)(`${header}
205
209
 
206
210
  ${conflictSection}
207
211
  ${unstagedSection}
208
212
 
209
213
  Press ENTER when the conflicts are resolved and files are staged`);
210
- if (!res) {
214
+ if (!didConfirm) {
211
215
  throw new HandledError_1.HandledError({ code: 'abort-exception' });
212
216
  }
213
217
  const MAX_RETRIES = 100;