backport 7.2.0-beta.2 → 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 (104) hide show
  1. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  2. package/dist/entrypoint.cli.private.test.js +46 -0
  3. package/dist/options/cliArgs.test.d.ts +1 -0
  4. package/dist/options/cliArgs.test.js +182 -0
  5. package/dist/options/config/config.test.d.ts +1 -0
  6. package/dist/options/config/config.test.js +32 -0
  7. package/dist/options/config/globalConfig.test.d.ts +1 -0
  8. package/dist/options/config/globalConfig.test.js +61 -0
  9. package/dist/options/config/projectConfig.test.d.ts +1 -0
  10. package/dist/options/config/projectConfig.test.js +109 -0
  11. package/dist/options/options.test.d.ts +1 -0
  12. package/dist/options/options.test.js +384 -0
  13. package/dist/runSequentially.test.d.ts +1 -0
  14. package/dist/runSequentially.test.js +243 -0
  15. package/dist/scripts/postinstall.test.d.ts +1 -0
  16. package/dist/scripts/postinstall.test.js +53 -0
  17. package/dist/services/env.test.d.ts +1 -0
  18. package/dist/services/env.test.js +21 -0
  19. package/dist/services/git.d.ts +1 -3
  20. package/dist/services/git.integration.test.d.ts +1 -0
  21. package/dist/services/git.integration.test.js +320 -0
  22. package/dist/services/git.js +5 -3
  23. package/dist/services/git.test.d.ts +1 -0
  24. package/dist/services/git.test.js +532 -0
  25. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  26. package/dist/services/github/commitFormatters.test.js +11 -0
  27. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  28. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  29. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  30. package/dist/services/github/v3/createPullRequest.test.js +325 -0
  31. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  32. package/dist/services/github/v3/createStatusComment.test.js +386 -0
  33. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  34. package/dist/services/github/v4/apiRequestV4.test.js +109 -0
  35. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  36. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  37. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  38. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  39. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  40. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  41. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  42. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +134 -0
  43. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  44. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +116 -0
  45. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  46. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
  47. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +152 -0
  49. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
  51. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  52. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  53. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  54. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  55. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  56. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
  57. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  59. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  60. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +156 -0
  61. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  62. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  63. package/dist/services/prompt.test.d.ts +1 -0
  64. package/dist/services/prompt.test.js +134 -0
  65. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  66. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  67. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  68. package/dist/services/sourceCommit/parseSourceCommit.test.js +225 -0
  69. package/dist/test/ExecError.d.ts +16 -0
  70. package/dist/test/ExecError.js +15 -0
  71. package/dist/test/e2e/cli.e2e.private.test.d.ts +1 -0
  72. package/dist/test/e2e/cli.e2e.private.test.js +433 -0
  73. package/dist/test/e2e/module.e2e.private.test.d.ts +1 -0
  74. package/dist/test/e2e/module.e2e.private.test.js +363 -0
  75. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  76. package/dist/test/handleUnbackportedPullRequests.private.test.js +55 -0
  77. package/dist/test/mockConfigFiles.d.ts +5 -0
  78. package/dist/test/mockConfigFiles.js +21 -0
  79. package/dist/test/mocks.d.ts +10 -0
  80. package/dist/test/mocks.js +23 -0
  81. package/dist/test/nockHelpers.d.ts +16 -0
  82. package/dist/test/nockHelpers.js +36 -0
  83. package/dist/test/private/getDevAccessToken.d.ts +2 -0
  84. package/dist/test/private/getDevAccessToken.js +12 -0
  85. package/dist/test/sandbox.d.ts +5 -0
  86. package/dist/test/sandbox.js +43 -0
  87. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  88. package/dist/test/setupFiles/automatic-mocks.js +63 -0
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +459 -0
  91. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  92. package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
  93. package/dist/ui/getTargetBranches.test.d.ts +1 -0
  94. package/dist/ui/getTargetBranches.test.js +198 -0
  95. package/dist/ui/maybeSetupRepo.js +7 -3
  96. package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
  97. package/dist/ui/maybeSetupRepo.test.js +238 -0
  98. package/dist/ui/ora.d.ts +1 -1
  99. package/dist/ui/ora.js +2 -2
  100. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  101. package/dist/utils/excludeUndefined.test.js +24 -0
  102. package/dist/utils/packageVersion.d.ts +1 -1
  103. package/dist/utils/packageVersion.js +1 -1
  104. package/package.json +1 -1
@@ -0,0 +1,363 @@
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.setTimeout(15000);
10
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
11
+ const octokit = new rest_1.Octokit({ auth: accessToken });
12
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
13
+ // repo
14
+ const REPO_OWNER = 'backport-org';
15
+ const REPO_NAME = 'integration-test';
16
+ const AUTHOR = 'sqren';
17
+ // commit 1
18
+ const COMMIT_SHA_1 = '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad';
19
+ const BRANCH_WITH_ONE_COMMIT = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}`;
20
+ // commit 2
21
+ const COMMIT_SHA_2 = '59d6ff1ca90a4ce210c0a4f0e159214875c19d60';
22
+ const BRANCH_WITH_TWO_COMMITS = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}_commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_2)}`;
23
+ describe('backport e2e', () => {
24
+ describe('when a single commit is backported', () => {
25
+ let res;
26
+ let pullRequestResponse;
27
+ beforeAll(async () => {
28
+ await resetState(accessToken);
29
+ res = await (0, entrypoint_module_1.backportRun)({
30
+ dir: sandboxPath,
31
+ accessToken,
32
+ repoOwner: 'backport-org',
33
+ repoName: 'integration-test',
34
+ sha: COMMIT_SHA_1,
35
+ targetBranches: ['7.x'],
36
+ });
37
+ // @ts-expect-error
38
+ const pullRequestNumber = res.results[0].pullRequestNumber;
39
+ pullRequestResponse = await octokit.pulls.get({
40
+ owner: REPO_OWNER,
41
+ repo: REPO_NAME,
42
+ pull_number: pullRequestNumber,
43
+ });
44
+ });
45
+ it('returns the backport result', () => {
46
+ expect(res).toEqual({
47
+ commits: [
48
+ {
49
+ expectedTargetPullRequests: [],
50
+ sourceBranch: 'master',
51
+ sourceCommit: {
52
+ committedDate: '2020-08-15T10:37:41Z',
53
+ message: 'Add ❤️ emoji',
54
+ sha: COMMIT_SHA_1,
55
+ },
56
+ sourcePullRequest: undefined,
57
+ },
58
+ ],
59
+ results: [
60
+ {
61
+ didUpdate: false,
62
+ pullRequestNumber: expect.any(Number),
63
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
64
+ status: 'success',
65
+ targetBranch: '7.x',
66
+ },
67
+ ],
68
+ status: 'success',
69
+ });
70
+ });
71
+ it('pull request: status code', async () => {
72
+ expect(pullRequestResponse.status).toEqual(200);
73
+ });
74
+ it('pull request: title', async () => {
75
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
76
+ });
77
+ it('pull request: body', async () => {
78
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
79
+ "# Backport
80
+
81
+ This will backport the following commits from \`master\` to \`7.x\`:
82
+ - Add ❤️ emoji (5bf29b7d)
83
+
84
+ <!--- Backport version: 1.2.3-mocked -->
85
+
86
+ ### Questions ?
87
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
88
+ `);
89
+ });
90
+ it('pull request: head branch is in fork repo', async () => {
91
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_ONE_COMMIT}`);
92
+ });
93
+ it('pull request: base branch', async () => {
94
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
95
+ });
96
+ it('does not create any new branches in origin (backport-org/integration-test)', async () => {
97
+ const branches = await getBranchesOnGithub({
98
+ accessToken,
99
+ repoOwner: REPO_OWNER,
100
+ repoName: REPO_NAME,
101
+ });
102
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
103
+ });
104
+ it('creates a branch in the fork (sqren/integration-test)', async () => {
105
+ const branches = await getBranchesOnGithub({
106
+ accessToken,
107
+ repoOwner: AUTHOR,
108
+ repoName: REPO_NAME,
109
+ });
110
+ expect(branches.map((b) => b.name)).toEqual([
111
+ '7.x',
112
+ BRANCH_WITH_ONE_COMMIT,
113
+ 'master',
114
+ ]);
115
+ });
116
+ });
117
+ describe('when two commits are backported', () => {
118
+ let res;
119
+ let pullRequestResponse;
120
+ beforeAll(async () => {
121
+ await resetState(accessToken);
122
+ res = await (0, entrypoint_module_1.backportRun)({
123
+ dir: sandboxPath,
124
+ accessToken,
125
+ repoOwner: 'backport-org',
126
+ repoName: 'integration-test',
127
+ sha: [COMMIT_SHA_1, COMMIT_SHA_2],
128
+ targetBranches: ['7.x'],
129
+ });
130
+ // @ts-expect-error
131
+ const pullRequestNumber = res.results[0].pullRequestNumber;
132
+ pullRequestResponse = await octokit.pulls.get({
133
+ owner: REPO_OWNER,
134
+ repo: REPO_NAME,
135
+ pull_number: pullRequestNumber,
136
+ });
137
+ });
138
+ it('returns the backport result containing both commits', () => {
139
+ expect(res).toEqual({
140
+ commits: [
141
+ {
142
+ expectedTargetPullRequests: [],
143
+ sourceBranch: 'master',
144
+ sourceCommit: {
145
+ committedDate: '2020-08-15T10:37:41Z',
146
+ message: 'Add ❤️ emoji',
147
+ sha: COMMIT_SHA_1,
148
+ },
149
+ sourcePullRequest: undefined,
150
+ },
151
+ {
152
+ expectedTargetPullRequests: [],
153
+ sourceBranch: 'master',
154
+ sourceCommit: {
155
+ committedDate: '2020-08-15T10:44:04Z',
156
+ message: 'Add family emoji (#2)',
157
+ sha: COMMIT_SHA_2,
158
+ },
159
+ sourcePullRequest: undefined,
160
+ },
161
+ ],
162
+ results: [
163
+ {
164
+ didUpdate: false,
165
+ pullRequestNumber: expect.any(Number),
166
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
167
+ status: 'success',
168
+ targetBranch: '7.x',
169
+ },
170
+ ],
171
+ status: 'success',
172
+ });
173
+ });
174
+ it('pull request: status code', async () => {
175
+ expect(pullRequestResponse.status).toEqual(200);
176
+ });
177
+ it('pull request: title', async () => {
178
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji | Add family emoji (#2)');
179
+ });
180
+ it('pull request: body', async () => {
181
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
182
+ "# Backport
183
+
184
+ This will backport the following commits from \`master\` to \`7.x\`:
185
+ - Add ❤️ emoji (5bf29b7d)
186
+ - Add family emoji (#2) (59d6ff1c)
187
+
188
+ <!--- Backport version: 1.2.3-mocked -->
189
+
190
+ ### Questions ?
191
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
192
+ `);
193
+ });
194
+ it('pull request: head branch contains both commits in name', async () => {
195
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_TWO_COMMITS}`);
196
+ });
197
+ it('pull request: base branch', async () => {
198
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
199
+ });
200
+ });
201
+ describe('when disabling fork mode', () => {
202
+ let res;
203
+ let pullRequestResponse;
204
+ beforeAll(async () => {
205
+ await resetState(accessToken);
206
+ res = await (0, entrypoint_module_1.backportRun)({
207
+ fork: false,
208
+ dir: sandboxPath,
209
+ accessToken,
210
+ repoOwner: 'backport-org',
211
+ repoName: 'integration-test',
212
+ sha: COMMIT_SHA_1,
213
+ targetBranches: ['7.x'],
214
+ });
215
+ // @ts-expect-error
216
+ const pullRequestNumber = res.results[0].pullRequestNumber;
217
+ pullRequestResponse = await octokit.pulls.get({
218
+ owner: REPO_OWNER,
219
+ repo: REPO_NAME,
220
+ pull_number: pullRequestNumber,
221
+ });
222
+ });
223
+ it('pull request: title', async () => {
224
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
225
+ });
226
+ it('pull request: body', async () => {
227
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
228
+ "# Backport
229
+
230
+ This will backport the following commits from \`master\` to \`7.x\`:
231
+ - Add ❤️ emoji (5bf29b7d)
232
+
233
+ <!--- Backport version: 1.2.3-mocked -->
234
+
235
+ ### Questions ?
236
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
237
+ `);
238
+ });
239
+ it('pull request: head branch is in origin (non-fork) repo', async () => {
240
+ expect(pullRequestResponse.data.head.label).toEqual(`backport-org:${BRANCH_WITH_ONE_COMMIT}`);
241
+ });
242
+ it('pull request: base branch', async () => {
243
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
244
+ });
245
+ it('returns pull request', () => {
246
+ expect(res).toEqual({
247
+ commits: [
248
+ {
249
+ expectedTargetPullRequests: [],
250
+ sourceBranch: 'master',
251
+ sourceCommit: {
252
+ committedDate: '2020-08-15T10:37:41Z',
253
+ message: 'Add ❤️ emoji',
254
+ sha: COMMIT_SHA_1,
255
+ },
256
+ sourcePullRequest: undefined,
257
+ },
258
+ ],
259
+ results: [
260
+ {
261
+ didUpdate: false,
262
+ pullRequestNumber: expect.any(Number),
263
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
264
+ status: 'success',
265
+ targetBranch: '7.x',
266
+ },
267
+ ],
268
+ status: 'success',
269
+ });
270
+ });
271
+ it('creates a new branch in origin (backport-org/integration-test)', async () => {
272
+ const branches = await getBranchesOnGithub({
273
+ accessToken,
274
+ repoOwner: REPO_OWNER,
275
+ repoName: REPO_NAME,
276
+ });
277
+ expect(branches.map((b) => b.name)).toEqual([
278
+ '7.x',
279
+ BRANCH_WITH_ONE_COMMIT,
280
+ 'master',
281
+ ]);
282
+ });
283
+ it('does not create branches in the fork (sqren/integration-test)', async () => {
284
+ const branches = await getBranchesOnGithub({
285
+ accessToken,
286
+ repoOwner: AUTHOR,
287
+ repoName: REPO_NAME,
288
+ });
289
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
290
+ });
291
+ });
292
+ });
293
+ async function getBranchesOnGithub({ accessToken, repoOwner, repoName, }) {
294
+ // console.log(`fetch branches for ${repoOwner}`);
295
+ const octokit = new rest_1.Octokit({
296
+ auth: accessToken,
297
+ });
298
+ const res = await octokit.repos.listBranches({
299
+ owner: repoOwner,
300
+ repo: repoName,
301
+ });
302
+ return res.data;
303
+ }
304
+ async function deleteBranchOnGithub({ accessToken, repoOwner, repoName, branchName, }) {
305
+ try {
306
+ const octokit = new rest_1.Octokit({
307
+ auth: accessToken,
308
+ });
309
+ // console.log({ accessToken });
310
+ const opts = {
311
+ owner: repoOwner,
312
+ repo: repoName,
313
+ ref: `heads/${branchName}`,
314
+ };
315
+ const res = await octokit.git.deleteRef(opts);
316
+ // console.log(`Deleted ${repoOwner}:heads/${branchName}`);
317
+ return res.data;
318
+ }
319
+ catch (e) {
320
+ // console.log(
321
+ // `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
322
+ // );
323
+ if (e.message === 'Reference does not exist') {
324
+ return;
325
+ }
326
+ throw e;
327
+ }
328
+ }
329
+ async function resetState(accessToken) {
330
+ const ownerBranches = await getBranchesOnGithub({
331
+ accessToken,
332
+ repoOwner: REPO_OWNER,
333
+ repoName: REPO_NAME,
334
+ });
335
+ // delete all branches except master and 7.x
336
+ await Promise.all(ownerBranches
337
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
338
+ .map((b) => {
339
+ return deleteBranchOnGithub({
340
+ accessToken,
341
+ repoOwner: REPO_OWNER,
342
+ repoName: REPO_NAME,
343
+ branchName: b.name,
344
+ });
345
+ }));
346
+ const forkBranches = await getBranchesOnGithub({
347
+ accessToken,
348
+ repoOwner: AUTHOR,
349
+ repoName: REPO_NAME,
350
+ });
351
+ // delete all branches except master and 7.x
352
+ await Promise.all(forkBranches
353
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
354
+ .map((b) => {
355
+ return deleteBranchOnGithub({
356
+ accessToken,
357
+ repoOwner: AUTHOR,
358
+ repoName: REPO_NAME,
359
+ branchName: b.name,
360
+ });
361
+ }));
362
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
363
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const entrypoint_module_1 = require("../entrypoint.module");
4
+ const getDevAccessToken_1 = require("./private/getDevAccessToken");
5
+ const sandbox_1 = require("./sandbox");
6
+ jest.unmock('find-up');
7
+ jest.setTimeout(15000);
8
+ describe('Handle unbackported pull requests', () => {
9
+ it('shows missing backports for PR number 8', async () => {
10
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
11
+ const commits = await (0, entrypoint_module_1.getCommits)({
12
+ accessToken: accessToken,
13
+ repoOwner: 'backport-org',
14
+ repoName: 'repo-with-conflicts',
15
+ pullNumber: 8,
16
+ });
17
+ const expectedCommit = {
18
+ sourceCommit: {
19
+ committedDate: '2021-12-16T00:03:34Z',
20
+ message: 'Change Barca to Braithwaite (#8)',
21
+ sha: '343402a748be2375325b2730fa979bcea5b96ba1',
22
+ },
23
+ sourcePullRequest: {
24
+ number: 8,
25
+ url: 'https://github.com/backport-org/repo-with-conflicts/pull/8',
26
+ mergeCommit: {
27
+ message: 'Change Barca to Braithwaite (#8)',
28
+ sha: '343402a748be2375325b2730fa979bcea5b96ba1',
29
+ },
30
+ },
31
+ sourceBranch: 'main',
32
+ expectedTargetPullRequests: [{ branch: '7.x', state: 'MISSING' }],
33
+ };
34
+ expect(commits[0]).toEqual(expectedCommit);
35
+ });
36
+ it('shows that backport failed because PR number 8 was not backported', async () => {
37
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
38
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
39
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
40
+ const result = await (0, entrypoint_module_1.backportRun)({
41
+ accessToken: accessToken,
42
+ repoOwner: 'backport-org',
43
+ repoName: 'repo-with-conflicts',
44
+ pullNumber: 12,
45
+ targetBranches: ['7.x'],
46
+ dir: sandboxPath,
47
+ ci: true,
48
+ publishStatusComment: false,
49
+ });
50
+ const commit =
51
+ //@ts-expect-error
52
+ result.results[0].error.errorContext?.commitsWithoutBackports[0].commit;
53
+ expect(commit.sourcePullRequest?.number).toBe(8);
54
+ });
55
+ });
@@ -0,0 +1,5 @@
1
+ import { ConfigFileOptions } from '../options/ConfigOptions';
2
+ export declare function mockConfigFiles({ projectConfig, globalConfig, }: {
3
+ projectConfig: ConfigFileOptions;
4
+ globalConfig: ConfigFileOptions;
5
+ }): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.mockConfigFiles = void 0;
7
+ const promises_1 = __importDefault(require("fs/promises"));
8
+ function mockConfigFiles({ projectConfig, globalConfig, }) {
9
+ jest
10
+ .spyOn(promises_1.default, 'readFile')
11
+ //@ts-expect-error
12
+ .mockImplementation(async (filepath) => {
13
+ if (filepath === '/path/to/project/config') {
14
+ return JSON.stringify(projectConfig);
15
+ }
16
+ if (filepath.endsWith('.backport/config.json')) {
17
+ return JSON.stringify(globalConfig);
18
+ }
19
+ });
20
+ }
21
+ exports.mockConfigFiles = mockConfigFiles;
@@ -0,0 +1,10 @@
1
+ /// <reference types="jest" />
2
+ export declare function mockOra(): void;
3
+ export declare function getOraMock(): {
4
+ start: () => any;
5
+ succeed: () => jest.Mock<any, any>;
6
+ stop: () => jest.Mock<any, any>;
7
+ fail: () => jest.Mock<any, any>;
8
+ stopAndPersist: () => jest.Mock<any, any>;
9
+ text: string;
10
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-empty-function */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getOraMock = exports.mockOra = void 0;
5
+ const oraMock = {
6
+ start: () => oraMock,
7
+ succeed: () => jest.fn(),
8
+ stop: () => jest.fn(),
9
+ fail: () => jest.fn(),
10
+ stopAndPersist: () => jest.fn(),
11
+ set text(value) { },
12
+ };
13
+ function mockOra() {
14
+ const ora = jest.fn(() => oraMock);
15
+ //@ts-expect-error
16
+ ora.oraMock = oraMock;
17
+ jest.mock('ora', () => ora);
18
+ }
19
+ exports.mockOra = mockOra;
20
+ function getOraMock() {
21
+ return oraMock;
22
+ }
23
+ exports.getOraMock = getOraMock;
@@ -0,0 +1,16 @@
1
+ import nock from 'nock';
2
+ export declare function mockGqlRequest<T>({ name, statusCode, body, headers, apiBaseUrl, }: {
3
+ name: string;
4
+ statusCode: number;
5
+ body?: {
6
+ data: T;
7
+ } | {
8
+ errors: any[];
9
+ };
10
+ headers?: any;
11
+ apiBaseUrl?: string;
12
+ }): {
13
+ query: string;
14
+ variables: string;
15
+ }[];
16
+ export declare function listenForCallsToNockScope(scope: nock.Scope): unknown[];
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.listenForCallsToNockScope = exports.mockGqlRequest = void 0;
7
+ const url_1 = require("url");
8
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
9
+ const graphql_tag_2 = require("graphql-tag");
10
+ const nock_1 = __importDefault(require("nock"));
11
+ (0, graphql_tag_2.disableFragmentWarnings)();
12
+ function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
13
+ const { origin, pathname } = new url_1.URL(
14
+ // default to localhost as host to avoid CORS issues
15
+ apiBaseUrl ?? 'http://localhost/graphql');
16
+ const scope = (0, nock_1.default)(origin)
17
+ .post(pathname, (body) => {
18
+ return getQueryNameFromString(body.query) === name;
19
+ })
20
+ .reply(statusCode, body, headers);
21
+ return listenForCallsToNockScope(scope);
22
+ }
23
+ exports.mockGqlRequest = mockGqlRequest;
24
+ function getQueryNameFromString(query) {
25
+ const obj = (0, graphql_tag_1.default)(query);
26
+ // @ts-expect-error
27
+ return obj.definitions[0].name.value;
28
+ }
29
+ function listenForCallsToNockScope(scope) {
30
+ const calls = [];
31
+ scope.on('request', (req, interceptor, body) => {
32
+ calls.push(JSON.parse(body));
33
+ });
34
+ return calls;
35
+ }
36
+ exports.listenForCallsToNockScope = listenForCallsToNockScope;
@@ -0,0 +1,2 @@
1
+ import 'dotenv/config';
2
+ export declare function getDevAccessToken(): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDevAccessToken = void 0;
4
+ require("dotenv/config");
5
+ function getDevAccessToken() {
6
+ const accessToken = process.env.ACCESS_TOKEN;
7
+ if (!accessToken) {
8
+ throw new Error('Please create ".env" file containing: `ACCESS_TOKEN="ghp_very_secret"`');
9
+ }
10
+ return accessToken;
11
+ }
12
+ exports.getDevAccessToken = getDevAccessToken;
@@ -0,0 +1,5 @@
1
+ export declare function getSandboxPath({ filename, specname, }: {
2
+ filename: string;
3
+ specname?: string;
4
+ }): string;
5
+ export declare function resetSandbox(sandboxPath: string): Promise<void>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.resetSandbox = exports.getSandboxPath = void 0;
26
+ const path_1 = __importStar(require("path"));
27
+ const del_1 = __importDefault(require("del"));
28
+ const make_dir_1 = __importDefault(require("make-dir"));
29
+ jest.unmock('make-dir');
30
+ jest.unmock('del');
31
+ function getSandboxPath({ filename, specname, }) {
32
+ const baseFilename = getFilenameWithoutExtension(filename);
33
+ return (0, path_1.resolve)(`${__dirname}/_tmp_sandbox_/${baseFilename}${specname ? `/${specname}` : ''}`);
34
+ }
35
+ exports.getSandboxPath = getSandboxPath;
36
+ async function resetSandbox(sandboxPath) {
37
+ await (0, del_1.default)(sandboxPath);
38
+ await (0, make_dir_1.default)(sandboxPath);
39
+ }
40
+ exports.resetSandbox = resetSandbox;
41
+ function getFilenameWithoutExtension(filename) {
42
+ return path_1.default.basename(filename, path_1.default.extname(filename));
43
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /*
3
+ * This file is included in `setupFiles` in jest.config.js
4
+ * It will be run once per test file
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const packageVersionModule = __importStar(require("../../utils/packageVersion"));
27
+ const mocks_1 = require("../mocks");
28
+ /* eslint-disable @typescript-eslint/no-empty-function */
29
+ jest.mock('find-up', () => {
30
+ return jest.fn(async () => '/path/to/project/config');
31
+ });
32
+ // @ts-expect-error
33
+ // eslint-disable-next-line no-import-assign
34
+ packageVersionModule.UNMOCKED_PACKAGE_VERSION =
35
+ packageVersionModule.PACKAGE_VERSION;
36
+ // @ts-expect-error
37
+ // eslint-disable-next-line no-import-assign
38
+ packageVersionModule.PACKAGE_VERSION = '1.2.3-mocked';
39
+ jest.mock('make-dir', () => {
40
+ return jest.fn(() => Promise.resolve('/some/path'));
41
+ });
42
+ jest.mock('del', () => {
43
+ return jest.fn(async (path) => `Attempted to delete ${path}`);
44
+ });
45
+ (0, mocks_1.mockOra)();
46
+ // silence logger
47
+ jest.mock('../../services/logger', () => {
48
+ const spy = jest.fn();
49
+ return {
50
+ initLogger: jest.fn(),
51
+ redactAccessToken: jest.fn((str) => str),
52
+ 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
+ },
62
+ };
63
+ });