backport 5.6.3 → 6.0.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 (230) hide show
  1. package/README.md +48 -39
  2. package/dist/entrypoint.cli.js +1 -1
  3. package/dist/entrypoint.module.d.ts +6 -5
  4. package/dist/entrypoint.module.js +8 -6
  5. package/dist/ink.d.ts +1 -0
  6. package/dist/ink.js +49 -0
  7. package/dist/main.d.ts +11 -6
  8. package/dist/main.js +40 -24
  9. package/dist/options/ConfigOptions.d.ts +47 -39
  10. package/dist/options/cliArgs.d.ts +28 -34
  11. package/dist/options/cliArgs.js +113 -94
  12. package/dist/options/cliArgs.test.js +103 -119
  13. package/dist/options/config/config.d.ts +81 -2
  14. package/dist/options/config/config.js +46 -6
  15. package/dist/options/config/config.test.js +24 -2
  16. package/dist/options/config/getOptionsFromGit.d.ts +3 -0
  17. package/dist/options/config/getOptionsFromGit.js +10 -0
  18. package/dist/options/config/globalConfig.d.ts +2 -1
  19. package/dist/options/config/globalConfig.js +8 -8
  20. package/dist/options/config/globalConfig.test.js +7 -3
  21. package/dist/options/config/projectConfig.d.ts +2 -1
  22. package/dist/options/config/projectConfig.js +3 -3
  23. package/dist/options/config/projectConfig.test.js +4 -4
  24. package/dist/options/config/readConfigFile.d.ts +2 -2
  25. package/dist/options/config/readConfigFile.js +3 -3
  26. package/dist/options/options.d.ts +40 -27
  27. package/dist/options/options.js +8 -16
  28. package/dist/options/options.test.js +66 -26
  29. package/dist/options/parseRequiredOptions.d.ts +71 -0
  30. package/dist/options/parseRequiredOptions.js +70 -0
  31. package/dist/options/parseRequiredOptions.test.d.ts +1 -0
  32. package/dist/options/parseRequiredOptions.test.js +127 -0
  33. package/dist/runSequentially.d.ts +20 -0
  34. package/dist/runSequentially.js +41 -0
  35. package/dist/runSequentially.test.d.ts +1 -0
  36. package/dist/runSequentially.test.js +235 -0
  37. package/dist/runWithOptions.js +7 -14
  38. package/dist/runWithOptions.test.js +142 -16
  39. package/dist/scripts/generate-gql.d.ts +1 -0
  40. package/dist/scripts/generate-gql.js +15 -0
  41. package/dist/scripts/postinstall.js +4 -4
  42. package/dist/scripts/postinstall.test.js +9 -2
  43. package/dist/scripts/runPostinstall.js +1 -1
  44. package/dist/services/HandledError.d.ts +11 -1
  45. package/dist/services/HandledError.js +2 -1
  46. package/dist/services/child-process-promisified.d.ts +1 -1
  47. package/dist/services/child-process-promisified.js +2 -2
  48. package/dist/services/env.js +5 -5
  49. package/dist/services/env.test.js +11 -4
  50. package/dist/services/fs-promisified.js +4 -4
  51. package/dist/services/getExpectedTarget.d.ts +9 -0
  52. package/dist/services/getExpectedTarget.js +77 -0
  53. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  54. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  55. package/dist/services/git.d.ts +19 -4
  56. package/dist/services/git.integration.test.d.ts +1 -0
  57. package/dist/services/git.integration.test.js +168 -0
  58. package/dist/services/git.js +129 -57
  59. package/dist/services/git.test.js +155 -51
  60. package/dist/services/github/commitFormatters.d.ts +3 -7
  61. package/dist/services/github/commitFormatters.js +10 -19
  62. package/dist/services/github/commitFormatters.test.js +2 -24
  63. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  64. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
  65. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
  66. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  67. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  68. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  69. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  70. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  71. package/dist/services/github/v3/createPullRequest.js +33 -24
  72. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  73. package/dist/services/github/v3/createStatusComment.js +97 -0
  74. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  75. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  76. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  77. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  78. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  79. package/dist/services/github/v4/apiRequestV4.js +8 -10
  80. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  81. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
  82. package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
  83. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
  84. package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
  85. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  86. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +113 -0
  87. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -0
  88. package/dist/services/github/v4/fetchAuthorId.js +1 -1
  89. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
  90. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  91. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
  92. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  93. package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
  94. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  110. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  111. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  112. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  113. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
  114. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  116. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
  117. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  118. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
  119. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  120. package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
  121. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  122. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
  123. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
  124. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
  125. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
  126. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
  127. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
  128. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
  129. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
  130. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
  131. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
  132. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  133. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
  134. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
  135. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
  136. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  137. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  138. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  139. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
  140. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  141. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
  142. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  143. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  144. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  145. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +61 -0
  146. package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
  147. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
  148. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +126 -0
  149. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +34 -0
  150. package/dist/services/github/v4/getOptionsFromGithub/query.js +44 -0
  151. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  152. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  153. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  154. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  155. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  156. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
  157. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  158. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
  159. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
  160. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  161. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  162. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  163. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  164. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  165. package/dist/services/logger.d.ts +3 -3
  166. package/dist/services/logger.js +24 -24
  167. package/dist/services/prompt.test.d.ts +1 -0
  168. package/dist/services/prompt.test.js +87 -0
  169. package/dist/services/prompts.d.ts +10 -4
  170. package/dist/services/prompts.js +85 -22
  171. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  172. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  173. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  174. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  175. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  176. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  177. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  178. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  179. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  180. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  181. package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
  182. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  183. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  184. package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
  185. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  186. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  187. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  188. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  189. package/dist/services/sourceCommit.d.ts +78 -0
  190. package/dist/services/sourceCommit.js +86 -0
  191. package/dist/services/sourceCommit.test.d.ts +1 -0
  192. package/dist/services/sourceCommit.test.js +280 -0
  193. package/dist/test/inquirer.private.test.js +81 -45
  194. package/dist/test/integration/createSpies.d.ts +1 -1
  195. package/dist/test/integration/createSpies.js +21 -9
  196. package/dist/test/integration/envConstants.js +5 -6
  197. package/dist/test/integration/helpers.js +1 -1
  198. package/dist/test/integration/integration.private.test.d.ts +1 -0
  199. package/dist/test/integration/integration.private.test.js +308 -0
  200. package/dist/test/integration/integration.test.js +30 -31
  201. package/dist/test/nockHelpers.d.ts +2 -2
  202. package/dist/test/nockHelpers.js +3 -7
  203. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  204. package/dist/test/setupFiles/automatic-mocks.js +0 -22
  205. package/dist/types/Commit.d.ts +85 -0
  206. package/dist/types/Commit.js +139 -0
  207. package/dist/types/commitNode.d.ts +89 -0
  208. package/dist/types/commitNode.js +139 -0
  209. package/dist/types/commitNode.test.d.ts +1 -0
  210. package/dist/types/commitNode.test.js +255 -0
  211. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  212. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  213. package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
  214. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  215. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +135 -67
  216. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  217. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  218. package/dist/ui/getCommits.d.ts +1 -1
  219. package/dist/ui/getCommits.js +55 -25
  220. package/dist/ui/getTargetBranches.d.ts +2 -2
  221. package/dist/ui/getTargetBranches.js +16 -17
  222. package/dist/ui/getTargetBranches.test.js +75 -99
  223. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  224. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  225. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  226. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  227. package/dist/ui/maybeSetupRepo.js +9 -9
  228. package/dist/ui/maybeSetupRepo.test.js +5 -1
  229. package/package.json +36 -51
  230. package/yarn.lock +2387 -2979
@@ -0,0 +1,308 @@
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 path_1 = require("path");
8
+ const rest_1 = require("@octokit/rest");
9
+ const del = require("del");
10
+ const nock_1 = __importDefault(require("nock"));
11
+ const options_1 = require("../../options/options");
12
+ const runSequentially_1 = require("../../runSequentially");
13
+ const getCommits_1 = require("../../ui/getCommits");
14
+ const nockHelpers_1 = require("../nockHelpers");
15
+ const getDevAccessToken_1 = require("../private/getDevAccessToken");
16
+ jest.unmock('make-dir');
17
+ jest.unmock('del');
18
+ jest.setTimeout(10000);
19
+ const INTEGRATION_TEST_DATA_PATH = (0, path_1.resolve)('./src/test/integration/mock-environment');
20
+ const HOMEDIR_PATH = (0, path_1.resolve)('./src/test/integration/mock-environment/homedir');
21
+ const REPO_OWNER = 'backport-org';
22
+ const REPO_NAME = 'integration-test';
23
+ const BRANCH_NAME = 'backport/7.x/commit-5bf29b7d';
24
+ const USERNAME = 'sqren';
25
+ describe('integration', () => {
26
+ afterAll(() => {
27
+ nock_1.default.cleanAll();
28
+ });
29
+ beforeAll(() => {
30
+ // set alternative homedir
31
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue(HOMEDIR_PATH);
32
+ });
33
+ describe('when a single commit is backported', () => {
34
+ let res;
35
+ let accessToken;
36
+ let createPullRequestsMockCalls;
37
+ beforeAll(async () => {
38
+ accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
39
+ await resetState(accessToken);
40
+ createPullRequestsMockCalls = mockCreatePullRequest({
41
+ number: 1337,
42
+ html_url: 'myHtmlUrl',
43
+ });
44
+ const options = await (0, options_1.getOptions)([], {
45
+ githubApiBaseUrlV3: 'https://api.foo.com',
46
+ ci: true,
47
+ sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
48
+ username: USERNAME,
49
+ accessToken,
50
+ upstream: 'backport-org/integration-test',
51
+ });
52
+ const commits = await (0, getCommits_1.getCommits)(options);
53
+ const targetBranches = ['7.x'];
54
+ res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
55
+ });
56
+ it('returns pull request', () => {
57
+ expect(res).toEqual([
58
+ {
59
+ didUpdate: false,
60
+ pullRequestUrl: 'myHtmlUrl',
61
+ pullRequestNumber: 1337,
62
+ status: 'success',
63
+ targetBranch: '7.x',
64
+ },
65
+ ]);
66
+ });
67
+ it('sends the correct http body when creating pull request', () => {
68
+ expect(createPullRequestsMockCalls).toEqual([
69
+ {
70
+ base: '7.x',
71
+ body: 'Backports the following commits to 7.x:\n - Add ❤️ emoji (5bf29b7d)',
72
+ head: 'sqren:backport/7.x/commit-5bf29b7d',
73
+ title: '[7.x] Add ❤️ emoji',
74
+ },
75
+ ]);
76
+ });
77
+ it('should not create new branches in origin (backport-org/integration-test)', async () => {
78
+ const branches = await getBranches({
79
+ accessToken,
80
+ repoOwner: REPO_OWNER,
81
+ repoName: REPO_NAME,
82
+ });
83
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
84
+ });
85
+ it('should create branch in the fork (sqren/integration-test)', async () => {
86
+ const branches = await getBranches({
87
+ accessToken,
88
+ repoOwner: USERNAME,
89
+ repoName: REPO_NAME,
90
+ });
91
+ expect(branches.map((b) => b.name)).toEqual([
92
+ '7.x',
93
+ BRANCH_NAME,
94
+ 'master',
95
+ ]);
96
+ });
97
+ it('should have cherry picked the correct commit', async () => {
98
+ const branches = await getBranches({
99
+ accessToken,
100
+ repoOwner: USERNAME,
101
+ repoName: REPO_NAME,
102
+ });
103
+ const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
104
+ expect(sha).toEqual('b68e4fcaaf4427fe1e902c718b3bb3f07b560fb5');
105
+ });
106
+ });
107
+ // eslint-disable-next-line jest/no-disabled-tests
108
+ describe.skip('when two commits are backported', () => {
109
+ let createPullRequestsMockCalls;
110
+ let res;
111
+ let accessToken;
112
+ beforeAll(async () => {
113
+ accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
114
+ await resetState(accessToken);
115
+ createPullRequestsMockCalls = mockCreatePullRequest({
116
+ number: 1337,
117
+ html_url: 'myHtmlUrl',
118
+ });
119
+ const options = {
120
+ githubApiBaseUrlV3: 'https://api.foo.com',
121
+ ci: true,
122
+ sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
123
+ username: USERNAME,
124
+ accessToken,
125
+ upstream: 'backport-org/integration-test',
126
+ };
127
+ const commits = await (0, getCommits_1.getCommits)(options);
128
+ const targetBranches = ['7.x'];
129
+ res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
130
+ });
131
+ it('sends the correct http body when creating pull request', () => {
132
+ expect(createPullRequestsMockCalls).toEqual([
133
+ {
134
+ base: '7.x',
135
+ body: 'Backports the following commits to 7.x:\n - Add ❤️ emoji (5bf29b7d)',
136
+ head: 'sqren:backport/7.x/commit-5bf29b7d',
137
+ title: '[7.x] Add ❤️ emoji',
138
+ },
139
+ ]);
140
+ });
141
+ it('returns pull request', () => {
142
+ expect(res).toEqual([
143
+ { pullRequestUrl: 'myHtmlUrl', success: true, targetBranch: '6.0' },
144
+ ]);
145
+ });
146
+ it('should not create new branches in origin (backport-org/integration-test)', async () => {
147
+ const branches = await getBranches({
148
+ accessToken,
149
+ repoOwner: REPO_OWNER,
150
+ repoName: REPO_NAME,
151
+ });
152
+ expect(branches.map((b) => b.name)).toEqual(['7.x', '* master']);
153
+ });
154
+ it('should create branch in the fork (sqren/integration-test)', async () => {
155
+ const branches = await getBranches({
156
+ accessToken,
157
+ repoOwner: USERNAME,
158
+ repoName: REPO_NAME,
159
+ });
160
+ expect(branches.map((b) => b.name)).toEqual([
161
+ '7.x',
162
+ 'backport/6.0/pr-85_commit-2e63475c',
163
+ 'master',
164
+ ]);
165
+ });
166
+ it('should have cherry picked the correct commit', async () => {
167
+ const branches = await getBranches({
168
+ accessToken,
169
+ repoOwner: USERNAME,
170
+ repoName: REPO_NAME,
171
+ });
172
+ const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
173
+ expect(sha).toEqual('foo');
174
+ });
175
+ });
176
+ describe('when disabling fork mode', () => {
177
+ let res;
178
+ let accessToken;
179
+ let createPullRequestsMockCalls;
180
+ beforeAll(async () => {
181
+ accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
182
+ await resetState(accessToken);
183
+ createPullRequestsMockCalls = mockCreatePullRequest({
184
+ number: 1337,
185
+ html_url: 'myHtmlUrl',
186
+ });
187
+ const options = await (0, options_1.getOptions)([], {
188
+ githubApiBaseUrlV3: 'https://api.foo.com',
189
+ ci: true,
190
+ sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
191
+ username: USERNAME,
192
+ accessToken,
193
+ upstream: 'backport-org/integration-test',
194
+ fork: false,
195
+ });
196
+ const commits = await (0, getCommits_1.getCommits)(options);
197
+ const targetBranches = ['7.x'];
198
+ res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
199
+ });
200
+ it('sends the correct http body when creating pull request', () => {
201
+ expect(createPullRequestsMockCalls).toEqual([
202
+ {
203
+ base: '7.x',
204
+ body: 'Backports the following commits to 7.x:\n - Add ❤️ emoji (5bf29b7d)',
205
+ head: 'backport-org:backport/7.x/commit-5bf29b7d',
206
+ title: '[7.x] Add ❤️ emoji',
207
+ },
208
+ ]);
209
+ });
210
+ it('returns pull request', () => {
211
+ expect(res).toEqual([
212
+ {
213
+ didUpdate: false,
214
+ pullRequestNumber: 1337,
215
+ pullRequestUrl: 'myHtmlUrl',
216
+ status: 'success',
217
+ targetBranch: '7.x',
218
+ },
219
+ ]);
220
+ });
221
+ it('should create new branches in origin (backport-org/integration-test)', async () => {
222
+ const branches = await getBranches({
223
+ accessToken,
224
+ repoOwner: REPO_OWNER,
225
+ repoName: REPO_NAME,
226
+ });
227
+ expect(branches.map((b) => b.name)).toEqual([
228
+ '7.x',
229
+ BRANCH_NAME,
230
+ 'master',
231
+ ]);
232
+ });
233
+ it('should NOT create branch in the fork (sqren/integration-test)', async () => {
234
+ const branches = await getBranches({
235
+ accessToken,
236
+ repoOwner: USERNAME,
237
+ repoName: REPO_NAME,
238
+ });
239
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
240
+ });
241
+ it('should cherry pick the correct commit', async () => {
242
+ const branches = await getBranches({
243
+ accessToken,
244
+ repoOwner: REPO_OWNER,
245
+ repoName: REPO_NAME,
246
+ });
247
+ const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
248
+ expect(sha).toEqual('b68e4fcaaf4427fe1e902c718b3bb3f07b560fb5');
249
+ });
250
+ });
251
+ });
252
+ function mockCreatePullRequest(response) {
253
+ const scope = (0, nock_1.default)('https://api.foo.com', { allowUnmocked: true })
254
+ .post('/repos/backport-org/integration-test/pulls')
255
+ .reply(200, response);
256
+ return (0, nockHelpers_1.getNockCallsForScope)(scope);
257
+ }
258
+ async function getBranches({ accessToken, repoOwner, repoName, }) {
259
+ // console.log(`fetch branches for ${repoOwner}`);
260
+ const octokit = new rest_1.Octokit({
261
+ auth: accessToken,
262
+ });
263
+ const res = await octokit.repos.listBranches({
264
+ owner: repoOwner,
265
+ repo: repoName,
266
+ });
267
+ return res.data;
268
+ }
269
+ async function deleteBranch({ accessToken, repoOwner, repoName, branchName, }) {
270
+ try {
271
+ const octokit = new rest_1.Octokit({
272
+ auth: accessToken,
273
+ });
274
+ // console.log({ accessToken });
275
+ const opts = {
276
+ owner: repoOwner,
277
+ repo: repoName,
278
+ ref: `heads/${branchName}`,
279
+ };
280
+ const res = await octokit.git.deleteRef(opts);
281
+ // console.log(`Deleted ${repoOwner}:heads/${branchName}`);
282
+ return res.data;
283
+ }
284
+ catch (e) {
285
+ // console.log(
286
+ // `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
287
+ // );
288
+ if (e.message === 'Reference does not exist') {
289
+ return;
290
+ }
291
+ throw e;
292
+ }
293
+ }
294
+ async function resetState(accessToken) {
295
+ await deleteBranch({
296
+ accessToken,
297
+ repoOwner: REPO_OWNER,
298
+ repoName: REPO_NAME,
299
+ branchName: BRANCH_NAME,
300
+ });
301
+ await deleteBranch({
302
+ accessToken,
303
+ repoOwner: USERNAME,
304
+ repoName: REPO_NAME,
305
+ branchName: BRANCH_NAME,
306
+ });
307
+ await del(INTEGRATION_TEST_DATA_PATH);
308
+ }
@@ -12,7 +12,6 @@ const envConstants_1 = require("./envConstants");
12
12
  const helpers_1 = require("./helpers");
13
13
  jest.unmock('make-dir');
14
14
  jest.unmock('del');
15
- jest.unmock('../../services/child-process-promisified');
16
15
  describe('integration', () => {
17
16
  afterAll(() => {
18
17
  nock_1.default.cleanAll();
@@ -20,15 +19,15 @@ describe('integration', () => {
20
19
  describe('when a single commit is backported', () => {
21
20
  let res;
22
21
  let spies;
23
- beforeEach(lodash_1.once(async () => {
22
+ beforeEach((0, lodash_1.once)(async () => {
24
23
  jest.clearAllMocks();
25
- spies = createSpies_1.createSpies({ commitCount: 1 });
26
- await helpers_1.deleteAndSetupEnvironment();
27
- const options = await options_1.getOptions([], {
24
+ spies = (0, createSpies_1.createSpies)({ commitCount: 1 });
25
+ await (0, helpers_1.deleteAndSetupEnvironment)();
26
+ const options = await (0, options_1.getOptions)([], {
28
27
  // use localhost to avoid CORS issues
29
28
  githubApiBaseUrlV4: 'http://localhost/graphql',
30
29
  });
31
- res = await runWithOptions_1.runWithOptions(options);
30
+ res = await (0, runWithOptions_1.runWithOptions)(options);
32
31
  }));
33
32
  it('returns pull request', () => {
34
33
  expect(res).toEqual([
@@ -39,27 +38,27 @@ describe('integration', () => {
39
38
  expect(spies.createPullRequestCalls).toEqual([
40
39
  {
41
40
  base: '6.0',
42
- body: 'Backports the following commits to 6.0:\n - Add witch (#85)',
41
+ body: 'Backports the following commits to 6.0:\n - #85',
43
42
  head: 'sqren:backport/6.0/pr-85',
44
43
  title: '[6.0] Add witch (#85)',
45
44
  },
46
45
  ]);
47
46
  });
48
47
  it('should make correct API requests', () => {
49
- expect(spies.getDefaultRepoBranchCalls).toMatchSnapshot();
48
+ expect(spies.getGithubConfigOptionsCalls).toMatchSnapshot();
50
49
  expect(spies.authorIdCalls).toMatchSnapshot();
51
50
  expect(spies.commitsByAuthorCalls).toMatchSnapshot();
52
51
  });
53
52
  it('should not create new branches in origin (backport-org/backport-demo)', async () => {
54
- const branches = await helpers_1.getBranches(envConstants_1.REMOTE_ORIGIN_REPO_PATH);
53
+ const branches = await (0, helpers_1.getBranches)(envConstants_1.REMOTE_ORIGIN_REPO_PATH);
55
54
  expect(branches).toEqual(['6.0', '* master']);
56
55
  });
57
56
  it('should create branch in the fork (sqren/backport-demo)', async () => {
58
- const branches = await helpers_1.getBranches(envConstants_1.REMOTE_FORK_REPO_PATH);
57
+ const branches = await (0, helpers_1.getBranches)(envConstants_1.REMOTE_FORK_REPO_PATH);
59
58
  expect(branches).toEqual(['6.0', 'backport/6.0/pr-85', '* master']);
60
59
  });
61
60
  it('should have cherry picked the correct commit', async () => {
62
- const commit = await helpers_1.getLatestCommit({
61
+ const commit = await (0, helpers_1.getLatestCommit)({
63
62
  branch: 'backport/6.0/pr-85',
64
63
  commitCount: 1,
65
64
  cwd: envConstants_1.REMOTE_FORK_REPO_PATH,
@@ -82,23 +81,23 @@ describe('integration', () => {
82
81
  describe('when two commits are backported', () => {
83
82
  let spies;
84
83
  let res;
85
- beforeEach(lodash_1.once(async () => {
84
+ beforeEach((0, lodash_1.once)(async () => {
86
85
  jest.clearAllMocks();
87
- spies = createSpies_1.createSpies({ commitCount: 2 });
88
- await helpers_1.deleteAndSetupEnvironment();
89
- const options = await options_1.getOptions([], {
86
+ spies = (0, createSpies_1.createSpies)({ commitCount: 2 });
87
+ await (0, helpers_1.deleteAndSetupEnvironment)();
88
+ const options = await (0, options_1.getOptions)([], {
90
89
  // use localhost to avoid CORS issues
91
90
  githubApiBaseUrlV4: 'http://localhost/graphql',
92
91
  });
93
- res = await runWithOptions_1.runWithOptions(options);
92
+ res = await (0, runWithOptions_1.runWithOptions)(options);
94
93
  }));
95
94
  it('sends the correct http body when creating pull request', () => {
96
95
  expect(spies.createPullRequestCalls).toEqual([
97
96
  {
98
- title: '[6.0] Add witch (#85) | Add 👻 (2e63475c)',
97
+ title: '[6.0] Add witch (#85) | Add 👻',
99
98
  head: 'sqren:backport/6.0/pr-85_commit-2e63475c',
100
99
  base: '6.0',
101
- body: 'Backports the following commits to 6.0:\n - Add witch (#85)\n - Add 👻 (2e63475c)',
100
+ body: 'Backports the following commits to 6.0:\n - #85\n - Add 👻 (2e63475c)',
102
101
  },
103
102
  ]);
104
103
  });
@@ -108,16 +107,16 @@ describe('integration', () => {
108
107
  ]);
109
108
  });
110
109
  it('should make correct API requests', () => {
111
- expect(spies.getDefaultRepoBranchCalls).toMatchSnapshot();
110
+ expect(spies.getGithubConfigOptionsCalls).toMatchSnapshot();
112
111
  expect(spies.authorIdCalls).toMatchSnapshot();
113
112
  expect(spies.commitsByAuthorCalls).toMatchSnapshot();
114
113
  });
115
114
  it('should not create new branches in origin (backport-org/backport-demo)', async () => {
116
- const branches = await helpers_1.getBranches(envConstants_1.REMOTE_ORIGIN_REPO_PATH);
115
+ const branches = await (0, helpers_1.getBranches)(envConstants_1.REMOTE_ORIGIN_REPO_PATH);
117
116
  expect(branches).toEqual(['6.0', '* master']);
118
117
  });
119
118
  it('should create branch in the fork (sqren/backport-demo)', async () => {
120
- const branches = await helpers_1.getBranches(envConstants_1.REMOTE_FORK_REPO_PATH);
119
+ const branches = await (0, helpers_1.getBranches)(envConstants_1.REMOTE_FORK_REPO_PATH);
121
120
  expect(branches).toEqual([
122
121
  '6.0',
123
122
  'backport/6.0/pr-85_commit-2e63475c',
@@ -125,7 +124,7 @@ describe('integration', () => {
125
124
  ]);
126
125
  });
127
126
  it('should have cherry picked the correct commit', async () => {
128
- const commit = await helpers_1.getLatestCommit({
127
+ const commit = await (0, helpers_1.getLatestCommit)({
129
128
  branch: 'backport/6.0/pr-85_commit-2e63475c',
130
129
  commitCount: 2,
131
130
  cwd: envConstants_1.REMOTE_FORK_REPO_PATH,
@@ -158,21 +157,21 @@ describe('integration', () => {
158
157
  describe('when disabling fork mode', () => {
159
158
  let res;
160
159
  let spies;
161
- beforeEach(lodash_1.once(async () => {
160
+ beforeEach((0, lodash_1.once)(async () => {
162
161
  jest.clearAllMocks();
163
- spies = createSpies_1.createSpies({ commitCount: 1 });
164
- await helpers_1.deleteAndSetupEnvironment();
165
- const options = await options_1.getOptions(['--fork=false'], {
162
+ spies = (0, createSpies_1.createSpies)({ commitCount: 1 });
163
+ await (0, helpers_1.deleteAndSetupEnvironment)();
164
+ const options = await (0, options_1.getOptions)(['--fork=false'], {
166
165
  // use localhost to avoid CORS issues
167
166
  githubApiBaseUrlV4: 'http://localhost/graphql',
168
167
  });
169
- res = await runWithOptions_1.runWithOptions(options);
168
+ res = await (0, runWithOptions_1.runWithOptions)(options);
170
169
  }));
171
170
  it('sends the correct http body when creating pull request', () => {
172
171
  expect(spies.createPullRequestCalls).toEqual([
173
172
  {
174
173
  base: '6.0',
175
- body: 'Backports the following commits to 6.0:\n - Add witch (#85)',
174
+ body: 'Backports the following commits to 6.0:\n - #85',
176
175
  head: 'backport-org:backport/6.0/pr-85',
177
176
  title: '[6.0] Add witch (#85)',
178
177
  },
@@ -184,15 +183,15 @@ describe('integration', () => {
184
183
  ]);
185
184
  });
186
185
  it('should create new branches in origin (backport-org/backport-demo)', async () => {
187
- const branches = await helpers_1.getBranches(envConstants_1.REMOTE_ORIGIN_REPO_PATH);
186
+ const branches = await (0, helpers_1.getBranches)(envConstants_1.REMOTE_ORIGIN_REPO_PATH);
188
187
  expect(branches).toEqual(['6.0', 'backport/6.0/pr-85', '* master']);
189
188
  });
190
189
  it('should NOT create branch in the fork (sqren/backport-demo)', async () => {
191
- const branches = await helpers_1.getBranches(envConstants_1.REMOTE_FORK_REPO_PATH);
190
+ const branches = await (0, helpers_1.getBranches)(envConstants_1.REMOTE_FORK_REPO_PATH);
192
191
  expect(branches).toEqual(['6.0', '* master']);
193
192
  });
194
193
  it('should cherry pick the correct commit', async () => {
195
- const commit = await helpers_1.getLatestCommit({
194
+ const commit = await (0, helpers_1.getLatestCommit)({
196
195
  branch: 'backport/6.0/pr-85',
197
196
  commitCount: 1,
198
197
  cwd: envConstants_1.REMOTE_ORIGIN_REPO_PATH,
@@ -1,9 +1,9 @@
1
1
  import nock from 'nock';
2
- export declare function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }: {
2
+ export declare function mockGqlRequest<T>({ name, statusCode, body, headers, apiBaseUrl, }: {
3
3
  name: string;
4
4
  statusCode: number;
5
5
  body?: {
6
- data: Record<any, any>;
6
+ data: T;
7
7
  } | {
8
8
  errors: any[];
9
9
  };
@@ -10,19 +10,15 @@ const nock_1 = __importDefault(require("nock"));
10
10
  function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
11
11
  const { origin, pathname } = new url_1.URL(
12
12
  // default to localhost as host to avoid CORS issues
13
- apiBaseUrl !== null &&
14
- // default to localhost as host to avoid CORS issues
15
- apiBaseUrl !== void 0 ?
16
- // default to localhost as host to avoid CORS issues
17
- apiBaseUrl : 'http://localhost/graphql');
18
- const scope = nock_1.default(origin)
13
+ apiBaseUrl ?? 'http://localhost/graphql');
14
+ const scope = (0, nock_1.default)(origin)
19
15
  .post(pathname, (body) => getGqlName(body.query) === name)
20
16
  .reply(statusCode, body, headers);
21
17
  return getNockCallsForScope(scope);
22
18
  }
23
19
  exports.mockGqlRequest = mockGqlRequest;
24
20
  function getGqlName(query) {
25
- const obj = graphql_tag_1.default `
21
+ const obj = (0, graphql_tag_1.default) `
26
22
  ${query}
27
23
  `;
28
24
  // @ts-expect-error
@@ -1 +0,0 @@
1
- export {};
@@ -3,29 +3,7 @@
3
3
  * This file is included in `setupFiles` in jest.config.js
4
4
  * It will be run once per test file
5
5
  */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
6
  /* eslint-disable @typescript-eslint/no-empty-function */
11
- const os_1 = __importDefault(require("os"));
12
- const lodash_1 = require("lodash");
13
- jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
14
- jest.mock('../../services/child-process-promisified', () => {
15
- return {
16
- exec: jest.fn(async (cmd) => {
17
- throw new Error(`Mock required for exec with cmd: "${cmd}"`);
18
- }),
19
- execAsCallback: jest.fn((...args) => {
20
- lodash_1.last(args)();
21
- return {
22
- stderr: {
23
- on: () => { },
24
- },
25
- };
26
- }),
27
- };
28
- });
29
7
  jest.mock('../../services/fs-promisified', () => {
30
8
  return {
31
9
  writeFile: jest.fn(async () => 'fs.writeFile mock value'),
@@ -0,0 +1,85 @@
1
+ import { ValidConfigOptions } from '../options/options';
2
+ export interface Commit {
3
+ committedDate: string;
4
+ sourceBranch: string;
5
+ targetBranchesFromLabels: string[];
6
+ sha: string;
7
+ formattedMessage: string;
8
+ originalMessage: string;
9
+ pullNumber?: number;
10
+ existingTargetPullRequests: ExistingTargetPullRequests;
11
+ }
12
+ export interface PullRequestNode {
13
+ baseRefName: string;
14
+ number: number;
15
+ mergeCommit: {
16
+ committedDate: string;
17
+ oid: string;
18
+ message: string;
19
+ } | null;
20
+ labels: {
21
+ nodes: {
22
+ name: string;
23
+ }[];
24
+ };
25
+ repository: {
26
+ owner: {
27
+ login: string;
28
+ };
29
+ name: string;
30
+ };
31
+ timelineItems: {
32
+ edges: Array<TimelineEdge>;
33
+ };
34
+ }
35
+ declare type TimelineEdge = TimelinePullRequestEdge | TimelineIssueEdge;
36
+ interface TimelinePullRequestEdge {
37
+ node: {
38
+ source: {
39
+ __typename: 'PullRequest';
40
+ title: string;
41
+ state: 'OPEN' | 'CLOSED' | 'MERGED';
42
+ baseRefName: string;
43
+ number: number;
44
+ commits: {
45
+ edges: CommitEdge[];
46
+ };
47
+ };
48
+ };
49
+ }
50
+ interface TimelineIssueEdge {
51
+ node: {
52
+ source: {
53
+ __typename: 'Issue';
54
+ };
55
+ };
56
+ }
57
+ interface CommitEdge {
58
+ node: {
59
+ commit: {
60
+ message: string;
61
+ };
62
+ };
63
+ }
64
+ export declare type CommitNode = {
65
+ oid: string;
66
+ message: string;
67
+ committedDate: string;
68
+ associatedPullRequests: {
69
+ edges: {
70
+ node: PullRequestNode;
71
+ }[] | null;
72
+ };
73
+ };
74
+ export declare function getCommit(options: ValidConfigOptions, commitNode: CommitNode): Commit;
75
+ export declare const commitNodeFragment: {
76
+ name: string;
77
+ source: string;
78
+ };
79
+ export declare type ExistingTargetPullRequests = ReturnType<typeof getExistingTargetPullRequests>;
80
+ export declare function getExistingTargetPullRequests(sourcePullRequest?: PullRequestNode): {
81
+ number: number;
82
+ branch: string;
83
+ state: "OPEN" | "CLOSED" | "MERGED";
84
+ }[];
85
+ export {};