backport 8.3.1 → 8.4.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 (202) hide show
  1. package/dist/lib/child-process-promisified.js +2 -2
  2. package/dist/lib/git.js +1 -0
  3. package/dist/lib/git.test.js +26 -0
  4. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  5. package/dist/options/ConfigOptions.d.ts +1 -0
  6. package/dist/options/cliArgs.d.ts +1 -0
  7. package/dist/options/cliArgs.js +5 -0
  8. package/dist/options/config/config.d.ts +1 -0
  9. package/dist/options/config/readConfigFile.d.ts +1 -0
  10. package/dist/options/options.d.ts +2 -0
  11. package/dist/options/options.js +1 -0
  12. package/dist/options/options.test.js +1 -0
  13. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -0
  14. package/dist/utils/packageVersion.d.ts +1 -1
  15. package/dist/utils/packageVersion.js +1 -1
  16. package/package.json +3 -4
  17. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  18. package/dist/entrypoint.cli.private.test.js +0 -47
  19. package/dist/errors/BackportError.d.ts +0 -19
  20. package/dist/errors/BackportError.js +0 -29
  21. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  22. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  23. package/dist/runSequentially.test.d.ts +0 -1
  24. package/dist/runSequentially.test.js +0 -243
  25. package/dist/services/BackportError.d.ts +0 -19
  26. package/dist/services/BackportError.js +0 -29
  27. package/dist/services/HandledBackportError.d.ts +0 -19
  28. package/dist/services/HandledBackportError.js +0 -29
  29. package/dist/services/HandledError.d.ts +0 -19
  30. package/dist/services/HandledError.js +0 -29
  31. package/dist/services/child-process-promisified.d.ts +0 -25
  32. package/dist/services/child-process-promisified.js +0 -58
  33. package/dist/services/env.d.ts +0 -7
  34. package/dist/services/env.js +0 -30
  35. package/dist/services/env.test.d.ts +0 -1
  36. package/dist/services/env.test.js +0 -21
  37. package/dist/services/git.d.ts +0 -77
  38. package/dist/services/git.integration.test.d.ts +0 -1
  39. package/dist/services/git.integration.test.js +0 -616
  40. package/dist/services/git.js +0 -439
  41. package/dist/services/git.private.test.d.ts +0 -1
  42. package/dist/services/git.private.test.js +0 -618
  43. package/dist/services/git.test.d.ts +0 -1
  44. package/dist/services/git.test.js +0 -580
  45. package/dist/services/github/commitFormatters.d.ts +0 -3
  46. package/dist/services/github/commitFormatters.js +0 -17
  47. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  48. package/dist/services/github/commitFormatters.test.js +0 -11
  49. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  50. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  51. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  52. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  53. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  54. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  55. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  56. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  57. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  58. package/dist/services/github/v3/createPullRequest.js +0 -91
  59. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  60. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  61. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  62. package/dist/services/github/v3/createStatusComment.js +0 -131
  63. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  64. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  65. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  66. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  67. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  68. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  69. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  70. package/dist/services/github/v4/apiRequestV4.js +0 -71
  71. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  72. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  73. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  74. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  75. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  76. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  77. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  78. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  79. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  80. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  81. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  82. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  83. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  84. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  85. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  86. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  87. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  88. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  89. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  90. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  91. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  92. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  93. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  94. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  95. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  96. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  97. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  98. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  99. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  100. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  101. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  102. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  103. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  104. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  105. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  106. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  107. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  108. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  109. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  110. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  111. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  112. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  113. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  114. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  115. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  116. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  117. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  118. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  119. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  120. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  121. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  122. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  123. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  124. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  125. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  126. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  127. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  128. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  129. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  130. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  131. package/dist/services/logger.d.ts +0 -9
  132. package/dist/services/logger.js +0 -74
  133. package/dist/services/prompt.test.d.ts +0 -1
  134. package/dist/services/prompt.test.js +0 -139
  135. package/dist/services/prompts.d.ts +0 -17
  136. package/dist/services/prompts.js +0 -132
  137. package/dist/services/remoteConfig.d.ts +0 -20
  138. package/dist/services/remoteConfig.js +0 -52
  139. package/dist/services/sequentially.d.ts +0 -1
  140. package/dist/services/sequentially.js +0 -10
  141. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  142. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  143. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  144. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  145. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  146. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  147. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  148. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  149. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  150. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  151. package/dist/services/test.d.ts +0 -1
  152. package/dist/services/test.js +0 -23
  153. package/dist/state.d.ts +0 -0
  154. package/dist/state.js +0 -1
  155. package/dist/test/ExecError.d.ts +0 -16
  156. package/dist/test/ExecError.js +0 -15
  157. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  158. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  159. package/dist/test/e2e/cli/date-filters.d.ts +0 -1
  160. package/dist/test/e2e/cli/date-filters.js +0 -43
  161. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  162. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  163. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  164. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  165. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  166. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  167. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  168. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  169. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  170. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  171. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  172. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  173. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  174. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  175. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  176. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  177. package/dist/ui/getCommits.d.ts +0 -2
  178. package/dist/ui/getCommits.js +0 -75
  179. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  180. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  181. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  182. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  183. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  184. package/dist/ui/getGitConfigAuthor.js +0 -15
  185. package/dist/ui/getTargetBranches.d.ts +0 -5
  186. package/dist/ui/getTargetBranches.js +0 -67
  187. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  188. package/dist/ui/getTargetBranches.test.js +0 -204
  189. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  190. package/dist/ui/maybeSetupRepo.js +0 -53
  191. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  192. package/dist/ui/maybeSetupRepo.test.js +0 -238
  193. package/dist/ui/ora.d.ts +0 -2
  194. package/dist/ui/ora.js +0 -21
  195. package/dist/ui/setupRepo.d.ts +0 -2
  196. package/dist/ui/setupRepo.js +0 -56
  197. package/dist/ui/setupRepo.test.d.ts +0 -1
  198. package/dist/ui/setupRepo.test.js +0 -273
  199. package/dist/utils/filterMissingCommits.d.ts +0 -2
  200. package/dist/utils/filterMissingCommits.js +0 -7
  201. package/dist/utils/redact.d.ts +0 -1
  202. package/dist/utils/redact.js +0 -7
@@ -1,320 +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
- 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);
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const os_1 = __importDefault(require("os"));
30
- const nock_1 = __importDefault(require("nock"));
31
- const ora_1 = __importDefault(require("ora"));
32
- const childProcess = __importStar(require("../services/child-process-promisified"));
33
- const logger = __importStar(require("../services/logger"));
34
- const nockHelpers_1 = require("../test/nockHelpers");
35
- const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
36
- describe('cherrypickAndCreateTargetPullRequest', () => {
37
- let execSpy;
38
- let addLabelsScope;
39
- let consoleLogSpy;
40
- beforeEach(() => {
41
- jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
42
- execSpy = jest
43
- .spyOn(childProcess, 'spawnPromise')
44
- // mock all exec commands to respond without errors
45
- .mockResolvedValue({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
46
- consoleLogSpy = jest.spyOn(logger, 'consoleLog');
47
- // ensure labels are added
48
- addLabelsScope = (0, nock_1.default)('https://api.github.com')
49
- .post('/repos/elastic/kibana/issues/1337/labels', {
50
- labels: ['backport'],
51
- })
52
- .reply(200);
53
- });
54
- afterEach(() => {
55
- jest.clearAllMocks();
56
- addLabelsScope.done();
57
- nock_1.default.cleanAll();
58
- });
59
- describe('when commit has a pull request reference', () => {
60
- let res;
61
- let createPullRequestCalls;
62
- beforeEach(async () => {
63
- const options = {
64
- assignees: [],
65
- authenticatedUsername: 'sqren_authenticated',
66
- author: 'sqren',
67
- fork: true,
68
- prTitle: '[{targetBranch}] {commitMessages}',
69
- repoForkOwner: 'sqren',
70
- repoName: 'kibana',
71
- repoOwner: 'elastic',
72
- reviewers: [],
73
- sourceBranch: 'myDefaultSourceBranch',
74
- sourcePRLabels: [],
75
- targetPRLabels: ['backport'],
76
- };
77
- const commits = [
78
- {
79
- author: {
80
- email: 'soren.louv@elastic.co',
81
- name: 'Søren Louv-Jansen',
82
- },
83
- sourceBranch: '7.x',
84
- sourceCommit: {
85
- committedDate: 'fff',
86
- sha: 'mySha',
87
- message: 'My original commit message (#1000)',
88
- },
89
- sourcePullRequest: {
90
- url: 'foo',
91
- number: 1000,
92
- mergeCommit: {
93
- sha: 'mySha',
94
- message: 'My original commit message (#1000)',
95
- },
96
- },
97
- expectedTargetPullRequests: [],
98
- },
99
- {
100
- author: {
101
- email: 'soren.louv@elastic.co',
102
- name: 'Søren Louv-Jansen',
103
- },
104
- sourceBranch: '7.x',
105
- sourceCommit: {
106
- committedDate: 'ggg',
107
- sha: 'mySha2',
108
- message: 'My other commit message (#2000)',
109
- },
110
- sourcePullRequest: {
111
- url: 'foo',
112
- number: 2000,
113
- mergeCommit: {
114
- sha: 'mySha2',
115
- message: 'My other commit message (#2000)',
116
- },
117
- },
118
- expectedTargetPullRequests: [],
119
- },
120
- ];
121
- const scope = (0, nock_1.default)('https://api.github.com')
122
- .post('/repos/elastic/kibana/pulls')
123
- .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
124
- createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
125
- res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
126
- options,
127
- commits,
128
- targetBranch: '6.x',
129
- });
130
- scope.done();
131
- nock_1.default.cleanAll();
132
- });
133
- it('creates the pull request with multiple PR references', () => {
134
- expect(createPullRequestCalls).toMatchInlineSnapshot(`
135
- Array [
136
- Object {
137
- "base": "6.x",
138
- "body": "# Backport
139
-
140
- This will backport the following commits from \`7.x\` to \`6.x\`:
141
- - [My original commit message (#1000)](foo)
142
- - [My other commit message (#2000)](foo)
143
-
144
- <!--- Backport version: 1.2.3-mocked -->
145
-
146
- ### Questions ?
147
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
148
- "head": "sqren:backport/6.x/pr-1000_pr-2000",
149
- "title": "[6.x] My original commit message (#1000) | My other commit message (#2000)",
150
- },
151
- ]
152
- `);
153
- });
154
- it('returns the expected response', () => {
155
- expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
156
- });
157
- it('should make correct git commands', () => {
158
- expect(execSpy.mock.calls).toMatchSnapshot();
159
- });
160
- it('logs correctly', () => {
161
- expect(consoleLogSpy.mock.calls.length).toBe(2);
162
- expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
163
- "
164
- Backporting to 6.x:"
165
- `);
166
- expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`"View pull request: myHtmlUrl"`);
167
- });
168
- it('should start the spinner with the correct text', () => {
169
- expect(ora_1.default.mock.calls.map((call) => call[0].text))
170
- .toMatchInlineSnapshot(`
171
- Array [
172
- "Pulling latest changes",
173
- "Cherry-picking: My original commit message (#1000)",
174
- "Cherry-picking: My other commit message (#2000)",
175
- "Pushing branch \\"sqren:backport/6.x/pr-1000_pr-2000\\"",
176
- undefined,
177
- "Creating pull request",
178
- "Adding labels: backport",
179
- ]
180
- `);
181
- });
182
- });
183
- describe('when commit does not have a pull request reference', () => {
184
- let res;
185
- let createPullRequestCalls;
186
- beforeEach(async () => {
187
- const options = {
188
- assignees: [],
189
- authenticatedUsername: 'sqren_authenticated',
190
- author: 'sqren',
191
- fork: true,
192
- prTitle: '[{targetBranch}] {commitMessages}',
193
- repoForkOwner: 'the_fork_owner',
194
- repoName: 'kibana',
195
- repoOwner: 'elastic',
196
- reviewers: [],
197
- sourcePRLabels: [],
198
- targetPRLabels: ['backport'],
199
- };
200
- const commits = [
201
- {
202
- author: {
203
- email: 'soren.louv@elastic.co',
204
- name: 'Søren Louv-Jansen',
205
- },
206
- sourceCommit: {
207
- committedDate: 'hhh',
208
- sha: 'mySha',
209
- message: 'My original commit message',
210
- },
211
- sourceBranch: '7.x',
212
- expectedTargetPullRequests: [],
213
- },
214
- ];
215
- const scope = (0, nock_1.default)('https://api.github.com')
216
- .post('/repos/elastic/kibana/pulls')
217
- .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
218
- createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
219
- res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
220
- options,
221
- commits,
222
- targetBranch: '6.x',
223
- });
224
- scope.done();
225
- nock_1.default.cleanAll();
226
- });
227
- it('creates the pull request with commit reference', () => {
228
- expect(createPullRequestCalls).toMatchInlineSnapshot(`
229
- Array [
230
- Object {
231
- "base": "6.x",
232
- "body": "# Backport
233
-
234
- This will backport the following commits from \`7.x\` to \`6.x\`:
235
- - My original commit message (mySha)
236
-
237
- <!--- Backport version: 1.2.3-mocked -->
238
-
239
- ### Questions ?
240
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
241
- "head": "the_fork_owner:backport/6.x/commit-mySha",
242
- "title": "[6.x] My original commit message",
243
- },
244
- ]
245
- `);
246
- });
247
- it('returns the expected response', () => {
248
- expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
249
- });
250
- });
251
- describe('when cherry-picking fails', () => {
252
- let res;
253
- let createPullRequestCalls;
254
- beforeEach(async () => {
255
- const options = {
256
- assignees: [],
257
- authenticatedUsername: 'sqren_authenticated',
258
- author: 'sqren',
259
- fork: true,
260
- githubApiBaseUrlV4: 'http://localhost/graphql',
261
- prTitle: '[{targetBranch}] {commitMessages}',
262
- repoForkOwner: 'sqren',
263
- repoName: 'kibana',
264
- repoOwner: 'elastic',
265
- reviewers: [],
266
- sourceBranch: 'myDefaultSourceBranch',
267
- sourcePRLabels: [],
268
- targetPRLabels: ['backport'],
269
- };
270
- const scope = (0, nock_1.default)('https://api.github.com')
271
- .post('/repos/elastic/kibana/pulls')
272
- .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
273
- createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
274
- res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
275
- options,
276
- commits: [
277
- {
278
- author: {
279
- email: 'soren.louv@elastic.co',
280
- name: 'Søren Louv-Jansen',
281
- },
282
- sourceCommit: {
283
- committedDate: '2021-08-18T16:11:38Z',
284
- sha: 'mySha',
285
- message: 'My original commit message',
286
- },
287
- sourceBranch: '7.x',
288
- expectedTargetPullRequests: [],
289
- },
290
- ],
291
- targetBranch: '6.x',
292
- });
293
- scope.done();
294
- nock_1.default.cleanAll();
295
- });
296
- it('creates the pull request with commit reference', () => {
297
- expect(createPullRequestCalls).toMatchInlineSnapshot(`
298
- Array [
299
- Object {
300
- "base": "6.x",
301
- "body": "# Backport
302
-
303
- This will backport the following commits from \`7.x\` to \`6.x\`:
304
- - My original commit message (mySha)
305
-
306
- <!--- Backport version: 1.2.3-mocked -->
307
-
308
- ### Questions ?
309
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
310
- "head": "sqren:backport/6.x/commit-mySha",
311
- "title": "[6.x] My original commit message",
312
- },
313
- ]
314
- `);
315
- });
316
- it('returns the expected response', () => {
317
- expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
318
- });
319
- });
320
- });
@@ -1,2 +0,0 @@
1
- import { ValidConfigOptions } from '../options/options';
2
- export declare function getCommits(options: ValidConfigOptions): Promise<import("../entrypoint.module").Commit[]>;
@@ -1,75 +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.getCommits = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const BackportError_1 = require("../services/BackportError");
9
- const commitFormatters_1 = require("../services/github/commitFormatters");
10
- const fetchCommitByPullNumber_1 = require("../services/github/v4/fetchCommits/fetchCommitByPullNumber");
11
- const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
12
- const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
13
- const fetchPullRequestsBySearchQuery_1 = require("../services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery");
14
- const prompts_1 = require("../services/prompts");
15
- const ora_1 = require("./ora");
16
- function getOraPersistsOption(question, answer) {
17
- return {
18
- symbol: chalk_1.default.green('?'),
19
- text: `${chalk_1.default.bold(question)} ${chalk_1.default.cyan(answer)}`,
20
- };
21
- }
22
- async function getCommits(options) {
23
- const spinner = (0, ora_1.ora)(options.ci).start();
24
- try {
25
- if (options.sha) {
26
- const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
27
- // TODO: use Intl.ListFormat to format the sha's
28
- spinner.text = `Loading commit "${shas.map(commitFormatters_1.getShortSha)}"`;
29
- const commits = await Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
30
- spinner.stopAndPersist(getOraPersistsOption('Select commit', commits.map((commit) => commit.sourceCommit.message).join(', ')));
31
- return commits;
32
- }
33
- if (options.pullNumber) {
34
- spinner.text = `Loading pull request #${options.pullNumber}`;
35
- const commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
36
- ...options,
37
- pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
38
- });
39
- // add styles to make it look like a prompt question
40
- spinner.stopAndPersist(getOraPersistsOption('Select pull request', (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message)));
41
- return [commit];
42
- }
43
- if (options.ci && !options.ls) {
44
- throw new BackportError_1.BackportError('When "--ci" flag is enabled either `--sha` or `--pr` must be specified');
45
- }
46
- spinner.text = options.prFilter
47
- ? 'Loading pull requests...'
48
- : `Loading commits from branch "${options.sourceBranch}"...`;
49
- const commitChoices = options.prFilter
50
- ? await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)({
51
- ...options,
52
- prFilter: options.prFilter,
53
- })
54
- : await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
55
- spinner.stop();
56
- if (options.ls) {
57
- return commitChoices;
58
- }
59
- return (0, prompts_1.promptForCommits)({
60
- commitChoices,
61
- isMultipleChoice: options.multipleCommits,
62
- showDetails: options.details,
63
- });
64
- }
65
- catch (e) {
66
- if (options.ls) {
67
- spinner.stop();
68
- }
69
- else {
70
- spinner.fail();
71
- }
72
- throw e;
73
- }
74
- }
75
- exports.getCommits = getCommits;
@@ -1,11 +0,0 @@
1
- import { Commit } from '../entrypoint.module';
2
- import { ValidConfigOptions } from '../options/options';
3
- export declare function getCommitsWithoutBackports({ options, commit, targetBranch, conflictingFiles, }: {
4
- options: ValidConfigOptions;
5
- commit: Commit;
6
- targetBranch: string;
7
- conflictingFiles: string[];
8
- }): Promise<{
9
- formatted: string;
10
- commit: Commit;
11
- }[]>;
@@ -1,68 +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.getCommitsWithoutBackports = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const git_1 = require("../services/git");
9
- const commitFormatters_1 = require("../services/github/commitFormatters");
10
- const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
11
- // when the user is facing a git conflict we should help them understand
12
- // why the conflict occurs. In many cases it's because one or more commits haven't been backported yet
13
- async function getCommitsWithoutBackports({ options,
14
- // commit that is being backported
15
- commit,
16
- // branch the commit is being backported to
17
- targetBranch,
18
- // the files with conflicts on the target branch
19
- conflictingFiles, }) {
20
- // commits on the source branch that also touched the conflicting files
21
- const commitsInConflictingPaths = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
22
- ...options,
23
- author: null,
24
- dateSince: null,
25
- dateUntil: commit.sourceCommit.committedDate,
26
- commitPaths: conflictingFiles,
27
- });
28
- const promises = await Promise.all(commitsInConflictingPaths
29
- .filter((c) => {
30
- // exclude the commit we are currently trying to backport
31
- if (c.sourceCommit.sha === commit.sourceCommit.sha) {
32
- return false;
33
- }
34
- // exclude commits that are newer than the commit we are trying to backport
35
- if (c.sourceCommit.committedDate > commit.sourceCommit.committedDate) {
36
- return false;
37
- }
38
- // only consider commits that have an associated pull request
39
- if (!c.sourcePullRequest?.url) {
40
- return false;
41
- }
42
- // only include commit if it has an unmerged PR for the given target branch
43
- const hasUnmergedPr = c.expectedTargetPullRequests.some((pr) => pr.branch === targetBranch && pr.state !== 'MERGED');
44
- return hasUnmergedPr;
45
- })
46
- .slice(0, 10) // limit to max 10 commits
47
- .map(async (c) => {
48
- const results = await Promise.all(c.expectedTargetPullRequests.map(async (targetPr) => {
49
- if (!targetPr.mergeCommit) {
50
- return false;
51
- }
52
- return (0, git_1.getIsCommitInBranch)(options, targetPr.mergeCommit.sha);
53
- }));
54
- const isCommitInBranch = results.some((inBranch) => inBranch === true);
55
- return { c, isCommitInBranch };
56
- }));
57
- return promises
58
- .filter(({ isCommitInBranch }) => !isCommitInBranch)
59
- .map(({ c }) => {
60
- // get pull request for the target branch (if it exists)
61
- const pendingBackportPr = c.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
62
- const formatted = pendingBackportPr
63
- ? ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.gray('(backport pending)')}\n ${pendingBackportPr.url}`
64
- : ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.red('(backport missing)')}\n ${c.sourcePullRequest?.url}`;
65
- return { formatted, commit: c };
66
- });
67
- }
68
- exports.getCommitsWithoutBackports = getCommitsWithoutBackports;
@@ -1 +0,0 @@
1
- export {};