backport 5.6.4 → 6.1.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 (253) hide show
  1. package/README.md +166 -41
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +33 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +56 -39
  12. package/dist/options/cliArgs.d.ts +38 -45
  13. package/dist/options/cliArgs.js +123 -104
  14. package/dist/options/cliArgs.test.js +106 -119
  15. package/dist/options/config/config.d.ts +56 -2
  16. package/dist/options/config/config.js +12 -6
  17. package/dist/options/config/config.test.js +11 -6
  18. package/dist/options/config/getOptionsFromGit.d.ts +4 -0
  19. package/dist/options/config/getOptionsFromGit.js +8 -0
  20. package/dist/options/config/globalConfig.d.ts +2 -1
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -1
  24. package/dist/options/config/projectConfig.js +3 -3
  25. package/dist/options/config/projectConfig.test.js +54 -17
  26. package/dist/options/config/readConfigFile.d.ts +53 -2
  27. package/dist/options/config/readConfigFile.js +31 -5
  28. package/dist/options/options.d.ts +67 -35
  29. package/dist/options/options.js +99 -16
  30. package/dist/options/options.test.js +214 -67
  31. package/dist/options/parseRequiredOptions.d.ts +71 -0
  32. package/dist/options/parseRequiredOptions.js +68 -0
  33. package/dist/options/parseRequiredOptions.test.d.ts +1 -0
  34. package/dist/options/parseRequiredOptions.test.js +122 -0
  35. package/dist/runSequentially.d.ts +20 -0
  36. package/dist/runSequentially.js +41 -0
  37. package/dist/runSequentially.test.d.ts +1 -0
  38. package/dist/runSequentially.test.js +192 -0
  39. package/dist/runWithOptions.js +7 -14
  40. package/dist/runWithOptions.test.js +142 -16
  41. package/dist/scripts/generate-gql.d.ts +1 -0
  42. package/dist/scripts/generate-gql.js +15 -0
  43. package/dist/scripts/postinstall.js +4 -4
  44. package/dist/scripts/postinstall.test.js +9 -2
  45. package/dist/scripts/runPostinstall.js +1 -1
  46. package/dist/services/HandledError.d.ts +11 -1
  47. package/dist/services/HandledError.js +2 -1
  48. package/dist/services/child-process-promisified.d.ts +1 -1
  49. package/dist/services/child-process-promisified.js +2 -2
  50. package/dist/services/env.js +5 -5
  51. package/dist/services/env.test.js +11 -4
  52. package/dist/services/fs-promisified.js +4 -4
  53. package/dist/services/getExpectedTarget.d.ts +9 -0
  54. package/dist/services/getExpectedTarget.js +77 -0
  55. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  56. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  57. package/dist/services/git.d.ts +23 -5
  58. package/dist/services/git.integration.test.d.ts +1 -0
  59. package/dist/services/git.integration.test.js +168 -0
  60. package/dist/services/git.js +133 -60
  61. package/dist/services/git.test.js +160 -53
  62. package/dist/services/github/commitFormatters.d.ts +3 -7
  63. package/dist/services/github/commitFormatters.js +10 -19
  64. package/dist/services/github/commitFormatters.test.js +2 -24
  65. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  66. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  67. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  68. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  69. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  70. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  71. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  72. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  73. package/dist/services/github/v3/createPullRequest.js +32 -26
  74. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  75. package/dist/services/github/v3/createPullRequest.test.js +78 -0
  76. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  77. package/dist/services/github/v3/createStatusComment.js +97 -0
  78. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  79. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  80. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  81. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  82. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  83. package/dist/services/github/v4/apiRequestV4.js +9 -11
  84. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  85. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
  86. package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
  87. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
  88. package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
  89. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  91. package/dist/services/github/v4/fetchAuthorId.d.ts +10 -2
  92. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  93. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  94. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  95. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
  96. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  97. package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
  98. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  110. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  114. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  115. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  119. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  120. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  121. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  122. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
  123. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  124. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
  125. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  126. package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
  127. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  128. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
  129. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
  130. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
  131. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
  132. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
  133. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
  134. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
  135. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
  136. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
  137. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
  138. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  139. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  140. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
  141. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
  142. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  143. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  144. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  145. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  146. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  147. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  148. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  149. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  150. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  151. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
  152. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  153. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
  154. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  155. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  156. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  157. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  158. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  159. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  160. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  161. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +63 -0
  162. package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
  163. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
  164. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +147 -0
  165. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +37 -0
  166. package/dist/services/github/v4/getOptionsFromGithub/query.js +47 -0
  167. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  168. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  169. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  170. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  171. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  172. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
  173. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  174. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
  175. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
  176. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  177. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  178. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  179. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  180. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  181. package/dist/services/logger.d.ts +3 -3
  182. package/dist/services/logger.js +24 -24
  183. package/dist/services/prompt.test.d.ts +1 -0
  184. package/dist/services/prompt.test.js +87 -0
  185. package/dist/services/prompts.d.ts +10 -4
  186. package/dist/services/prompts.js +85 -22
  187. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  188. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  189. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  190. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  191. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  192. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  193. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  194. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  195. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  196. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  197. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  198. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  199. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  200. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  201. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  202. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  203. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  204. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  205. package/dist/services/sourceCommit.d.ts +78 -0
  206. package/dist/services/sourceCommit.js +86 -0
  207. package/dist/services/sourceCommit.test.d.ts +1 -0
  208. package/dist/services/sourceCommit.test.js +280 -0
  209. package/dist/test/inquirer.private.test.js +105 -61
  210. package/dist/test/integration/createSpies.d.ts +1 -1
  211. package/dist/test/integration/createSpies.js +21 -9
  212. package/dist/test/integration/envConstants.js +5 -6
  213. package/dist/test/integration/helpers.js +1 -1
  214. package/dist/test/integration/integration.private.test.d.ts +1 -0
  215. package/dist/test/integration/integration.private.test.js +317 -0
  216. package/dist/test/integration/integration.test.js +30 -31
  217. package/dist/test/mockConfigFiles.d.ts +5 -0
  218. package/dist/test/mockConfigFiles.js +37 -0
  219. package/dist/test/nockHelpers.d.ts +3 -3
  220. package/dist/test/nockHelpers.js +7 -11
  221. package/dist/test/private/getDevAccessToken.js +1 -1
  222. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  223. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  224. package/dist/types/Commit.d.ts +85 -0
  225. package/dist/types/Commit.js +139 -0
  226. package/dist/types/commitNode.d.ts +89 -0
  227. package/dist/types/commitNode.js +139 -0
  228. package/dist/types/commitNode.test.d.ts +1 -0
  229. package/dist/types/commitNode.test.js +255 -0
  230. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  231. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  232. package/dist/ui/cherrypickAndCreatePullRequest.test.js +333 -76
  233. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  234. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
  235. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  236. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  237. package/dist/ui/getCommits.d.ts +1 -1
  238. package/dist/ui/getCommits.js +55 -25
  239. package/dist/ui/getTargetBranches.d.ts +3 -2
  240. package/dist/ui/getTargetBranches.js +33 -18
  241. package/dist/ui/getTargetBranches.test.js +75 -99
  242. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  243. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  244. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  245. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  246. package/dist/ui/maybeSetupRepo.js +11 -10
  247. package/dist/ui/maybeSetupRepo.test.js +54 -4
  248. package/dist/utils/excludeUndefined.d.ts +6 -0
  249. package/dist/utils/excludeUndefined.js +7 -0
  250. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  251. package/dist/utils/excludeUndefined.test.js +24 -0
  252. package/package.json +37 -51
  253. package/yarn.lock +2416 -2987
@@ -24,119 +24,266 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const nock_1 = __importDefault(require("nock"));
26
26
  const logger = __importStar(require("../services/logger"));
27
+ const mockConfigFiles_1 = require("../test/mockConfigFiles");
27
28
  const nockHelpers_1 = require("../test/nockHelpers");
28
29
  const options_1 = require("./options");
29
- function mockGetDefaultRepoBranch({ defaultBranch, refName, }) {
30
- return nockHelpers_1.mockGqlRequest({
31
- name: 'DefaultRepoBranch',
30
+ jest.unmock('../services/fs-promisified');
31
+ function mockGithubConfigOptions({ viewerLogin = 'sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', refName, historicalMappings = [], }) {
32
+ return (0, nockHelpers_1.mockGqlRequest)({
33
+ name: 'GithubConfigOptions',
32
34
  statusCode: 200,
33
35
  body: {
34
36
  data: {
37
+ viewer: {
38
+ login: viewerLogin,
39
+ },
35
40
  repository: {
36
- ref: { name: refName },
37
- defaultBranchRef: { name: defaultBranch },
41
+ isFork: false,
42
+ parent: null,
43
+ ref: refName ? { name: refName } : null,
44
+ defaultBranchRef: {
45
+ name: defaultBranchRef,
46
+ target: {
47
+ history: {
48
+ edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
49
+ return {
50
+ remoteConfig: {
51
+ committedDate,
52
+ file: {
53
+ object: {
54
+ text: JSON.stringify({
55
+ branchLabelMapping,
56
+ }),
57
+ },
58
+ },
59
+ },
60
+ };
61
+ }),
62
+ },
63
+ },
64
+ },
38
65
  },
39
66
  },
40
67
  },
41
68
  });
42
69
  }
43
- describe('getOptions', () => {
44
- const defaultArgs = [
45
- '--branch',
46
- '6.0',
47
- '--branch',
48
- '6.1',
49
- '--upstream',
50
- 'elastic/kibana',
70
+ const defaultConfigs = {
71
+ projectConfig: {
51
72
  // use localhost to avoid CORS issues with nock
52
- '--github-api-base-url-v4',
53
- 'http://localhost/graphql',
54
- ];
73
+ githubApiBaseUrlV4: 'http://localhost/graphql',
74
+ repoOwner: 'elastic',
75
+ repoName: 'kibana',
76
+ targetBranchChoices: ['7.9', '8.0'],
77
+ },
78
+ globalConfig: { accessToken: 'abc', editor: 'code' },
79
+ };
80
+ describe('getOptions', () => {
55
81
  afterEach(() => {
56
82
  jest.clearAllMocks();
57
83
  nock_1.default.cleanAll();
58
84
  });
59
- it('should use the default repository branch as sourceBranch', async () => {
60
- const mockCalls = mockGetDefaultRepoBranch({
61
- defaultBranch: 'my-default-branch',
85
+ beforeEach(() => {
86
+ (0, mockConfigFiles_1.mockConfigFiles)(defaultConfigs);
87
+ });
88
+ describe('should throw', () => {
89
+ beforeEach(() => {
90
+ mockGithubConfigOptions({});
91
+ });
92
+ it('when accessToken is missing', async () => {
93
+ (0, mockConfigFiles_1.mockConfigFiles)({
94
+ projectConfig: defaultConfigs.projectConfig,
95
+ globalConfig: { accessToken: undefined },
96
+ });
97
+ await expect(() => (0, options_1.getOptions)([])).rejects
98
+ .toThrowErrorMatchingInlineSnapshot(`
99
+ "Please update your config file: /Users/sqren/.backport/config.json.
100
+ It must contain a valid \\"accessToken\\".
101
+
102
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
103
+ `);
104
+ });
105
+ it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
106
+ (0, mockConfigFiles_1.mockConfigFiles)({
107
+ projectConfig: {
108
+ ...defaultConfigs.projectConfig,
109
+ targetBranchChoices: undefined,
110
+ branchLabelMapping: undefined,
111
+ },
112
+ globalConfig: { accessToken: 'abc' },
113
+ });
114
+ await expect(() => (0, options_1.getOptions)([])).rejects
115
+ .toThrowErrorMatchingInlineSnapshot(`
116
+ "Please specify a target branch: \\"--branch 6.1\\".
117
+
118
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
119
+ `);
120
+ });
121
+ it('when repoName is missing', async () => {
122
+ (0, mockConfigFiles_1.mockConfigFiles)({
123
+ projectConfig: {
124
+ ...defaultConfigs.projectConfig,
125
+ repoName: '',
126
+ },
127
+ globalConfig: { accessToken: 'abc' },
128
+ });
129
+ await expect(() => (0, options_1.getOptions)([])).rejects
130
+ .toThrowErrorMatchingInlineSnapshot(`
131
+ "Please specify a repo name: \\"--repo-name kibana\\".
132
+
133
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
134
+ `);
135
+ });
136
+ it('when repoOwner is missing', async () => {
137
+ (0, mockConfigFiles_1.mockConfigFiles)({
138
+ projectConfig: {
139
+ ...defaultConfigs.projectConfig,
140
+ repoOwner: '',
141
+ },
142
+ globalConfig: { accessToken: 'abc' },
143
+ });
144
+ await expect(() => (0, options_1.getOptions)([])).rejects
145
+ .toThrowErrorMatchingInlineSnapshot(`
146
+ "Please specify a repo owner: \\"--repo-owner elastic\\".
147
+
148
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
149
+ `);
62
150
  });
63
- const options = await options_1.getOptions(defaultArgs);
64
- expect(mockCalls.length).toBe(1);
65
- expect(options.sourceBranch).toBe('my-default-branch');
66
151
  });
67
- it('should use explicit sourceBranch instead of defaultBranch', async () => {
68
- const argv = [
69
- '--branch',
70
- '6.0',
71
- '--branch',
72
- '6.1',
73
- '--upstream',
74
- 'elastic/kibana',
75
- '--source-branch',
76
- 'my-source-branch',
77
- '--github-api-base-url-v4',
78
- 'http://localhost/graphql',
79
- ];
80
- mockGetDefaultRepoBranch({ defaultBranch: 'my-default-branch' });
81
- const options = await options_1.getOptions(argv);
82
- expect(options.sourceBranch).toBe('my-source-branch');
152
+ describe('sourceBranch', () => {
153
+ beforeEach(() => {
154
+ mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
155
+ });
156
+ it('uses the `defaultBranchRef` as default', async () => {
157
+ const options = await (0, options_1.getOptions)([]);
158
+ expect(options.sourceBranch).toBe('some-default-branch');
159
+ });
160
+ it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
161
+ const options = await (0, options_1.getOptions)([
162
+ '--source-branch',
163
+ 'cli-source-branch',
164
+ ]);
165
+ expect(options.sourceBranch).toBe('cli-source-branch');
166
+ });
83
167
  });
84
168
  it('should ensure that "backport" branch does not exist', async () => {
85
- mockGetDefaultRepoBranch({
86
- defaultBranch: 'my-default-branch',
169
+ mockGithubConfigOptions({
87
170
  refName: 'backport',
88
171
  });
89
- await expect(options_1.getOptions(defaultArgs)).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
90
- });
91
- it('should omit upstream', async () => {
92
- mockGetDefaultRepoBranch({ defaultBranch: 'my-default-branch' });
93
- const options = await options_1.getOptions(defaultArgs);
94
- //@ts-expect-error
95
- expect(options.upstream).toBe(undefined);
172
+ await expect((0, options_1.getOptions)([])).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
96
173
  });
97
174
  it('should merge config options and module options', async () => {
98
- mockGetDefaultRepoBranch({ defaultBranch: 'my-default-branch' });
175
+ mockGithubConfigOptions({});
99
176
  const myFn = async () => true;
100
- const options = await options_1.getOptions(defaultArgs, { autoFixConflicts: myFn });
177
+ const options = await (0, options_1.getOptions)([], { autoFixConflicts: myFn });
101
178
  expect(options.autoFixConflicts).toBe(myFn);
102
179
  });
103
180
  it('should call updateLogger', async () => {
104
- mockGetDefaultRepoBranch({ defaultBranch: 'my-default-branch' });
105
- await options_1.getOptions(defaultArgs);
181
+ mockGithubConfigOptions({});
182
+ await (0, options_1.getOptions)([]);
106
183
  expect(logger.updateLogger).toHaveBeenCalledTimes(1);
107
184
  });
108
185
  it('should return options', async () => {
109
- mockGetDefaultRepoBranch({ defaultBranch: 'some-branch-name' });
110
- const options = await options_1.getOptions(defaultArgs);
186
+ mockGithubConfigOptions({
187
+ defaultBranchRef: 'default-branch-from-github',
188
+ historicalMappings: [
189
+ {
190
+ committedDate: '2022-01-02T20:52:45.173Z',
191
+ branchLabelMapping: { foo: 'bar' },
192
+ },
193
+ ],
194
+ });
195
+ const options = await (0, options_1.getOptions)([]);
111
196
  expect(options).toEqual({
112
- accessToken: 'myAccessToken',
113
- all: false,
114
- author: 'sqren',
197
+ accessToken: 'abc',
115
198
  assignees: [],
199
+ autoAssign: false,
200
+ autoMerge: false,
201
+ autoMergeMethod: 'merge',
202
+ authenticatedUsername: 'sqren',
203
+ branchLabelMapping: {
204
+ foo: 'bar',
205
+ },
206
+ cherrypickRef: true,
116
207
  ci: false,
117
- dryRun: false,
208
+ commitPaths: [],
209
+ details: false,
210
+ editor: 'code',
118
211
  fork: true,
119
- gitHostname: 'github.com',
120
- githubApiBaseUrlV3: 'https://api.github.com',
121
212
  githubApiBaseUrlV4: 'http://localhost/graphql',
213
+ historicalBranchLabelMappings: [
214
+ {
215
+ branchLabelMapping: { foo: 'bar' },
216
+ committedDate: '2022-01-02T20:52:45.173Z',
217
+ },
218
+ ],
219
+ mainline: 1,
122
220
  maxNumber: 10,
123
221
  multipleBranches: true,
124
222
  multipleCommits: false,
125
223
  noVerify: true,
126
- prTitle: '[{targetBranch}] {commitMessages}',
127
224
  repoName: 'kibana',
128
225
  repoOwner: 'elastic',
129
226
  resetAuthor: false,
130
- sourceBranch: 'some-branch-name',
227
+ reviewers: [],
228
+ sourceBranch: 'default-branch-from-github',
131
229
  sourcePRLabels: [],
132
- targetBranchChoices: [
133
- { checked: false, name: '6.0' },
134
- { checked: false, name: '5.9' },
135
- ],
136
- targetBranches: ['6.0', '6.1'],
230
+ targetBranchChoices: ['7.9', '8.0'],
231
+ targetBranches: [],
137
232
  targetPRLabels: [],
138
- username: 'sqren',
233
+ author: 'sqren',
139
234
  verbose: false,
140
235
  });
141
236
  });
237
+ describe('author', () => {
238
+ beforeEach(() => {
239
+ mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
240
+ });
241
+ it('defaults to authenticated user', async () => {
242
+ const { author } = await (0, options_1.getOptions)([]);
243
+ expect(author).toBe('billy.bob');
244
+ });
245
+ it('can be overridden via cli args', async () => {
246
+ const { author } = await (0, options_1.getOptions)(['--author', 'john.doe']);
247
+ expect(author).toBe('john.doe');
248
+ });
249
+ it('can be overridden via config file', async () => {
250
+ (0, mockConfigFiles_1.mockConfigFiles)({
251
+ globalConfig: { accessToken: 'abc' },
252
+ projectConfig: {
253
+ author: 'jane.doe',
254
+ githubApiBaseUrlV4: 'http://localhost/graphql',
255
+ targetBranchChoices: ['7.9', '8.0'],
256
+ repoName: 'foo',
257
+ repoOwner: 'bar',
258
+ },
259
+ });
260
+ const { author } = await (0, options_1.getOptions)([]);
261
+ expect(author).toBe('jane.doe');
262
+ });
263
+ });
264
+ describe('cherrypickRef', () => {
265
+ beforeEach(() => {
266
+ mockGithubConfigOptions({});
267
+ });
268
+ it('should default to true', async () => {
269
+ const { cherrypickRef } = await (0, options_1.getOptions)([]);
270
+ expect(cherrypickRef).toBe(true);
271
+ });
272
+ it('should negate with `noCherrypickRef` cli arg', async () => {
273
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref']);
274
+ expect(cherrypickRef).toBe(false);
275
+ });
276
+ it('should be settable via config file', async () => {
277
+ const { cherrypickRef } = await (0, options_1.getOptions)([], {
278
+ cherrypickRef: false,
279
+ });
280
+ expect(cherrypickRef).toBe(false);
281
+ });
282
+ it('cli args overwrites config', async () => {
283
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref'], {
284
+ cherrypickRef: false,
285
+ });
286
+ expect(cherrypickRef).toBe(true);
287
+ });
288
+ });
142
289
  });
@@ -0,0 +1,71 @@
1
+ import { OptionsFromGithub } from '../services/github/v4/getOptionsFromGithub';
2
+ import { TargetBranchChoiceOrString, TargetBranchChoice, ConfigFileOptions } from './ConfigOptions';
3
+ import { OptionsFromCliArgs } from './cliArgs';
4
+ import { OptionsFromConfigFiles } from './config/config';
5
+ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFromConfigFiles, optionsFromCliArgs: OptionsFromCliArgs, optionsFromGithub: OptionsFromGithub): {
6
+ targetBranchChoices: TargetBranchChoice[];
7
+ accessToken: string;
8
+ username: string;
9
+ repoName: string;
10
+ repoOwner: string;
11
+ assignees: string[];
12
+ author: string;
13
+ all: boolean;
14
+ multipleBranches: boolean;
15
+ multipleCommits: boolean;
16
+ commitPaths: string[];
17
+ reviewers: string[];
18
+ sourcePRLabels: (string[] | undefined) & (string[] | never[]);
19
+ targetBranches: (string[] | undefined) & (string[] | never[]);
20
+ targetPRLabels: (string[] | undefined) & (string[] | never[]);
21
+ cherrypickRef: boolean;
22
+ fork: boolean;
23
+ noVerify: boolean;
24
+ autoAssign: boolean;
25
+ autoMerge: boolean;
26
+ autoMergeMethod: string;
27
+ ci: boolean;
28
+ details: boolean;
29
+ editor: string | undefined;
30
+ forceLocalConfig: boolean | undefined;
31
+ gitHostname: string;
32
+ githubApiBaseUrlV3: string;
33
+ githubApiBaseUrlV4: string;
34
+ mainline: number | undefined;
35
+ maxNumber: number;
36
+ prDescription: string | undefined;
37
+ prTitle: string;
38
+ prFilter: string | undefined;
39
+ pullNumber: number | undefined;
40
+ resetAuthor: boolean;
41
+ sha: string | undefined;
42
+ sourceBranch: string;
43
+ verbose: boolean;
44
+ autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
45
+ files: string[];
46
+ directory: string;
47
+ logger: {
48
+ error: (message: string, meta?: unknown) => void;
49
+ warn: (message: string, meta?: unknown) => void;
50
+ info: (message: string, meta?: unknown) => void;
51
+ verbose: (message: string, meta?: unknown) => void;
52
+ debug: (message: string, meta?: unknown) => void;
53
+ };
54
+ targetBranch: string;
55
+ }) => boolean | Promise<boolean>) | undefined;
56
+ multiple?: boolean | undefined;
57
+ branchLabelMapping?: Record<string, string> | undefined;
58
+ upstream?: string | undefined;
59
+ branches?: TargetBranchChoiceOrString[] | undefined;
60
+ labels?: string[] | undefined;
61
+ historicalBranchLabelMappings: {
62
+ branchLabelMapping: Record<string, string>;
63
+ committedDate: string;
64
+ }[];
65
+ };
66
+ export declare function getRequiredOptions({ accessToken, username, repoName, repoOwner, }: ConfigFileOptions): {
67
+ accessToken: string;
68
+ username: string;
69
+ repoOwner: string;
70
+ repoName: string;
71
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRequiredOptions = exports.parseRequiredOptions = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const HandledError_1 = require("../services/HandledError");
6
+ const env_1 = require("../services/env");
7
+ const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/e119d71d6dc03cd061f6ad9b9a8b1cd995f98961/docs/configuration.md#project-config-backportrcjson';
8
+ const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/e119d71d6dc03cd061f6ad9b9a8b1cd995f98961/docs/configuration.md#global-config-backportconfigjson';
9
+ function parseRequiredOptions(optionsFromConfigFiles, optionsFromCliArgs, optionsFromGithub) {
10
+ const options = {
11
+ // local config files have lowest precedence
12
+ ...optionsFromConfigFiles,
13
+ // remote config options override local config options
14
+ ...optionsFromGithub,
15
+ // cli args override both of the above
16
+ ...optionsFromCliArgs,
17
+ };
18
+ // ensure `targetBranches` or `targetBranchChoices` are given
19
+ if ((0, lodash_1.isEmpty)(options.targetBranches) &&
20
+ (0, lodash_1.isEmpty)(options.targetBranchChoices) &&
21
+ // this is primarily necessary on CI where `targetBranches` and `targetBranchChoices` and not given
22
+ (0, lodash_1.isEmpty)(options.branchLabelMapping)) {
23
+ throw new HandledError_1.HandledError(`You must specify a target branch\n\nYou can specify it via either:\n - Config file (recommended): ".backportrc.json". Read more: ${PROJECT_CONFIG_DOCS_LINK}\n - CLI: "--branch 6.1"`);
24
+ }
25
+ const { accessToken, username, repoName, repoOwner } = getRequiredOptions(options);
26
+ return {
27
+ ...options,
28
+ // convert from array of primitives to array of object
29
+ targetBranchChoices: getTargetBranchChoicesAsObject(options.targetBranchChoices),
30
+ // required options
31
+ accessToken,
32
+ username,
33
+ repoName,
34
+ repoOwner,
35
+ // auto-assign the current user or default to the specified assignees
36
+ assignees: options.autoAssign && options.username
37
+ ? [options.username]
38
+ : options.assignees,
39
+ author: options.author || username,
40
+ all: options.author ? false : options.all,
41
+ };
42
+ }
43
+ exports.parseRequiredOptions = parseRequiredOptions;
44
+ // `branches` can either be a string or an object.
45
+ // It must be transformed so it is always treated as an object troughout the application
46
+ function getTargetBranchChoicesAsObject(targetBranchChoices) {
47
+ return targetBranchChoices.map((choice) => {
48
+ if ((0, lodash_1.isString)(choice)) {
49
+ return {
50
+ name: choice,
51
+ checked: false,
52
+ };
53
+ }
54
+ return choice;
55
+ });
56
+ }
57
+ function getRequiredOptions({ accessToken, username, repoName, repoOwner, }) {
58
+ // accessToken and username must be supplied in config or via cli args
59
+ if (!accessToken || !username) {
60
+ const globalConfigPath = (0, env_1.getGlobalConfigPath)();
61
+ throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "username" and "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
62
+ }
63
+ if (!repoOwner || !repoName) {
64
+ throw new HandledError_1.HandledError(`You must specify a valid Github repository\n\nYou can specify it via either:\n - Config file (recommended): ".backportrc.json". Read more: ${PROJECT_CONFIG_DOCS_LINK}\n - CLI: "--repo-owner elastic --repo-name kibana"`);
65
+ }
66
+ return { accessToken, username, repoOwner, repoName };
67
+ }
68
+ exports.getRequiredOptions = getRequiredOptions;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,122 @@
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
+ const os_1 = __importDefault(require("os"));
7
+ const config_1 = require("./config/config");
8
+ const parseRequiredOptions_1 = require("./parseRequiredOptions");
9
+ describe('parseRequiredOptions', () => {
10
+ beforeEach(() => {
11
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
12
+ });
13
+ const optionsFromConfigFiles = {
14
+ ...config_1.defaultConfigOptions,
15
+ accessToken: 'myAccessToken',
16
+ username: 'sqren',
17
+ repoOwner: 'elastic',
18
+ repoName: 'kibana',
19
+ targetBranches: ['branchA', 'branchB'],
20
+ };
21
+ const optionsFromCliArgs = {};
22
+ const optionsFromGithub = {
23
+ sourceBranch: 'source-branch-from-github',
24
+ };
25
+ describe('should not throw', () => {
26
+ it('when all options are valid and `branches` is given', () => {
27
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)(optionsFromConfigFiles, optionsFromCliArgs, optionsFromGithub)).not.toThrow();
28
+ });
29
+ it('when `targetBranchChoices` is given instead of `targetBranches`', () => {
30
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
31
+ ...optionsFromConfigFiles,
32
+ targetBranchChoices: [{ name: 'branchA' }],
33
+ targetBranches: [],
34
+ }, optionsFromCliArgs, optionsFromGithub)).not.toThrow();
35
+ });
36
+ describe('autoAssign/assignees', () => {
37
+ it('should set `assignees` to current user if `autoAssign` is true', () => {
38
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({ ...optionsFromConfigFiles, assignees: ['john'] }, { autoAssign: true }, optionsFromGithub);
39
+ expect(options.assignees).toEqual(['sqren']);
40
+ });
41
+ it('should set `assignees` to specified value if `autoAssign` is false', () => {
42
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({ ...optionsFromConfigFiles, assignees: ['john'] }, { autoAssign: false }, optionsFromGithub);
43
+ expect(options.assignees).toEqual(['john']);
44
+ });
45
+ it('should set `assignees` to empty if neither `assignees` or `autoAssign` is specified', () => {
46
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({ ...optionsFromConfigFiles, assignees: [] }, { autoAssign: false }, optionsFromGithub);
47
+ expect(options.assignees).toEqual([]);
48
+ });
49
+ });
50
+ describe('targetBranchChoices', () => {
51
+ it('should convert primitives', () => {
52
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({
53
+ ...optionsFromConfigFiles,
54
+ targetBranchChoices: ['choice 1', 'choice 2'],
55
+ }, optionsFromCliArgs, optionsFromGithub);
56
+ expect(options.targetBranchChoices).toEqual([
57
+ { name: 'choice 1', checked: false },
58
+ { name: 'choice 2', checked: false },
59
+ ]);
60
+ });
61
+ it('should preserve objects as-is', () => {
62
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({
63
+ ...optionsFromConfigFiles,
64
+ targetBranchChoices: [
65
+ { name: 'choice 1', checked: false },
66
+ { name: 'choice 2', checked: true },
67
+ ],
68
+ }, optionsFromCliArgs, optionsFromGithub);
69
+ expect(options.targetBranchChoices).toEqual([
70
+ { name: 'choice 1', checked: false },
71
+ { name: 'choice 2', checked: true },
72
+ ]);
73
+ });
74
+ });
75
+ });
76
+ describe('should throw', () => {
77
+ it('when accessToken is missing', () => {
78
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
79
+ ...optionsFromConfigFiles,
80
+ accessToken: undefined,
81
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
82
+ });
83
+ it('when accessToken is empty', () => {
84
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
85
+ ...optionsFromConfigFiles,
86
+ accessToken: '',
87
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
88
+ });
89
+ it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', () => {
90
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
91
+ ...optionsFromConfigFiles,
92
+ targetBranchChoices: [],
93
+ targetBranches: [],
94
+ branchLabelMapping: {},
95
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
96
+ });
97
+ it('when repoName is missing', () => {
98
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
99
+ ...optionsFromConfigFiles,
100
+ repoName: undefined,
101
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
102
+ });
103
+ it('when repoOwner is missing', () => {
104
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
105
+ ...optionsFromConfigFiles,
106
+ repoOwner: undefined,
107
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
108
+ });
109
+ it('when username is missing', () => {
110
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
111
+ ...optionsFromConfigFiles,
112
+ username: undefined,
113
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
114
+ });
115
+ it('when username is empty', () => {
116
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
117
+ ...optionsFromConfigFiles,
118
+ username: '',
119
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
120
+ });
121
+ });
122
+ });
@@ -0,0 +1,20 @@
1
+ import { ValidConfigOptions } from './options/options';
2
+ import { HandledError } from './services/HandledError';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
4
+ export declare type Result = {
5
+ status: 'success';
6
+ didUpdate: boolean;
7
+ targetBranch: string;
8
+ pullRequestUrl: string;
9
+ pullRequestNumber: number;
10
+ } | {
11
+ status: 'failure';
12
+ targetBranch: string;
13
+ errorMessage: string;
14
+ error: HandledError;
15
+ };
16
+ export declare function runSequentially({ options, commits, targetBranches, }: {
17
+ options: ValidConfigOptions;
18
+ commits: Commit[];
19
+ targetBranches: string[];
20
+ }): Promise<Result[]>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSequentially = void 0;
4
+ const logger_1 = require("./services/logger");
5
+ const sequentially_1 = require("./services/sequentially");
6
+ const cherrypickAndCreateTargetPullRequest_1 = require("./ui/cherrypickAndCreateTargetPullRequest");
7
+ const maybeSetupRepo_1 = require("./ui/maybeSetupRepo");
8
+ async function runSequentially({ options, commits, targetBranches, }) {
9
+ logger_1.logger.verbose('Backport options', options);
10
+ await (0, maybeSetupRepo_1.maybeSetupRepo)(options);
11
+ const results = [];
12
+ await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
13
+ logger_1.logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
14
+ try {
15
+ const { number, url, didUpdate } = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
16
+ options,
17
+ commits,
18
+ targetBranch,
19
+ });
20
+ results.push({
21
+ targetBranch,
22
+ status: 'success',
23
+ didUpdate,
24
+ pullRequestUrl: url,
25
+ pullRequestNumber: number,
26
+ });
27
+ }
28
+ catch (e) {
29
+ results.push({
30
+ targetBranch,
31
+ status: 'failure',
32
+ errorMessage: e.message,
33
+ error: e,
34
+ });
35
+ (0, logger_1.consoleLog)(e.message);
36
+ }
37
+ });
38
+ // return the results for consumers to programatically read
39
+ return results;
40
+ }
41
+ exports.runSequentially = runSequentially;
@@ -0,0 +1 @@
1
+ export {};