backport 7.2.0-beta.1 → 7.2.0-beta.2

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 (129) hide show
  1. package/dist/entrypoint.cli.js +0 -0
  2. package/dist/entrypoint.module.d.ts +4 -3
  3. package/dist/entrypoint.module.js +2 -7
  4. package/dist/options/ConfigOptions.d.ts +1 -1
  5. package/dist/options/cliArgs.d.ts +1 -0
  6. package/dist/options/cliArgs.js +4 -0
  7. package/dist/options/config/config.d.ts +1 -1
  8. package/dist/options/config/readConfigFile.d.ts +1 -1
  9. package/dist/options/options.d.ts +2 -1
  10. package/dist/services/github/v3/createStatusComment.js +1 -1
  11. package/dist/services/github/v4/apiRequestV4.d.ts +2 -3
  12. package/dist/services/github/v4/apiRequestV4.js +15 -14
  13. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +2 -2
  14. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  15. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
  16. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +2 -2
  17. package/dist/services/github/v4/fetchRemoteProjectConfig.js +1 -1
  18. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
  19. package/dist/services/github/v4/getOptionsFromGithub/query.js +1 -1
  20. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  21. package/dist/services/remoteConfig.js +2 -2
  22. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  23. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  24. package/dist/services/sourceCommit/getMockSourceCommit.js +19 -18
  25. package/dist/services/sourceCommit/parseSourceCommit.d.ts +2 -2
  26. package/dist/services/sourceCommit/parseSourceCommit.js +9 -15
  27. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -18
  28. package/dist/ui/getCommits.js +6 -4
  29. package/dist/ui/maybeSetupRepo.js +7 -14
  30. package/dist/utils/packageVersion.d.ts +1 -1
  31. package/dist/utils/packageVersion.js +1 -1
  32. package/package.json +9 -9
  33. package/yarn.lock +121 -114
  34. package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
  35. package/dist/entrypoint.cli.e2e.private.test.js +0 -386
  36. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  37. package/dist/entrypoint.cli.private.test.js +0 -46
  38. package/dist/options/cliArgs.test.d.ts +0 -1
  39. package/dist/options/cliArgs.test.js +0 -182
  40. package/dist/options/config/config.test.d.ts +0 -1
  41. package/dist/options/config/config.test.js +0 -32
  42. package/dist/options/config/globalConfig.test.d.ts +0 -1
  43. package/dist/options/config/globalConfig.test.js +0 -61
  44. package/dist/options/config/projectConfig.test.d.ts +0 -1
  45. package/dist/options/config/projectConfig.test.js +0 -109
  46. package/dist/options/options.test.d.ts +0 -1
  47. package/dist/options/options.test.js +0 -384
  48. package/dist/runSequentially.test.d.ts +0 -1
  49. package/dist/runSequentially.test.js +0 -219
  50. package/dist/scripts/postinstall.test.d.ts +0 -1
  51. package/dist/scripts/postinstall.test.js +0 -53
  52. package/dist/services/env.test.d.ts +0 -1
  53. package/dist/services/env.test.js +0 -21
  54. package/dist/services/git.integration.test.d.ts +0 -1
  55. package/dist/services/git.integration.test.js +0 -320
  56. package/dist/services/git.test.d.ts +0 -1
  57. package/dist/services/git.test.js +0 -532
  58. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  59. package/dist/services/github/commitFormatters.test.js +0 -11
  60. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  61. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  62. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  63. package/dist/services/github/v3/createPullRequest.test.js +0 -325
  64. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  65. package/dist/services/github/v3/createStatusComment.test.js +0 -386
  66. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  67. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  68. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  69. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  70. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  71. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
  72. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  73. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  74. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  75. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -134
  76. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  77. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -116
  78. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  79. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -195
  80. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  81. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -152
  82. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  83. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
  84. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  85. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
  86. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  87. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
  88. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  89. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -117
  90. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  91. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
  92. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  93. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -159
  94. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  95. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  96. package/dist/services/prompt.test.d.ts +0 -1
  97. package/dist/services/prompt.test.js +0 -134
  98. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  99. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
  100. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  101. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -225
  102. package/dist/test/ExecError.d.ts +0 -16
  103. package/dist/test/ExecError.js +0 -15
  104. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  105. package/dist/test/backport-e2e.mutation.test.js +0 -347
  106. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
  107. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
  108. package/dist/test/mockConfigFiles.d.ts +0 -5
  109. package/dist/test/mockConfigFiles.js +0 -21
  110. package/dist/test/mocks.d.ts +0 -10
  111. package/dist/test/mocks.js +0 -23
  112. package/dist/test/nockHelpers.d.ts +0 -16
  113. package/dist/test/nockHelpers.js +0 -36
  114. package/dist/test/private/getDevAccessToken.d.ts +0 -2
  115. package/dist/test/private/getDevAccessToken.js +0 -12
  116. package/dist/test/sandbox.d.ts +0 -5
  117. package/dist/test/sandbox.js +0 -43
  118. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  119. package/dist/test/setupFiles/automatic-mocks.js +0 -63
  120. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  121. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -459
  122. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  123. package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
  124. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  125. package/dist/ui/getTargetBranches.test.js +0 -198
  126. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  127. package/dist/ui/maybeSetupRepo.test.js +0 -204
  128. package/dist/utils/excludeUndefined.test.d.ts +0 -1
  129. package/dist/utils/excludeUndefined.test.js +0 -24
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExecError = void 0;
4
- class ExecError extends Error {
5
- constructor(error) {
6
- super(error.stderr);
7
- this.name = 'ExecError';
8
- this.code = error.code;
9
- this.cmd = error.cmd;
10
- this.stdout = error.stdout;
11
- this.stderr = error.stderr;
12
- Error.captureStackTrace(this, ExecError);
13
- }
14
- }
15
- exports.ExecError = ExecError;
@@ -1 +0,0 @@
1
- export {};
@@ -1,347 +0,0 @@
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
- /* eslint-disable jest/no-commented-out-tests */
7
- const os_1 = __importDefault(require("os"));
8
- const rest_1 = require("@octokit/rest");
9
- const nock_1 = __importDefault(require("nock"));
10
- const options_1 = require("../options/options");
11
- const runSequentially_1 = require("../runSequentially");
12
- const getCommits_1 = require("../ui/getCommits");
13
- const mockConfigFiles_1 = require("./mockConfigFiles");
14
- const nockHelpers_1 = require("./nockHelpers");
15
- const getDevAccessToken_1 = require("./private/getDevAccessToken");
16
- const sandbox_1 = require("./sandbox");
17
- jest.setTimeout(10000);
18
- const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
19
- const REPO_OWNER = 'backport-org';
20
- const REPO_NAME = 'integration-test';
21
- const BRANCH_WITH_ONE_COMMIT = 'backport/7.x/commit-5bf29b7d';
22
- const BRANCH_WITH_TWO_COMMITS = 'backport/7.x/commit-5bf29b7d_commit-59d6ff1c';
23
- const AUTHOR = 'sqren';
24
- describe('backport e2e', () => {
25
- let accessToken;
26
- afterAll(() => {
27
- nock_1.default.cleanAll();
28
- });
29
- beforeAll(async () => {
30
- // set alternative homedir
31
- jest.spyOn(os_1.default, 'homedir').mockReturnValue(`${sandboxPath}/homedir`);
32
- accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
33
- (0, mockConfigFiles_1.mockConfigFiles)({
34
- globalConfig: {},
35
- projectConfig: {},
36
- });
37
- });
38
- describe('when a single commit is backported', () => {
39
- let res;
40
- let createPullRequestsMockCalls;
41
- beforeAll(async () => {
42
- await resetState(accessToken);
43
- createPullRequestsMockCalls = mockCreatePullRequest({
44
- number: 1337,
45
- html_url: 'myHtmlUrl',
46
- });
47
- const options = await (0, options_1.getOptions)([], {
48
- accessToken,
49
- author: AUTHOR,
50
- ci: true,
51
- githubApiBaseUrlV3: 'https://api.foo.com',
52
- repoName: 'integration-test',
53
- repoOwner: 'backport-org',
54
- sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
55
- });
56
- const commits = await (0, getCommits_1.getCommits)(options);
57
- const targetBranches = ['7.x'];
58
- res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
59
- });
60
- it('returns pull request', () => {
61
- expect(res).toEqual([
62
- {
63
- didUpdate: false,
64
- pullRequestUrl: 'myHtmlUrl',
65
- pullRequestNumber: 1337,
66
- status: 'success',
67
- targetBranch: '7.x',
68
- },
69
- ]);
70
- });
71
- it('sends the correct http body when creating pull request', () => {
72
- expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
73
- Array [
74
- Object {
75
- "base": "7.x",
76
- "body": "# Backport
77
-
78
- This will backport the following commits from \`master\` to \`7.x\`:
79
- - Add ❤️ emoji (5bf29b7d)
80
-
81
- <!--- Backport version: 1.2.3-mocked -->
82
-
83
- ### Questions ?
84
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
85
- "head": "sqren:backport/7.x/commit-5bf29b7d",
86
- "title": "[7.x] Add ❤️ emoji",
87
- },
88
- ]
89
- `);
90
- });
91
- it('should not create new branches in origin (backport-org/integration-test)', async () => {
92
- const branches = await getBranches({
93
- accessToken,
94
- repoOwner: REPO_OWNER,
95
- repoName: REPO_NAME,
96
- });
97
- expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
98
- });
99
- it('should create branch in the fork (sqren/integration-test)', async () => {
100
- const branches = await getBranches({
101
- accessToken,
102
- repoOwner: AUTHOR,
103
- repoName: REPO_NAME,
104
- });
105
- expect(branches.map((b) => b.name)).toEqual([
106
- '7.x',
107
- BRANCH_WITH_ONE_COMMIT,
108
- 'master',
109
- ]);
110
- });
111
- });
112
- describe('when two commits are backported', () => {
113
- let createPullRequestsMockCalls;
114
- let res;
115
- beforeAll(async () => {
116
- await resetState(accessToken);
117
- createPullRequestsMockCalls = mockCreatePullRequest({
118
- number: 1337,
119
- html_url: 'myHtmlUrl',
120
- });
121
- const options = await (0, options_1.getOptions)([], {
122
- accessToken,
123
- author: AUTHOR,
124
- ci: true,
125
- githubApiBaseUrlV3: 'https://api.foo.com',
126
- repoName: 'integration-test',
127
- repoOwner: 'backport-org',
128
- });
129
- const commits = [
130
- ...(await (0, getCommits_1.getCommits)({
131
- ...options,
132
- sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
133
- })),
134
- ...(await (0, getCommits_1.getCommits)({
135
- ...options,
136
- sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
137
- })),
138
- ];
139
- const targetBranches = ['7.x'];
140
- res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
141
- });
142
- it('contains both commits in the pull request body', () => {
143
- expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
144
- Array [
145
- Object {
146
- "base": "7.x",
147
- "body": "# Backport
148
-
149
- This will backport the following commits from \`master\` to \`7.x\`:
150
- - Add ❤️ emoji (5bf29b7d)
151
- - Add family emoji (#2) (59d6ff1c)
152
-
153
- <!--- Backport version: 1.2.3-mocked -->
154
-
155
- ### Questions ?
156
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
157
- "head": "sqren:backport/7.x/commit-5bf29b7d_commit-59d6ff1c",
158
- "title": "[7.x] Add ❤️ emoji | Add family emoji (#2)",
159
- },
160
- ]
161
- `);
162
- });
163
- it('returns the pull request response', () => {
164
- expect(res).toEqual([
165
- {
166
- didUpdate: false,
167
- pullRequestNumber: 1337,
168
- status: 'success',
169
- pullRequestUrl: 'myHtmlUrl',
170
- targetBranch: '7.x',
171
- },
172
- ]);
173
- });
174
- it('should not create new branches in origin (backport-org/integration-test)', async () => {
175
- const branches = await getBranches({
176
- accessToken,
177
- repoOwner: REPO_OWNER,
178
- repoName: REPO_NAME,
179
- });
180
- expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
181
- });
182
- it('should create branch in the fork (sqren/integration-test)', async () => {
183
- const branches = await getBranches({
184
- accessToken,
185
- repoOwner: AUTHOR,
186
- repoName: REPO_NAME,
187
- });
188
- expect(branches.map((b) => b.name)).toEqual([
189
- '7.x',
190
- BRANCH_WITH_TWO_COMMITS,
191
- 'master',
192
- ]);
193
- });
194
- });
195
- describe('when disabling fork mode', () => {
196
- let res;
197
- let createPullRequestsMockCalls;
198
- beforeAll(async () => {
199
- await resetState(accessToken);
200
- createPullRequestsMockCalls = mockCreatePullRequest({
201
- number: 1337,
202
- html_url: 'myHtmlUrl',
203
- });
204
- const options = await (0, options_1.getOptions)([], {
205
- accessToken,
206
- author: AUTHOR,
207
- ci: true,
208
- fork: false,
209
- githubApiBaseUrlV3: 'https://api.foo.com',
210
- repoName: 'integration-test',
211
- repoOwner: 'backport-org',
212
- sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
213
- });
214
- const commits = await (0, getCommits_1.getCommits)(options);
215
- const targetBranches = ['7.x'];
216
- res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
217
- });
218
- it('sends the correct http body when creating pull request', () => {
219
- expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
220
- Array [
221
- Object {
222
- "base": "7.x",
223
- "body": "# Backport
224
-
225
- This will backport the following commits from \`master\` to \`7.x\`:
226
- - Add ❤️ emoji (5bf29b7d)
227
-
228
- <!--- Backport version: 1.2.3-mocked -->
229
-
230
- ### Questions ?
231
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
232
- "head": "backport-org:backport/7.x/commit-5bf29b7d",
233
- "title": "[7.x] Add ❤️ emoji",
234
- },
235
- ]
236
- `);
237
- });
238
- it('returns pull request', () => {
239
- expect(res).toEqual([
240
- {
241
- didUpdate: false,
242
- pullRequestNumber: 1337,
243
- pullRequestUrl: 'myHtmlUrl',
244
- status: 'success',
245
- targetBranch: '7.x',
246
- },
247
- ]);
248
- });
249
- it('should create new branches in origin (backport-org/integration-test)', async () => {
250
- const branches = await getBranches({
251
- accessToken,
252
- repoOwner: REPO_OWNER,
253
- repoName: REPO_NAME,
254
- });
255
- expect(branches.map((b) => b.name)).toEqual([
256
- '7.x',
257
- BRANCH_WITH_ONE_COMMIT,
258
- 'master',
259
- ]);
260
- });
261
- it('should NOT create branch in the fork (sqren/integration-test)', async () => {
262
- const branches = await getBranches({
263
- accessToken,
264
- repoOwner: AUTHOR,
265
- repoName: REPO_NAME,
266
- });
267
- expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
268
- });
269
- });
270
- });
271
- function mockCreatePullRequest(response) {
272
- const scope = (0, nock_1.default)('https://api.foo.com', { allowUnmocked: true })
273
- .post('/repos/backport-org/integration-test/pulls')
274
- .reply(200, response);
275
- return (0, nockHelpers_1.listenForCallsToNockScope)(scope);
276
- }
277
- async function getBranches({ accessToken, repoOwner, repoName, }) {
278
- // console.log(`fetch branches for ${repoOwner}`);
279
- const octokit = new rest_1.Octokit({
280
- auth: accessToken,
281
- });
282
- const res = await octokit.repos.listBranches({
283
- owner: repoOwner,
284
- repo: repoName,
285
- });
286
- return res.data;
287
- }
288
- async function deleteBranch({ accessToken, repoOwner, repoName, branchName, }) {
289
- try {
290
- const octokit = new rest_1.Octokit({
291
- auth: accessToken,
292
- });
293
- // console.log({ accessToken });
294
- const opts = {
295
- owner: repoOwner,
296
- repo: repoName,
297
- ref: `heads/${branchName}`,
298
- };
299
- const res = await octokit.git.deleteRef(opts);
300
- // console.log(`Deleted ${repoOwner}:heads/${branchName}`);
301
- return res.data;
302
- }
303
- catch (e) {
304
- // console.log(
305
- // `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
306
- // );
307
- if (e.message === 'Reference does not exist') {
308
- return;
309
- }
310
- throw e;
311
- }
312
- }
313
- async function resetState(accessToken) {
314
- const ownerBranches = await getBranches({
315
- accessToken,
316
- repoOwner: REPO_OWNER,
317
- repoName: REPO_NAME,
318
- });
319
- // delete all branches except master and 7.x
320
- await Promise.all(ownerBranches
321
- .filter((b) => b.name !== 'master' && b.name !== '7.x')
322
- .map((b) => {
323
- return deleteBranch({
324
- accessToken,
325
- repoOwner: REPO_OWNER,
326
- repoName: REPO_NAME,
327
- branchName: b.name,
328
- });
329
- }));
330
- const forkBranches = await getBranches({
331
- accessToken,
332
- repoOwner: AUTHOR,
333
- repoName: REPO_NAME,
334
- });
335
- // delete all branches except master and 7.x
336
- await Promise.all(forkBranches
337
- .filter((b) => b.name !== 'master' && b.name !== '7.x')
338
- .map((b) => {
339
- return deleteBranch({
340
- accessToken,
341
- repoOwner: AUTHOR,
342
- repoName: REPO_NAME,
343
- branchName: b.name,
344
- });
345
- }));
346
- await (0, sandbox_1.resetSandbox)(sandboxPath);
347
- }
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const entrypoint_module_1 = require("../entrypoint.module");
4
- const child_process_promisified_1 = require("../services/child-process-promisified");
5
- const getDevAccessToken_1 = require("./private/getDevAccessToken");
6
- const sandbox_1 = require("./sandbox");
7
- jest.unmock('find-up');
8
- jest.setTimeout(15000);
9
- describe('Handle unbackported pull requests', () => {
10
- it('shows missing backports for PR number 8', async () => {
11
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
12
- const commits = await (0, entrypoint_module_1.getCommits)({
13
- accessToken: accessToken,
14
- repoOwner: 'backport-org',
15
- repoName: 'repo-with-conflicts',
16
- pullNumber: 8,
17
- });
18
- const expectedCommit = {
19
- sourceCommit: {
20
- committedDate: '2021-12-16T00:03:34Z',
21
- message: 'Change Barca to Braithwaite (#8)',
22
- sha: '343402a748be2375325b2730fa979bcea5b96ba1',
23
- },
24
- sourcePullRequest: {
25
- number: 8,
26
- url: 'https://github.com/backport-org/repo-with-conflicts/pull/8',
27
- mergeCommit: {
28
- message: 'Change Barca to Braithwaite (#8)',
29
- sha: '343402a748be2375325b2730fa979bcea5b96ba1',
30
- },
31
- },
32
- sourceBranch: 'main',
33
- expectedTargetPullRequests: [{ branch: '7.x', state: 'MISSING' }],
34
- };
35
- expect(commits[0]).toEqual(expectedCommit);
36
- });
37
- it('shows that backport failed because PR number 8 was not backported', async () => {
38
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
39
- const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
40
- await (0, sandbox_1.resetSandbox)(sandboxPath);
41
- await (0, child_process_promisified_1.exec)('git init', { cwd: sandboxPath });
42
- const result = await (0, entrypoint_module_1.backportRun)({
43
- accessToken: accessToken,
44
- repoOwner: 'backport-org',
45
- repoName: 'repo-with-conflicts',
46
- pullNumber: 12,
47
- targetBranches: ['7.x'],
48
- dir: sandboxPath,
49
- ci: true,
50
- publishStatusComment: false,
51
- });
52
- const commit =
53
- //@ts-expect-error
54
- result.results[0].error.errorContext?.commitsWithoutBackports[0].commit;
55
- expect(commit.sourcePullRequest?.number).toBe(8);
56
- });
57
- });
@@ -1,5 +0,0 @@
1
- import { ConfigFileOptions } from '../options/ConfigOptions';
2
- export declare function mockConfigFiles({ projectConfig, globalConfig, }: {
3
- projectConfig: ConfigFileOptions;
4
- globalConfig: ConfigFileOptions;
5
- }): void;
@@ -1,21 +0,0 @@
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;
@@ -1,10 +0,0 @@
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
- };
@@ -1,23 +0,0 @@
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;
@@ -1,16 +0,0 @@
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[];
@@ -1,36 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import 'dotenv/config';
2
- export declare function getDevAccessToken(): string;
@@ -1,12 +0,0 @@
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;
@@ -1,5 +0,0 @@
1
- export declare function getSandboxPath({ filename, specname, }: {
2
- filename: string;
3
- specname?: string;
4
- }): string;
5
- export declare function resetSandbox(sandboxPath: string): Promise<void>;
@@ -1,43 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
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
- });