backport 8.3.1 → 8.4.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 (225) hide show
  1. package/README.md +11 -178
  2. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +42 -21
  3. package/dist/lib/child-process-promisified.js +2 -2
  4. package/dist/lib/git.d.ts +4 -3
  5. package/dist/lib/git.js +22 -29
  6. package/dist/lib/git.private.test.js +10 -7
  7. package/dist/lib/git.test.js +47 -15
  8. package/dist/lib/github/v4/apiRequestV4.js +14 -8
  9. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
  10. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  11. package/dist/lib/ora.d.ts +1 -0
  12. package/dist/options/ConfigOptions.d.ts +1 -0
  13. package/dist/options/cliArgs.d.ts +1 -0
  14. package/dist/options/cliArgs.js +5 -0
  15. package/dist/options/config/config.d.ts +1 -0
  16. package/dist/options/config/readConfigFile.d.ts +1 -0
  17. package/dist/options/options.d.ts +2 -0
  18. package/dist/options/options.js +3 -2
  19. package/dist/options/options.test.js +5 -4
  20. package/dist/test/e2e/cli/date-filters.private.test.js +1 -0
  21. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +122 -6
  22. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -0
  23. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +27 -13
  24. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
  25. package/dist/{entrypoint.cli.private.test.d.ts → test/e2e/cli/gracefully-handles-corrupt-repo.private.test.d.ts} +0 -0
  26. package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +52 -0
  27. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
  28. package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/repo-with-programatically-added-commits.mutation.test.d.ts} +0 -0
  29. package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +114 -0
  30. package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
  31. package/dist/test/e2e/cli/runBackportViaCli.js +47 -17
  32. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +7 -1
  33. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
  34. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
  35. package/dist/test/replaceStringAndLinebreaks.d.ts +5 -0
  36. package/dist/test/replaceStringAndLinebreaks.js +8 -0
  37. package/dist/test/sandbox.js +6 -2
  38. package/dist/utils/packageVersion.d.ts +1 -1
  39. package/dist/utils/packageVersion.js +1 -1
  40. package/package.json +23 -24
  41. package/yarn.lock +841 -950
  42. package/dist/entrypoint.cli.private.test.js +0 -47
  43. package/dist/errors/BackportError.d.ts +0 -19
  44. package/dist/errors/BackportError.js +0 -29
  45. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  46. package/dist/runSequentially.test.d.ts +0 -1
  47. package/dist/runSequentially.test.js +0 -243
  48. package/dist/services/BackportError.d.ts +0 -19
  49. package/dist/services/BackportError.js +0 -29
  50. package/dist/services/HandledBackportError.d.ts +0 -19
  51. package/dist/services/HandledBackportError.js +0 -29
  52. package/dist/services/HandledError.d.ts +0 -19
  53. package/dist/services/HandledError.js +0 -29
  54. package/dist/services/child-process-promisified.d.ts +0 -25
  55. package/dist/services/child-process-promisified.js +0 -58
  56. package/dist/services/env.d.ts +0 -7
  57. package/dist/services/env.js +0 -30
  58. package/dist/services/env.test.d.ts +0 -1
  59. package/dist/services/env.test.js +0 -21
  60. package/dist/services/git.d.ts +0 -77
  61. package/dist/services/git.integration.test.d.ts +0 -1
  62. package/dist/services/git.integration.test.js +0 -616
  63. package/dist/services/git.js +0 -439
  64. package/dist/services/git.private.test.d.ts +0 -1
  65. package/dist/services/git.private.test.js +0 -618
  66. package/dist/services/git.test.d.ts +0 -1
  67. package/dist/services/git.test.js +0 -580
  68. package/dist/services/github/commitFormatters.d.ts +0 -3
  69. package/dist/services/github/commitFormatters.js +0 -17
  70. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  71. package/dist/services/github/commitFormatters.test.js +0 -11
  72. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  73. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  74. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  75. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  76. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  77. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  78. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  79. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  80. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  81. package/dist/services/github/v3/createPullRequest.js +0 -91
  82. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  83. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  84. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  85. package/dist/services/github/v3/createStatusComment.js +0 -131
  86. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  87. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  88. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  89. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  90. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  91. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  92. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  93. package/dist/services/github/v4/apiRequestV4.js +0 -71
  94. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  95. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  96. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  97. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  98. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  99. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  100. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  101. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  102. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  103. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  104. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  105. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  106. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  108. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  110. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  111. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  112. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  113. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  114. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  116. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  117. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  118. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  119. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  120. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  121. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  122. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  123. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  124. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  125. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  126. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  127. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  128. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  129. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  130. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  131. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  132. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  133. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  134. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  135. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  136. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  137. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  138. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  139. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  140. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  141. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  142. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  143. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  144. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  145. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  146. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  147. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  148. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  149. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  150. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  151. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  152. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  153. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  154. package/dist/services/logger.d.ts +0 -9
  155. package/dist/services/logger.js +0 -74
  156. package/dist/services/prompt.test.d.ts +0 -1
  157. package/dist/services/prompt.test.js +0 -139
  158. package/dist/services/prompts.d.ts +0 -17
  159. package/dist/services/prompts.js +0 -132
  160. package/dist/services/remoteConfig.d.ts +0 -20
  161. package/dist/services/remoteConfig.js +0 -52
  162. package/dist/services/sequentially.d.ts +0 -1
  163. package/dist/services/sequentially.js +0 -10
  164. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  165. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  166. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  167. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  168. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  169. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  170. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  171. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  172. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  173. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  174. package/dist/services/test.d.ts +0 -1
  175. package/dist/services/test.js +0 -23
  176. package/dist/state.d.ts +0 -0
  177. package/dist/state.js +0 -1
  178. package/dist/test/ExecError.d.ts +0 -16
  179. package/dist/test/ExecError.js +0 -15
  180. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  181. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  182. package/dist/test/e2e/cli/date-filters.d.ts +0 -1
  183. package/dist/test/e2e/cli/date-filters.js +0 -43
  184. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  185. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  186. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  187. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  188. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  189. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  190. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  191. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  192. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  193. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  194. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  195. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  196. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  197. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  199. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  200. package/dist/ui/getCommits.d.ts +0 -2
  201. package/dist/ui/getCommits.js +0 -75
  202. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  203. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  204. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  205. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  206. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  207. package/dist/ui/getGitConfigAuthor.js +0 -15
  208. package/dist/ui/getTargetBranches.d.ts +0 -5
  209. package/dist/ui/getTargetBranches.js +0 -67
  210. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  211. package/dist/ui/getTargetBranches.test.js +0 -204
  212. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  213. package/dist/ui/maybeSetupRepo.js +0 -53
  214. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  215. package/dist/ui/maybeSetupRepo.test.js +0 -238
  216. package/dist/ui/ora.d.ts +0 -2
  217. package/dist/ui/ora.js +0 -21
  218. package/dist/ui/setupRepo.d.ts +0 -2
  219. package/dist/ui/setupRepo.js +0 -56
  220. package/dist/ui/setupRepo.test.d.ts +0 -1
  221. package/dist/ui/setupRepo.test.js +0 -273
  222. package/dist/utils/filterMissingCommits.d.ts +0 -2
  223. package/dist/utils/filterMissingCommits.js +0 -7
  224. package/dist/utils/redact.d.ts +0 -1
  225. package/dist/utils/redact.js +0 -7
@@ -1,335 +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 strip_ansi_1 = __importDefault(require("strip-ansi"));
30
- const git = __importStar(require("../services/git"));
31
- const fetchCommitsByAuthorModule = __importStar(require("../services/github/v4/fetchCommits/fetchCommitsByAuthor"));
32
- const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
33
- describe('getCommitsWithoutBackports', () => {
34
- afterEach(() => {
35
- jest.restoreAllMocks();
36
- });
37
- describe('expectedTargetPullRequests', () => {
38
- function setupExpectedPullRequests({ expectedTargetPullRequests, }) {
39
- // simulate 1 unbackported commit
40
- jest
41
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
42
- .mockResolvedValueOnce([
43
- {
44
- author: {
45
- email: 'soren.louv@elastic.co',
46
- name: 'Søren Louv-Jansen',
47
- },
48
- sourceCommit: {
49
- committedDate: '10',
50
- message: 'First commit (#1)',
51
- sha: 'xyz',
52
- },
53
- sourcePullRequest: {
54
- url: 'https://www.github.com/foo/bar/pull/123',
55
- number: 123,
56
- mergeCommit: {
57
- message: 'First commit (#1)',
58
- sha: 'xyz',
59
- },
60
- },
61
- expectedTargetPullRequests,
62
- sourceBranch: 'main',
63
- },
64
- ]);
65
- // simulate commit is definitely not backported
66
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
67
- return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
68
- options: {},
69
- commit: {
70
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
71
- sourceCommit: {
72
- committedDate: '100',
73
- message: 'Second commit (#2)',
74
- sha: 'abc',
75
- },
76
- expectedTargetPullRequests: [],
77
- sourceBranch: 'main',
78
- },
79
- targetBranch: '7.x',
80
- conflictingFiles: ['/foo/bar/baz.ts'],
81
- });
82
- }
83
- it('should not unbackported commits if no backports were expected', async () => {
84
- const commitsWithoutBackports = await setupExpectedPullRequests({
85
- expectedTargetPullRequests: [],
86
- });
87
- expect(commitsWithoutBackports.length).toEqual(0);
88
- });
89
- it('should display as missing if a backport is CLOSED', async () => {
90
- const commitsWithoutBackports = await setupExpectedPullRequests({
91
- expectedTargetPullRequests: [
92
- {
93
- state: 'CLOSED',
94
- branch: '7.x',
95
- number: 456,
96
- url: 'https://www.github.com/foo/bar/pull/456',
97
- },
98
- ],
99
- });
100
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
101
- });
102
- it('should display as missing if a backport is NOT_CREATED', async () => {
103
- const commitsWithoutBackports = await setupExpectedPullRequests({
104
- expectedTargetPullRequests: [{ state: 'NOT_CREATED', branch: '7.x' }],
105
- });
106
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
107
- });
108
- it('should display as pending if a backport is OPEN', async () => {
109
- const commitsWithoutBackports = await setupExpectedPullRequests({
110
- expectedTargetPullRequests: [
111
- {
112
- state: 'OPEN',
113
- branch: '7.x',
114
- url: 'https://www.github.com/foo/bar/pull/456',
115
- number: 456,
116
- },
117
- ],
118
- });
119
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
120
- });
121
- it('should not display commit as unbackported if a backport was MERGED', async () => {
122
- const commitsWithoutBackports = await setupExpectedPullRequests({
123
- expectedTargetPullRequests: [
124
- {
125
- state: 'MERGED',
126
- branch: '7.x',
127
- number: 456,
128
- url: 'https://www.github.com/foo/bar/pull/456',
129
- },
130
- ],
131
- });
132
- expect(commitsWithoutBackports).toEqual([]);
133
- });
134
- });
135
- describe('commitDate', () => {
136
- function setupCommitDateDiff({ offendingCommitDate, currentCommitDate, }) {
137
- // simulate 1 commit with a pending backport
138
- jest
139
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
140
- .mockResolvedValueOnce([
141
- {
142
- author: {
143
- email: 'soren.louv@elastic.co',
144
- name: 'Søren Louv-Jansen',
145
- },
146
- sourceCommit: {
147
- committedDate: offendingCommitDate,
148
- message: 'First commit (#1)',
149
- sha: 'xyz',
150
- },
151
- sourcePullRequest: {
152
- number: 123,
153
- url: 'https://www.github.com/foo/bar/pull/123',
154
- mergeCommit: {
155
- message: 'First commit (#1)',
156
- sha: 'xyz',
157
- },
158
- },
159
- sourceBranch: 'main',
160
- expectedTargetPullRequests: [
161
- {
162
- state: 'OPEN',
163
- branch: '7.x',
164
- number: 456,
165
- url: 'https://www.github.com/foo/bar/pull/456',
166
- },
167
- ],
168
- },
169
- ]);
170
- // simulate commit is definitely not backported
171
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
172
- return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
173
- options: {},
174
- commit: {
175
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
176
- sourceCommit: {
177
- committedDate: currentCommitDate,
178
- message: 'Second commit (#2)',
179
- sha: 'abc',
180
- },
181
- sourcePullRequest: {
182
- number: 123,
183
- url: 'https://www.github.com/foo/bar/pull/123',
184
- mergeCommit: {
185
- message: 'Second commit (#2)',
186
- sha: 'abc',
187
- },
188
- },
189
- sourceBranch: 'main',
190
- expectedTargetPullRequests: [],
191
- },
192
- targetBranch: '7.x',
193
- conflictingFiles: ['/foo/bar/baz.ts'],
194
- });
195
- }
196
- it('should not display commit as unbackport if is newer than the commit currently being backported', async () => {
197
- const commitsWithoutBackports = await setupCommitDateDiff({
198
- offendingCommitDate: '100',
199
- currentCommitDate: '10',
200
- });
201
- expect(commitsWithoutBackports).toEqual([]);
202
- });
203
- it('should display commit as unbackport if is older than the commit currently being backported', async () => {
204
- const commitsWithoutBackports = await setupCommitDateDiff({
205
- offendingCommitDate: '10',
206
- currentCommitDate: '100',
207
- });
208
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
209
- });
210
- });
211
- describe('targetBranch', () => {
212
- function setupTargetBranchDiff({ offendingCommitTargetBranch, currentCommitTargetBranch, }) {
213
- // return mock commits that also touched the conflicting files
214
- jest
215
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
216
- .mockResolvedValueOnce([
217
- {
218
- author: {
219
- email: 'soren.louv@elastic.co',
220
- name: 'Søren Louv-Jansen',
221
- },
222
- sourceCommit: {
223
- committedDate: '10',
224
- message: 'First commit (#1)',
225
- sha: 'xyz',
226
- },
227
- sourcePullRequest: {
228
- number: 123,
229
- url: 'https://www.github.com/foo/bar/pull/123',
230
- mergeCommit: {
231
- message: 'First commit (#1)',
232
- sha: 'xyz',
233
- },
234
- },
235
- sourceBranch: 'main',
236
- expectedTargetPullRequests: [
237
- {
238
- branch: offendingCommitTargetBranch,
239
- state: 'OPEN',
240
- url: 'https://www.github.com/foo/bar/pull/456',
241
- number: 456,
242
- },
243
- ],
244
- },
245
- ]);
246
- // simulate commit is definitely not backported
247
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
248
- return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
249
- options: {},
250
- // commit that is being backported
251
- commit: {
252
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
253
- sourceCommit: {
254
- committedDate: '100',
255
- message: 'Second commit (#2)',
256
- sha: 'abc',
257
- },
258
- sourcePullRequest: {
259
- url: 'https://www.github.com/foo/bar/pull/123',
260
- number: 123,
261
- mergeCommit: {
262
- message: 'Second commit (#2)',
263
- sha: 'abc',
264
- },
265
- },
266
- expectedTargetPullRequests: [],
267
- sourceBranch: 'main',
268
- },
269
- targetBranch: currentCommitTargetBranch,
270
- conflictingFiles: ['/foo/bar/baz.ts'],
271
- });
272
- }
273
- it('should display backport as pending if target branches match', async () => {
274
- const commitsWithoutBackports = await setupTargetBranchDiff({
275
- offendingCommitTargetBranch: '7.x',
276
- currentCommitTargetBranch: '7.x',
277
- });
278
- expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
279
- });
280
- it("should not display commit if target branches don't match", async () => {
281
- const commitsWithoutBackports = await setupTargetBranchDiff({
282
- offendingCommitTargetBranch: '7.x',
283
- currentCommitTargetBranch: '8.x',
284
- });
285
- expect(commitsWithoutBackports.length).toBe(0);
286
- });
287
- });
288
- describe("when conflicting commit doesn't have an associated pull request", () => {
289
- it('should be ignored', async () => {
290
- jest
291
- .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
292
- .mockResolvedValueOnce([
293
- {
294
- author: {
295
- email: 'soren.louv@elastic.co',
296
- name: 'Søren Louv-Jansen',
297
- },
298
- sourceCommit: {
299
- committedDate: '10',
300
- sha: 'xyz',
301
- message: 'First commit (#1)',
302
- },
303
- expectedTargetPullRequests: [],
304
- sourceBranch: 'main',
305
- },
306
- ]);
307
- // simulate commit is definitely not backported
308
- jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
309
- const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
310
- options: {},
311
- commit: {
312
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
313
- sourceCommit: {
314
- committedDate: '100',
315
- message: 'Second commit (#2)',
316
- sha: 'abc',
317
- },
318
- sourcePullRequest: {
319
- url: 'https://www.github.com/foo/bar/pull/123',
320
- number: 123,
321
- mergeCommit: {
322
- message: 'Second commit (#2)',
323
- sha: 'abc',
324
- },
325
- },
326
- expectedTargetPullRequests: [],
327
- sourceBranch: 'main',
328
- },
329
- targetBranch: '7.x',
330
- conflictingFiles: ['/foo/bar/baz.ts'],
331
- });
332
- expect(commitsWithoutBackports.length).toEqual(0);
333
- });
334
- });
335
- });
@@ -1,6 +0,0 @@
1
- import { ValidConfigOptions } from '../options/options';
2
- export declare type GitConfigAuthor = {
3
- name?: string;
4
- email?: string;
5
- };
6
- export declare function getGitConfigAuthor(options: ValidConfigOptions): Promise<GitConfigAuthor | undefined>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGitConfigAuthor = void 0;
4
- const git_1 = require("../services/git");
5
- async function getGitConfigAuthor(options) {
6
- const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
7
- if (!localRepoPath) {
8
- return;
9
- }
10
- return {
11
- name: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' }),
12
- email: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' }),
13
- };
14
- }
15
- exports.getGitConfigAuthor = getGitConfigAuthor;
@@ -1,5 +0,0 @@
1
- import { TargetBranchChoice } from '../options/ConfigOptions';
2
- import { ValidConfigOptions } from '../options/options';
3
- import { Commit } from '../services/sourceCommit/parseSourceCommit';
4
- export declare function getTargetBranches(options: ValidConfigOptions, commits: Commit[]): string[] | Promise<string[]>;
5
- export declare function getTargetBranchChoices(options: ValidConfigOptions, missingTargetBranches: string[], sourceBranch: string): TargetBranchChoice[];
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTargetBranchChoices = exports.getTargetBranches = void 0;
4
- const lodash_1 = require("lodash");
5
- const BackportError_1 = require("../services/BackportError");
6
- const prompts_1 = require("../services/prompts");
7
- function getTargetBranches(options, commits) {
8
- // target branches already specified (in contrast to letting the user choose from a list)
9
- if (!(0, lodash_1.isEmpty)(options.targetBranches)) {
10
- return options.targetBranches;
11
- }
12
- // target branches from the first commit
13
- const missingTargetBranches = commits.length === 1
14
- ? commits[0].expectedTargetPullRequests
15
- .filter((pr) => pr.state === 'NOT_CREATED' || pr.state === 'CLOSED')
16
- .map((pr) => pr.branch)
17
- : [];
18
- // automatically backport to specified target branches
19
- if (options.ci) {
20
- if ((0, lodash_1.isEmpty)(missingTargetBranches)) {
21
- throw new BackportError_1.BackportError({ code: 'no-branches-exception' });
22
- }
23
- return missingTargetBranches;
24
- }
25
- // sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
26
- // this is specifically needed when backporting a PR like `backport --pr 123` and the source PR was merged to a non-default (aka non-master) branch.
27
- const { sourceBranch } = commits[0];
28
- const targetBranchChoices = getTargetBranchChoices(options, missingTargetBranches, sourceBranch);
29
- // render interactive list of branches
30
- return (0, prompts_1.promptForTargetBranches)({
31
- targetBranchChoices,
32
- isMultipleChoice: options.multipleBranches,
33
- });
34
- }
35
- exports.getTargetBranches = getTargetBranches;
36
- function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
37
- // exclude sourceBranch from targetBranchChoices
38
- const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
39
- if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
40
- throw new BackportError_1.BackportError('Missing target branch choices');
41
- }
42
- if (!options.branchLabelMapping) {
43
- return targetBranchesChoices;
44
- }
45
- // select missing target branches (based on pull request labels)
46
- return targetBranchesChoices.map((choice) => {
47
- const isChecked = missingTargetBranches.includes(choice.name);
48
- return { ...choice, checked: isChecked };
49
- });
50
- }
51
- exports.getTargetBranchChoices = getTargetBranchChoices;
52
- // `targetBranchChoices` can either be a string or an object.
53
- // It must be transformed so it is always treated as an object troughout the application
54
- function getTargetBranchChoicesAsObject(targetBranchChoices) {
55
- if (!targetBranchChoices) {
56
- return [];
57
- }
58
- return targetBranchChoices.map((choice) => {
59
- if ((0, lodash_1.isString)(choice)) {
60
- return {
61
- name: choice,
62
- checked: false,
63
- };
64
- }
65
- return choice;
66
- });
67
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,204 +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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const prompts = __importStar(require("../services/prompts"));
27
- const getTargetBranches_1 = require("./getTargetBranches");
28
- describe('getTargetBranches', () => {
29
- let promptSpy;
30
- beforeEach(() => {
31
- jest.clearAllMocks();
32
- promptSpy = jest
33
- .spyOn(prompts, 'promptForTargetBranches')
34
- .mockResolvedValueOnce(['branchA']);
35
- });
36
- describe('when `options.targetBranches` is empty', () => {
37
- let branches;
38
- beforeEach(async () => {
39
- const options = {
40
- targetBranches: [],
41
- targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
42
- multipleBranches: false,
43
- };
44
- const commits = [
45
- {
46
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
47
- sourceCommit: {
48
- committedDate: 'aaa',
49
- message: 'hey',
50
- sha: 'abcd',
51
- },
52
- sourcePullRequest: {
53
- url: 'foo',
54
- number: 1337,
55
- mergeCommit: {
56
- message: 'hey',
57
- sha: 'abcd',
58
- },
59
- },
60
- sourceBranch: '7.x',
61
- expectedTargetPullRequests: [],
62
- },
63
- ];
64
- branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
65
- });
66
- it('should return branches from prompt', () => {
67
- expect(branches).toEqual(['branchA']);
68
- });
69
- it('should call prompt with correct args', () => {
70
- expect(promptSpy).toHaveBeenLastCalledWith({
71
- targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
72
- isMultipleChoice: false,
73
- });
74
- });
75
- });
76
- describe('when `options.targetBranches` is not empty', () => {
77
- let branches;
78
- beforeEach(() => {
79
- branches = (0, getTargetBranches_1.getTargetBranches)({
80
- targetBranches: ['branchA', 'branchB'],
81
- targetBranchChoices: [],
82
- multipleBranches: false,
83
- }, []);
84
- });
85
- it('should return branches from `options.branches`', () => {
86
- expect(branches).toEqual(['branchA', 'branchB']);
87
- });
88
- it('should not call prompt', () => {
89
- expect(promptSpy).not.toHaveBeenCalled();
90
- });
91
- });
92
- describe('when ci=true', () => {
93
- it('should throw when there are no missing backports', () => {
94
- const commits = [];
95
- expect(() => {
96
- return (0, getTargetBranches_1.getTargetBranches)({
97
- expectedTargetPullRequests: [],
98
- ci: true,
99
- }, commits);
100
- }).toThrow('There are no branches to backport to. Aborting.');
101
- });
102
- it('should return missing backports', () => {
103
- const commits = [
104
- {
105
- expectedTargetPullRequests: [
106
- { branch: '7.2', state: 'MERGED' },
107
- { branch: '7.1', state: 'OPEN' },
108
- { branch: '7.x', state: 'NOT_CREATED' },
109
- ],
110
- },
111
- ];
112
- const targetBranches = (0, getTargetBranches_1.getTargetBranches)({ ci: true }, commits);
113
- expect(targetBranches).toEqual(['7.x']);
114
- });
115
- });
116
- describe('when `expectedTargetPullRequests` is missing a backport to 7.x', () => {
117
- let targetBranchChoices;
118
- beforeEach(async () => {
119
- const options = {
120
- targetBranches: [],
121
- multipleBranches: true,
122
- targetBranchChoices: [
123
- { name: 'master' },
124
- { name: '7.x' },
125
- { name: '7.7' },
126
- { name: '7.6' },
127
- { name: '7.5' },
128
- ],
129
- branchLabelMapping: {},
130
- sourceBranch: 'master',
131
- };
132
- const commits = [
133
- {
134
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
135
- sourceCommit: {
136
- committedDate: 'bbb',
137
- message: '[backport] Bump to 5.1.3 (#62286)',
138
- sha: 'my-sha',
139
- },
140
- sourcePullRequest: {
141
- url: 'foo',
142
- number: 62286,
143
- mergeCommit: {
144
- message: '[backport] Bump to 5.1.3 (#62286)',
145
- sha: 'my-sha',
146
- },
147
- },
148
- sourceBranch: 'master',
149
- expectedTargetPullRequests: [{ branch: '7.x', state: 'NOT_CREATED' }],
150
- },
151
- ];
152
- await (0, getTargetBranches_1.getTargetBranches)(options, commits);
153
- targetBranchChoices = promptSpy.mock.calls[0][0].targetBranchChoices;
154
- });
155
- it('should list the correct branches', async () => {
156
- expect(targetBranchChoices).toEqual([
157
- { checked: true, name: '7.x' },
158
- { checked: false, name: '7.7' },
159
- { checked: false, name: '7.6' },
160
- { checked: false, name: '7.5' },
161
- ]);
162
- });
163
- it('should not list the sourceBranch (master)', async () => {
164
- expect(targetBranchChoices).not.toContainEqual(expect.objectContaining({ name: 'master' }));
165
- });
166
- it('should select 7.x', async () => {
167
- expect(targetBranchChoices).toContainEqual({
168
- name: '7.x',
169
- checked: true,
170
- });
171
- });
172
- });
173
- });
174
- describe('getTargetBranchChoices', () => {
175
- const options = {
176
- ci: false,
177
- targetBranchChoices: [
178
- { name: 'master', checked: true },
179
- { name: '7.x', checked: true },
180
- { name: '7.8', checked: false },
181
- { name: '7.7', checked: false },
182
- ],
183
- branchLabelMapping: {},
184
- };
185
- const sourceBranch = 'master';
186
- it('should not check any branches if no labels match', () => {
187
- const targetBranchesFromLabels = [];
188
- const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
189
- expect(branches).toEqual([
190
- { checked: false, name: '7.x' },
191
- { checked: false, name: '7.8' },
192
- { checked: false, name: '7.7' },
193
- ]);
194
- });
195
- it('should pre-select branches based on labels', () => {
196
- const targetBranchesFromLabels = ['7.7'];
197
- const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
198
- expect(branches).toEqual([
199
- { checked: false, name: '7.x' },
200
- { checked: false, name: '7.8' },
201
- { checked: true, name: '7.7' },
202
- ]);
203
- });
204
- });
@@ -1,2 +0,0 @@
1
- import { ValidConfigOptions } from '../options/options';
2
- export declare function maybeSetupRepo(options: ValidConfigOptions): Promise<void>;