backport 6.1.2 → 6.2.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 (166) hide show
  1. package/README.md +39 -37
  2. package/dist/backportRun.d.ts +14 -0
  3. package/dist/backportRun.js +75 -0
  4. package/dist/entrypoint.api.d.ts +22 -0
  5. package/dist/entrypoint.api.js +57 -0
  6. package/dist/entrypoint.api.private.test.d.ts +1 -0
  7. package/dist/entrypoint.api.private.test.js +37 -0
  8. package/dist/entrypoint.module.d.ts +4 -1
  9. package/dist/entrypoint.module.js +10 -4
  10. package/dist/entrypoint.module.private.test.js +4 -1
  11. package/dist/main.js +5 -1
  12. package/dist/options/ConfigOptions.d.ts +2 -0
  13. package/dist/options/cliArgs.d.ts +5 -1
  14. package/dist/options/cliArgs.js +24 -2
  15. package/dist/options/config/config.d.ts +6 -1
  16. package/dist/options/config/config.js +2 -2
  17. package/dist/options/config/config.test.js +1 -1
  18. package/dist/options/config/getProjectConfig.d.ts +0 -0
  19. package/dist/options/config/getProjectConfig.js +1 -0
  20. package/dist/options/config/globalConfig.d.ts +1 -1
  21. package/dist/options/config/globalConfig.js +4 -8
  22. package/dist/options/config/globalConfig.test.js +2 -2
  23. package/dist/options/config/readConfigFile.d.ts +3 -1
  24. package/dist/options/options.d.ts +8 -1
  25. package/dist/options/options.js +9 -2
  26. package/dist/options/options.test.js +7 -3
  27. package/dist/react-components/0-loadOptions.d.ts +6 -0
  28. package/dist/react-components/0-loadOptions.js +45 -0
  29. package/dist/react-components/1-loadCommit.d.ts +8 -0
  30. package/dist/react-components/1-loadCommit.js +88 -0
  31. package/dist/react-components/1a-loadCommit.d.ts +5 -0
  32. package/dist/react-components/1a-loadCommit.js +76 -0
  33. package/dist/react-components/1b-commitChoices.d.ts +5 -0
  34. package/dist/react-components/1b-commitChoices.js +98 -0
  35. package/dist/react-components/2-commitChoices.d.ts +8 -0
  36. package/dist/react-components/2-commitChoices.js +96 -0
  37. package/dist/react-components/2-commitsPrompt.d.ts +8 -0
  38. package/dist/react-components/2-commitsPrompt.js +96 -0
  39. package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
  40. package/dist/react-components/2-targetBranchChoices.js +109 -0
  41. package/dist/react-components/3-cherrypick.d.ts +1 -0
  42. package/dist/react-components/3-cherrypick.js +2 -0
  43. package/dist/react-components/App.d.ts +2 -0
  44. package/dist/react-components/App.js +35 -0
  45. package/dist/react-components/BackportStateContext.d.ts +33 -0
  46. package/dist/react-components/BackportStateContext.js +42 -0
  47. package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
  48. package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
  49. package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
  50. package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
  51. package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
  52. package/dist/react-components/CommitPrompt/getCommits.js +27 -0
  53. package/dist/react-components/CommitPrompt.d.ts +8 -0
  54. package/dist/react-components/CommitPrompt.js +96 -0
  55. package/dist/react-components/CustomMultiSelect.d.ts +13 -0
  56. package/dist/react-components/CustomMultiSelect.js +21 -0
  57. package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
  58. package/dist/react-components/CustomMultiSelectItem.js +12 -0
  59. package/dist/react-components/CustomSelect.d.ts +14 -0
  60. package/dist/react-components/CustomSelect.js +34 -0
  61. package/dist/react-components/ErrorBoundary.d.ts +15 -0
  62. package/dist/react-components/ErrorBoundary.js +53 -0
  63. package/dist/react-components/MultiSelect.d.ts +7 -0
  64. package/dist/react-components/MultiSelect.js +16 -0
  65. package/dist/react-components/hooks/useAsync.d.ts +12 -0
  66. package/dist/react-components/hooks/useAsync.js +73 -0
  67. package/dist/runSequentially.test.js +10 -7
  68. package/dist/services/HandledError.d.ts +1 -1
  69. package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
  70. package/dist/services/backportRun/backportRun.ci.js +81 -0
  71. package/dist/services/backportRun/backportRun.d.ts +14 -0
  72. package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
  73. package/dist/services/backportRun/backportRun.interactive.js +4 -0
  74. package/dist/services/backportRun/backportRun.js +14 -0
  75. package/dist/services/backportRun/backportState.d.ts +4 -0
  76. package/dist/services/backportRun/backportState.js +28 -0
  77. package/dist/services/backportRun/getCommits.d.ts +2 -0
  78. package/dist/services/backportRun/getCommits.js +20 -0
  79. package/dist/services/backportRun/runSequentially.d.ts +20 -0
  80. package/dist/services/backportRun/runSequentially.js +41 -0
  81. package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
  82. package/dist/services/backportRun/runSequentially.test.js +199 -0
  83. package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
  84. package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
  85. package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  86. package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
  87. package/dist/services/env.d.ts +2 -3
  88. package/dist/services/env.js +9 -10
  89. package/dist/services/env.test.js +0 -6
  90. package/dist/services/getCommits.d.ts +2 -0
  91. package/dist/services/getCommits.js +38 -0
  92. package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
  93. package/dist/services/getCommitsWithoutBackports.js +68 -0
  94. package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
  95. package/dist/services/getCommitsWithoutBackports.test.js +259 -0
  96. package/dist/services/getTargetBranches.d.ts +5 -0
  97. package/dist/services/getTargetBranches.js +60 -0
  98. package/dist/services/getTargetBranches.test.d.ts +1 -0
  99. package/dist/services/getTargetBranches.test.js +180 -0
  100. package/dist/services/git.d.ts +2 -1
  101. package/dist/services/git.js +5 -3
  102. package/dist/services/github/v3/createPullRequest.js +1 -1
  103. package/dist/services/github/v3/createPullRequest.test.js +3 -3
  104. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  105. package/dist/services/github/v3/createStatusComment.js +40 -15
  106. package/dist/services/github/v3/createStatusComment.test.js +190 -73
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  110. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  112. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  114. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  115. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  116. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  119. package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
  120. package/dist/services/github/v4/fetchProjectConfig.js +3 -3
  121. package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
  122. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  123. package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
  124. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  125. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  126. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
  127. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
  128. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  129. package/dist/services/logger.d.ts +0 -1
  130. package/dist/services/logger.js +3 -3
  131. package/dist/services/maybeSetupRepo.d.ts +2 -0
  132. package/dist/services/maybeSetupRepo.js +33 -0
  133. package/dist/services/maybeSetupRepo.test.d.ts +1 -0
  134. package/dist/services/maybeSetupRepo.test.js +78 -0
  135. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  136. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  137. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  138. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  139. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  140. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  141. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  142. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  143. package/dist/test/backport-e2e.private.test.d.ts +1 -0
  144. package/dist/test/backport-e2e.private.test.js +327 -0
  145. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  146. package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
  147. package/dist/test/inquirer.private.test.js +1 -1
  148. package/dist/test/integration/integration.private.test.js +2 -2
  149. package/dist/test/nockHelpers.js +1 -3
  150. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  151. package/dist/todo-delete.d.ts +1 -0
  152. package/dist/todo-delete.js +17 -0
  153. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -3
  154. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
  155. package/dist/ui/getCommits.js +1 -1
  156. package/dist/ui/getCommitsWithoutBackports.js +17 -2
  157. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  158. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  159. package/dist/ui/maybeSetupRepo.js +0 -6
  160. package/dist/ui/maybeSetupRepo.test.js +8 -4
  161. package/dist/utils/redact.d.ts +1 -0
  162. package/dist/utils/redact.js +7 -0
  163. package/dist/utils/sequentially.d.ts +1 -0
  164. package/dist/utils/sequentially.js +10 -0
  165. package/package.json +3 -3
  166. package/yarn.lock +462 -284
@@ -0,0 +1,327 @@
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 path_1 = require("path");
9
+ const rest_1 = require("@octokit/rest");
10
+ const del = require("del");
11
+ const nock_1 = __importDefault(require("nock"));
12
+ const options_1 = require("../options/options");
13
+ const runSequentially_1 = require("../runSequentially");
14
+ const getCommits_1 = require("../ui/getCommits");
15
+ const mockConfigFiles_1 = require("./mockConfigFiles");
16
+ const nockHelpers_1 = require("./nockHelpers");
17
+ const getDevAccessToken_1 = require("./private/getDevAccessToken");
18
+ jest.unmock('make-dir');
19
+ jest.unmock('del');
20
+ jest.setTimeout(10000);
21
+ const E2E_TEST_DATA_PATH = (0, path_1.resolve)('./src/test/tmp-mock-environments/backport-e2e');
22
+ const HOMEDIR_PATH = (0, path_1.resolve)('./src/test/tmp-mock-environments/backport-e2e/homedir');
23
+ const REPO_OWNER = 'backport-org';
24
+ const REPO_NAME = 'integration-test';
25
+ const BRANCH_NAME = 'backport/7.x/commit-5bf29b7d';
26
+ const AUHTOR = 'sqren';
27
+ describe('backport e2e', () => {
28
+ afterAll(() => {
29
+ nock_1.default.cleanAll();
30
+ });
31
+ beforeAll(() => {
32
+ // set alternative homedir
33
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue(HOMEDIR_PATH);
34
+ (0, mockConfigFiles_1.mockConfigFiles)({
35
+ globalConfig: {},
36
+ projectConfig: {},
37
+ });
38
+ });
39
+ describe('when a single commit is backported', () => {
40
+ let res;
41
+ let accessToken;
42
+ let createPullRequestsMockCalls;
43
+ beforeAll(async () => {
44
+ accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
45
+ await resetState(accessToken);
46
+ createPullRequestsMockCalls = mockCreatePullRequest({
47
+ number: 1337,
48
+ html_url: 'myHtmlUrl',
49
+ });
50
+ const options = await (0, options_1.getOptions)([], {
51
+ githubApiBaseUrlV3: 'https://api.foo.com',
52
+ ci: true,
53
+ sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
54
+ author: AUHTOR,
55
+ accessToken,
56
+ repoOwner: 'backport-org',
57
+ repoName: 'integration-test',
58
+ });
59
+ const commits = await (0, getCommits_1.getCommits)(options);
60
+ const targetBranches = ['7.x'];
61
+ res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
62
+ });
63
+ it('returns pull request', () => {
64
+ expect(res).toEqual([
65
+ {
66
+ didUpdate: false,
67
+ pullRequestUrl: 'myHtmlUrl',
68
+ pullRequestNumber: 1337,
69
+ status: 'success',
70
+ targetBranch: '7.x',
71
+ },
72
+ ]);
73
+ });
74
+ it('sends the correct http body when creating pull request', () => {
75
+ expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
76
+ Array [
77
+ Object {
78
+ "base": "7.x",
79
+ "body": "# Backport
80
+
81
+ This is an automatic backport to \`7.x\` of:
82
+ - Add ❤️ emoji (5bf29b7d)
83
+
84
+ ### Questions ?
85
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
86
+ ",
87
+ "head": "sqren:backport/7.x/commit-5bf29b7d",
88
+ "title": "[7.x] Add ❤️ emoji",
89
+ },
90
+ ]
91
+ `);
92
+ });
93
+ it('should not create new branches in origin (backport-org/integration-test)', async () => {
94
+ const branches = await getBranches({
95
+ accessToken,
96
+ repoOwner: REPO_OWNER,
97
+ repoName: REPO_NAME,
98
+ });
99
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
100
+ });
101
+ it('should create branch in the fork (sqren/integration-test)', async () => {
102
+ const branches = await getBranches({
103
+ accessToken,
104
+ repoOwner: AUHTOR,
105
+ repoName: REPO_NAME,
106
+ });
107
+ expect(branches.map((b) => b.name)).toEqual([
108
+ '7.x',
109
+ BRANCH_NAME,
110
+ 'master',
111
+ ]);
112
+ });
113
+ it('should have cherry picked the correct commit', async () => {
114
+ const branches = await getBranches({
115
+ accessToken,
116
+ repoOwner: AUHTOR,
117
+ repoName: REPO_NAME,
118
+ });
119
+ const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
120
+ expect(sha).toEqual('b68e4fcaaf4427fe1e902c718b3bb3f07b560fb5');
121
+ });
122
+ });
123
+ // describe.skip('when two commits are backported', () => {
124
+ // let createPullRequestsMockCalls: unknown[];
125
+ // let res: Awaited<ReturnType<typeof runSequentially>>;
126
+ // let accessToken: string;
127
+ // beforeAll(async () => {
128
+ // accessToken = await getDevAccessToken();
129
+ // await resetState(accessToken);
130
+ // createPullRequestsMockCalls = mockCreatePullRequest({
131
+ // number: 1337,
132
+ // html_url: 'myHtmlUrl',
133
+ // });
134
+ // const options = {
135
+ // githubApiBaseUrlV3: 'https://api.foo.com',
136
+ // ci: true,
137
+ // sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
138
+ // author: AUHTOR,
139
+ // accessToken,
140
+ // repoOwner: 'backport-org',
141
+ // reponame: 'integration-test',
142
+ // } as ValidConfigOptions;
143
+ // const commits = await getCommits(options);
144
+ // const targetBranches: string[] = ['7.x'];
145
+ // res = await runSequentially({ options, commits, targetBranches });
146
+ // });
147
+ // it('sends the correct http body when creating pull request', () => {
148
+ // expect(createPullRequestsMockCalls).toMatchInlineSnapshot();
149
+ // });
150
+ // it('returns pull request', () => {
151
+ // expect(res).toEqual([
152
+ // { pullRequestUrl: 'myHtmlUrl', success: true, targetBranch: '6.0' },
153
+ // ]);
154
+ // });
155
+ // it('should not create new branches in origin (backport-org/integration-test)', async () => {
156
+ // const branches = await getBranches({
157
+ // accessToken,
158
+ // repoOwner: REPO_OWNER,
159
+ // repoName: REPO_NAME,
160
+ // });
161
+ // expect(branches.map((b) => b.name)).toEqual(['7.x', '* master']);
162
+ // });
163
+ // it('should create branch in the fork (sqren/integration-test)', async () => {
164
+ // const branches = await getBranches({
165
+ // accessToken,
166
+ // repoOwner: AUHTOR,
167
+ // repoName: REPO_NAME,
168
+ // });
169
+ // expect(branches.map((b) => b.name)).toEqual([
170
+ // '7.x',
171
+ // 'backport/6.0/pr-85_commit-2e63475c',
172
+ // 'master',
173
+ // ]);
174
+ // });
175
+ // it('should have cherry picked the correct commit', async () => {
176
+ // const branches = await getBranches({
177
+ // accessToken,
178
+ // repoOwner: AUHTOR,
179
+ // repoName: REPO_NAME,
180
+ // });
181
+ // const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
182
+ // expect(sha).toEqual('foo');
183
+ // });
184
+ // });
185
+ describe('when disabling fork mode', () => {
186
+ let res;
187
+ let accessToken;
188
+ let createPullRequestsMockCalls;
189
+ beforeAll(async () => {
190
+ accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
191
+ await resetState(accessToken);
192
+ createPullRequestsMockCalls = mockCreatePullRequest({
193
+ number: 1337,
194
+ html_url: 'myHtmlUrl',
195
+ });
196
+ const options = await (0, options_1.getOptions)([], {
197
+ author: AUHTOR,
198
+ githubApiBaseUrlV3: 'https://api.foo.com',
199
+ ci: true,
200
+ sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
201
+ accessToken,
202
+ repoOwner: 'backport-org',
203
+ repoName: 'integration-test',
204
+ fork: false,
205
+ });
206
+ const commits = await (0, getCommits_1.getCommits)(options);
207
+ const targetBranches = ['7.x'];
208
+ res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
209
+ });
210
+ it('sends the correct http body when creating pull request', () => {
211
+ expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
212
+ Array [
213
+ Object {
214
+ "base": "7.x",
215
+ "body": "# Backport
216
+
217
+ This is an automatic backport to \`7.x\` of:
218
+ - Add ❤️ emoji (5bf29b7d)
219
+
220
+ ### Questions ?
221
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
222
+ ",
223
+ "head": "backport-org:backport/7.x/commit-5bf29b7d",
224
+ "title": "[7.x] Add ❤️ emoji",
225
+ },
226
+ ]
227
+ `);
228
+ });
229
+ it('returns pull request', () => {
230
+ expect(res).toEqual([
231
+ {
232
+ didUpdate: false,
233
+ pullRequestNumber: 1337,
234
+ pullRequestUrl: 'myHtmlUrl',
235
+ status: 'success',
236
+ targetBranch: '7.x',
237
+ },
238
+ ]);
239
+ });
240
+ it('should create new branches in origin (backport-org/integration-test)', async () => {
241
+ const branches = await getBranches({
242
+ accessToken,
243
+ repoOwner: REPO_OWNER,
244
+ repoName: REPO_NAME,
245
+ });
246
+ expect(branches.map((b) => b.name)).toEqual([
247
+ '7.x',
248
+ BRANCH_NAME,
249
+ 'master',
250
+ ]);
251
+ });
252
+ it('should NOT create branch in the fork (sqren/integration-test)', async () => {
253
+ const branches = await getBranches({
254
+ accessToken,
255
+ repoOwner: AUHTOR,
256
+ repoName: REPO_NAME,
257
+ });
258
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
259
+ });
260
+ it('should cherry pick the correct commit', async () => {
261
+ const branches = await getBranches({
262
+ accessToken,
263
+ repoOwner: REPO_OWNER,
264
+ repoName: REPO_NAME,
265
+ });
266
+ const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
267
+ expect(sha).toEqual('b68e4fcaaf4427fe1e902c718b3bb3f07b560fb5');
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
+ await deleteBranch({
315
+ accessToken,
316
+ repoOwner: REPO_OWNER,
317
+ repoName: REPO_NAME,
318
+ branchName: BRANCH_NAME,
319
+ });
320
+ await deleteBranch({
321
+ accessToken,
322
+ repoOwner: AUHTOR,
323
+ repoName: REPO_NAME,
324
+ branchName: BRANCH_NAME,
325
+ });
326
+ await del(E2E_TEST_DATA_PATH);
327
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ const entrypoint_module_1 = require("../entrypoint.module");
5
+ const getDevAccessToken_1 = require("./private/getDevAccessToken");
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 = await (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
+ expect(commits[0]).toEqual({
18
+ committedDate: '2021-12-16T00:03:34Z',
19
+ expectedTargetPullRequests: [{ branch: '7.x', state: 'MISSING' }],
20
+ originalMessage: 'Change Barca to Braithwaite (#8)',
21
+ pullNumber: 8,
22
+ pullUrl: 'https://github.com/backport-org/repo-with-conflicts/pull/8',
23
+ sha: '343402a748be2375325b2730fa979bcea5b96ba1',
24
+ sourceBranch: 'main',
25
+ });
26
+ });
27
+ it('shows that backport failed because PR number 8 was not backported', async () => {
28
+ const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
29
+ const result = await (0, entrypoint_module_1.backportRun)({
30
+ accessToken: accessToken,
31
+ repoOwner: 'backport-org',
32
+ repoName: 'repo-with-conflicts',
33
+ pullNumber: 12,
34
+ targetBranches: ['7.x'],
35
+ dir: (0, path_1.resolve)('./src/test/tmp-mock-environments/handleUnbackportedPullRequests'),
36
+ ci: true,
37
+ publishStatusComment: false,
38
+ });
39
+ expect(
40
+ //@ts-expect-error
41
+ result.results[0].error.meta?.commitsWithoutBackports[0].commit.pullNumber).toBe(8);
42
+ });
43
+ });
@@ -50,7 +50,7 @@ describe('inquirer cli', () => {
50
50
  devAccessToken,
51
51
  ]);
52
52
  const lineCount = res.split('\n').length;
53
- expect(lineCount).toBe(12);
53
+ expect(lineCount).toBe(11);
54
54
  expect(res.includes('Select commit (Use arrow keys)')).toBe(true);
55
55
  });
56
56
  it('should return error when access token is invalid', async () => {
@@ -78,7 +78,7 @@ describe('integration', () => {
78
78
  "base": "7.x",
79
79
  "body": "# Backport
80
80
 
81
- This is an automatic backport to 7.x of:
81
+ This is an automatic backport to \`7.x\` of:
82
82
  - Add ❤️ emoji (5bf29b7d)
83
83
 
84
84
  ### Questions ?
@@ -214,7 +214,7 @@ describe('integration', () => {
214
214
  "base": "7.x",
215
215
  "body": "# Backport
216
216
 
217
- This is an automatic backport to 7.x of:
217
+ This is an automatic backport to \`7.x\` of:
218
218
  - Add ❤️ emoji (5bf29b7d)
219
219
 
220
220
  ### Questions ?
@@ -18,9 +18,7 @@ function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
18
18
  }
19
19
  exports.mockGqlRequest = mockGqlRequest;
20
20
  function getGqlName(query) {
21
- const obj = (0, graphql_tag_1.default) `
22
- ${query}
23
- `;
21
+ const obj = (0, graphql_tag_1.default)(query);
24
22
  // @ts-expect-error
25
23
  return obj.definitions[0].name.value;
26
24
  }
@@ -28,6 +28,7 @@ jest.mock('ora', () => {
28
28
  jest.mock('../../services/logger', () => {
29
29
  const spy = jest.fn();
30
30
  return {
31
+ initLogger: jest.fn(),
31
32
  redactAccessToken: jest.fn((str) => str),
32
33
  consoleLog: jest.fn(),
33
34
  updateLogger: jest.fn(),
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const entrypoint_module_1 = require("./entrypoint.module");
4
+ async function init() {
5
+ const { accessToken } = await (0, entrypoint_module_1.getLocalGlobalConfig)();
6
+ if (!accessToken) {
7
+ throw new Error('Missing access token');
8
+ }
9
+ const commit = await (0, entrypoint_module_1.getCommits)({
10
+ accessToken: accessToken,
11
+ repoOwner: 'backport-org',
12
+ repoName: 'repo-with-conflicts',
13
+ pullNumber: 8,
14
+ });
15
+ console.log({ commit });
16
+ }
17
+ init();
@@ -103,13 +103,14 @@ function getBackportBranchName(targetBranch, commits) {
103
103
  exports.getBackportBranchName = getBackportBranchName;
104
104
  async function waitForCherrypick(options, commit, targetBranch) {
105
105
  const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.originalMessage))}`;
106
+ const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
106
107
  const cherrypickSpinner = ora(spinnerText).start();
107
108
  let conflictingFiles;
108
109
  let unstagedFiles;
109
110
  let needsResolving;
110
111
  try {
111
112
  await (0, git_1.fetchBranch)(options, commit.sourceBranch);
112
- ({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha));
113
+ ({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha, mergedTargetPullRequest));
113
114
  // no conflicts encountered
114
115
  if (!needsResolving) {
115
116
  cherrypickSpinner.succeed();
@@ -147,13 +148,13 @@ async function waitForCherrypick(options, commit, targetBranch) {
147
148
  });
148
149
  if (options.ci) {
149
150
  throw new HandledError_1.HandledError(`Commit could not be cherrypicked due to conflicts`, {
150
- type: 'commitsWithoutBackports',
151
+ type: 'merge-conflict-due-to-missing-backports',
151
152
  commitsWithoutBackports,
152
153
  });
153
154
  }
154
155
  (0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
155
156
  if (commitsWithoutBackports.length > 0) {
156
- (0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following commits to "${targetBranch}":`));
157
+ (0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to "${targetBranch}":`));
157
158
  (0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
158
159
  }
159
160
  /*