backport 6.1.5 → 6.3.0-beta-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 (249) hide show
  1. package/README.md +15 -6
  2. package/dist/{main.d.ts → backportRun.d.ts} +3 -3
  3. package/dist/{main.js → backportRun.js} +21 -10
  4. package/dist/{entrypoint.module.private.test.d.ts → entrypoint.cli.e2e.private.test.d.ts} +0 -0
  5. package/dist/entrypoint.cli.e2e.private.test.js +277 -0
  6. package/dist/entrypoint.cli.js +3 -5
  7. package/dist/{options/getValidatedOptions.test.d.ts → entrypoint.cli.private.test.d.ts} +0 -0
  8. package/dist/{entrypoint.module.private.test.js → entrypoint.cli.private.test.js} +17 -8
  9. package/dist/entrypoint.module.d.ts +2 -2
  10. package/dist/entrypoint.module.js +4 -4
  11. package/dist/options/ConfigOptions.d.ts +5 -1
  12. package/dist/options/cliArgs.d.ts +16 -14
  13. package/dist/options/cliArgs.js +15 -5
  14. package/dist/options/cliArgs.test.js +28 -10
  15. package/dist/options/config/config.d.ts +10 -4
  16. package/dist/options/config/config.js +7 -6
  17. package/dist/options/config/config.test.js +11 -1
  18. package/dist/options/config/globalConfig.d.ts +1 -1
  19. package/dist/options/config/globalConfig.js +15 -9
  20. package/dist/options/config/globalConfig.test.js +19 -32
  21. package/dist/options/config/projectConfig.d.ts +3 -1
  22. package/dist/options/config/projectConfig.js +5 -2
  23. package/dist/options/config/projectConfig.test.js +41 -31
  24. package/dist/options/config/readConfigFile.d.ts +27 -23
  25. package/dist/options/config/readConfigFile.js +2 -2
  26. package/dist/options/options.d.ts +18 -39
  27. package/dist/options/options.js +40 -32
  28. package/dist/options/options.test.js +83 -47
  29. package/dist/runSequentially.d.ts +0 -1
  30. package/dist/runSequentially.js +0 -1
  31. package/dist/runSequentially.test.js +39 -20
  32. package/dist/scripts/postinstall.js +3 -3
  33. package/dist/services/HandledError.d.ts +6 -4
  34. package/dist/services/HandledError.js +18 -3
  35. package/dist/services/child-process-promisified.d.ts +3 -1
  36. package/dist/services/env.d.ts +3 -1
  37. package/dist/services/env.js +4 -1
  38. package/dist/services/env.test.js +2 -2
  39. package/dist/services/git.d.ts +22 -9
  40. package/dist/services/git.integration.test.js +123 -24
  41. package/dist/services/git.js +66 -54
  42. package/dist/services/git.test.js +35 -20
  43. package/dist/services/github/commitFormatters.d.ts +0 -1
  44. package/dist/services/github/commitFormatters.js +1 -8
  45. package/dist/services/github/v3/createPullRequest.js +16 -10
  46. package/dist/services/github/v3/createPullRequest.test.js +248 -33
  47. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  48. package/dist/services/github/v3/createStatusComment.js +26 -15
  49. package/dist/services/github/v3/createStatusComment.test.js +165 -70
  50. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +2 -1
  51. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -7
  52. package/dist/services/github/v4/apiRequestV4.d.ts +21 -17
  53. package/dist/services/github/v4/apiRequestV4.js +38 -28
  54. package/dist/services/github/v4/apiRequestV4.test.js +4 -4
  55. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -7
  56. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -7
  57. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +37 -19
  58. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +17 -8
  59. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -3
  60. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +23 -14
  61. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
  62. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +4 -4
  63. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +41 -19
  64. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +1 -8
  65. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +31 -14
  66. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -4
  67. package/dist/services/github/v4/fetchExistingPullRequest.js +1 -2
  68. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -9
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +6 -2
  70. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +41 -34
  71. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -0
  72. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +2 -1
  73. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  74. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +56 -0
  75. package/dist/{options/parseRequiredOptions.test.d.ts → services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts} +0 -0
  76. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  77. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +11 -11
  78. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +4 -5
  79. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -7
  80. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
  81. package/dist/services/logger.d.ts +9 -3
  82. package/dist/services/logger.js +38 -35
  83. package/dist/services/prompt.test.js +66 -19
  84. package/dist/services/prompts.js +12 -10
  85. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +1 -1
  86. package/dist/services/sourceCommit/getMockSourceCommit.js +6 -6
  87. package/dist/services/sourceCommit/parseSourceCommit.d.ts +18 -10
  88. package/dist/services/sourceCommit/parseSourceCommit.js +20 -14
  89. package/dist/services/sourceCommit/parseSourceCommit.test.js +18 -20
  90. package/dist/{runWithOptions.test.d.ts → test/backport-e2e.mutation.test.d.ts} +0 -0
  91. package/dist/test/{integration/integration.private.test.js → backport-e2e.mutation.test.js} +143 -123
  92. package/dist/{scripts/generate-gql.d.ts → test/handleUnbackportedPullRequests.private.test.d.ts} +0 -0
  93. package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
  94. package/dist/test/mockConfigFiles.js +4 -20
  95. package/dist/test/mocks.d.ts +10 -0
  96. package/dist/test/mocks.js +23 -0
  97. package/dist/test/private/getDevAccessToken.js +5 -4
  98. package/dist/test/sandbox.d.ts +5 -0
  99. package/dist/test/sandbox.js +43 -0
  100. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  101. package/dist/test/setupFiles/automatic-mocks.js +27 -11
  102. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -1
  103. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -13
  104. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +50 -27
  105. package/dist/ui/getCommits.js +8 -14
  106. package/dist/ui/getCommitsWithoutBackports.js +6 -6
  107. package/dist/ui/getCommitsWithoutBackports.test.js +91 -39
  108. package/dist/ui/getTargetBranches.js +1 -1
  109. package/dist/ui/getTargetBranches.test.js +26 -8
  110. package/dist/ui/maybeSetupRepo.js +25 -5
  111. package/dist/ui/maybeSetupRepo.test.js +144 -14
  112. package/dist/utils/maybe.d.ts +1 -0
  113. package/dist/utils/maybe.js +7 -0
  114. package/dist/utils/packageVersion.d.ts +1 -0
  115. package/dist/{types/PromiseReturnType.js → utils/packageVersion.js} +2 -0
  116. package/package.json +24 -20
  117. package/yarn.lock +160 -237
  118. package/dist/index.d.ts +0 -783
  119. package/dist/index.js +0 -8001
  120. package/dist/ink.d.ts +0 -1
  121. package/dist/ink.js +0 -49
  122. package/dist/options/config/getOptionsFromGit.d.ts +0 -4
  123. package/dist/options/config/getOptionsFromGit.js +0 -8
  124. package/dist/options/getValidatedOptions.d.ts +0 -49
  125. package/dist/options/getValidatedOptions.js +0 -45
  126. package/dist/options/getValidatedOptions.test.js +0 -97
  127. package/dist/options/parseRequiredOptions.d.ts +0 -71
  128. package/dist/options/parseRequiredOptions.js +0 -68
  129. package/dist/options/parseRequiredOptions.test.js +0 -122
  130. package/dist/runWithOptions.d.ts +0 -9
  131. package/dist/runWithOptions.js +0 -43
  132. package/dist/runWithOptions.test.js +0 -304
  133. package/dist/scripts/generate-gql.js +0 -15
  134. package/dist/services/fs-promisified.d.ts +0 -6
  135. package/dist/services/fs-promisified.js +0 -12
  136. package/dist/services/getExpectedTarget.d.ts +0 -9
  137. package/dist/services/getExpectedTarget.js +0 -77
  138. package/dist/services/getExpectedTargetPullRequests.d.ts +0 -9
  139. package/dist/services/getExpectedTargetPullRequests.js +0 -77
  140. package/dist/services/github/v4/fetchCommitByPullNumber.d.ts +0 -5
  141. package/dist/services/github/v4/fetchCommitByPullNumber.js +0 -86
  142. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.d.ts +0 -1
  143. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +0 -57
  144. package/dist/services/github/v4/fetchCommitBySha.d.ts +0 -5
  145. package/dist/services/github/v4/fetchCommitBySha.js +0 -95
  146. package/dist/services/github/v4/fetchCommitBySha.private.test.d.ts +0 -1
  147. package/dist/services/github/v4/fetchCommitBySha.private.test.js +0 -50
  148. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +0 -28
  149. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +0 -52
  150. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +0 -3
  151. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +0 -55
  152. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +0 -1
  153. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +0 -252
  154. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +0 -28
  155. package/dist/services/github/v4/fetchCommitsByAuthor.js +0 -161
  156. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.d.ts +0 -1
  157. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +0 -115
  158. package/dist/services/github/v4/fetchCommitsByAuthor.test.d.ts +0 -1
  159. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +0 -272
  160. package/dist/services/github/v4/fetchDefaultBranch.d.ts +0 -9
  161. package/dist/services/github/v4/fetchDefaultBranch.js +0 -24
  162. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -4
  163. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -52
  164. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
  165. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
  166. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +0 -4
  167. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +0 -72
  168. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +0 -1
  169. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +0 -34
  170. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +0 -40
  171. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +0 -72
  172. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -17
  173. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -69
  174. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
  175. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
  176. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +0 -37
  177. package/dist/services/github/v4/fetchMergedPullRequests.js +0 -37
  178. package/dist/services/github/v4/fetchMergedPullRequests.private.test.d.ts +0 -1
  179. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +0 -59
  180. package/dist/services/github/v4/fetchMergedPullRequests.test.d.ts +0 -1
  181. package/dist/services/github/v4/fetchMergedPullRequests.test.js +0 -22
  182. package/dist/services/github/v4/fetchProjectConfig.d.ts +0 -8
  183. package/dist/services/github/v4/fetchProjectConfig.js +0 -56
  184. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +0 -1
  185. package/dist/services/github/v4/fetchProjectConfig.private.test.js +0 -52
  186. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +0 -1
  187. package/dist/services/github/v4/fetchProjectConfig.test.js +0 -37
  188. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +0 -9
  189. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +0 -92
  190. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  191. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +0 -66
  192. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.d.ts +0 -1
  193. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +0 -242
  194. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +0 -7
  195. package/dist/services/github/v4/getExistingTargetPullRequests.js +0 -45
  196. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +0 -63
  197. package/dist/services/github/v4/getOptionsFromGithub/index.js +0 -139
  198. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +0 -1
  199. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +0 -147
  200. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -5
  201. package/dist/services/github/v4/getTargetBranchesFromLabels.js +0 -20
  202. package/dist/services/github/v4/getTargetBranchesFromLabels.test.d.ts +0 -1
  203. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +0 -201
  204. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +0 -2
  205. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +0 -843
  206. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +0 -2
  207. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +0 -73
  208. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +0 -12
  209. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +0 -44
  210. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +0 -5
  211. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +0 -20
  212. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +0 -1
  213. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +0 -201
  214. package/dist/services/sourceCommit/sourceCommit.d.ts +0 -78
  215. package/dist/services/sourceCommit/sourceCommit.js +0 -86
  216. package/dist/services/sourceCommit/sourceCommit.test.d.ts +0 -1
  217. package/dist/services/sourceCommit/sourceCommit.test.js +0 -287
  218. package/dist/services/sourceCommit.d.ts +0 -78
  219. package/dist/services/sourceCommit.js +0 -86
  220. package/dist/services/sourceCommit.test.d.ts +0 -1
  221. package/dist/services/sourceCommit.test.js +0 -280
  222. package/dist/test/inquirer.private.test.d.ts +0 -1
  223. package/dist/test/inquirer.private.test.js +0 -168
  224. package/dist/test/integration/createSpies.d.ts +0 -17
  225. package/dist/test/integration/createSpies.js +0 -85
  226. package/dist/test/integration/envConstants.d.ts +0 -5
  227. package/dist/test/integration/envConstants.js +0 -9
  228. package/dist/test/integration/helpers.d.ts +0 -7
  229. package/dist/test/integration/helpers.js +0 -31
  230. package/dist/test/integration/integration.private.test.d.ts +0 -1
  231. package/dist/test/integration/integration.test.d.ts +0 -1
  232. package/dist/test/integration/integration.test.js +0 -214
  233. package/dist/todo-delete.d.ts +0 -1
  234. package/dist/todo-delete.js +0 -17
  235. package/dist/types/Commit.d.ts +0 -85
  236. package/dist/types/Commit.js +0 -139
  237. package/dist/types/PromiseReturnType.d.ts +0 -1
  238. package/dist/types/commitNode.d.ts +0 -89
  239. package/dist/types/commitNode.js +0 -139
  240. package/dist/types/commitNode.test.d.ts +0 -1
  241. package/dist/types/commitNode.test.js +0 -255
  242. package/dist/types/commitWithAssociatedPullRequests.d.ts +0 -86
  243. package/dist/types/commitWithAssociatedPullRequests.js +0 -145
  244. package/dist/ui/cherrypickAndCreatePullRequest.test.d.ts +0 -1
  245. package/dist/ui/cherrypickAndCreatePullRequest.test.js +0 -617
  246. package/dist/ui/getTargetBranchesFromLabels.d.ts +0 -6
  247. package/dist/ui/getTargetBranchesFromLabels.js +0 -40
  248. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +0 -1
  249. package/dist/ui/getTargetBranchesFromLabels.test.js +0 -288
@@ -37,12 +37,21 @@ describe('getCommitsWithoutBackports', () => {
37
37
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
38
38
  .mockResolvedValueOnce([
39
39
  {
40
- committedDate: '10',
40
+ sourceCommit: {
41
+ committedDate: '10',
42
+ message: 'First commit (#1)',
43
+ sha: 'xyz',
44
+ },
45
+ sourcePullRequest: {
46
+ url: 'https://www.github.com/foo/bar/pull/123',
47
+ number: 123,
48
+ mergeCommit: {
49
+ message: 'First commit (#1)',
50
+ sha: 'xyz',
51
+ },
52
+ },
41
53
  expectedTargetPullRequests,
42
- originalMessage: 'First commit (#1)',
43
- sha: 'xyz',
44
54
  sourceBranch: 'main',
45
- pullUrl: 'https://www.github.com/foo/bar/pull/123',
46
55
  },
47
56
  ]);
48
57
  // simulate commit is definitely not backported
@@ -50,10 +59,12 @@ describe('getCommitsWithoutBackports', () => {
50
59
  return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
51
60
  options: {},
52
61
  commit: {
53
- committedDate: '100',
62
+ sourceCommit: {
63
+ committedDate: '100',
64
+ message: 'Second commit (#2)',
65
+ sha: 'abc',
66
+ },
54
67
  expectedTargetPullRequests: [],
55
- originalMessage: 'Second commit (#2)',
56
- sha: 'abc',
57
68
  sourceBranch: 'main',
58
69
  },
59
70
  targetBranch: '7.x',
@@ -119,7 +130,20 @@ describe('getCommitsWithoutBackports', () => {
119
130
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
120
131
  .mockResolvedValueOnce([
121
132
  {
122
- committedDate: offendingCommitDate,
133
+ sourceCommit: {
134
+ committedDate: offendingCommitDate,
135
+ message: 'First commit (#1)',
136
+ sha: 'xyz',
137
+ },
138
+ sourcePullRequest: {
139
+ number: 123,
140
+ url: 'https://www.github.com/foo/bar/pull/123',
141
+ mergeCommit: {
142
+ message: 'First commit (#1)',
143
+ sha: 'xyz',
144
+ },
145
+ },
146
+ sourceBranch: 'main',
123
147
  expectedTargetPullRequests: [
124
148
  {
125
149
  state: 'OPEN',
@@ -128,11 +152,6 @@ describe('getCommitsWithoutBackports', () => {
128
152
  url: 'https://www.github.com/foo/bar/pull/456',
129
153
  },
130
154
  ],
131
- originalMessage: 'First commit (#1)',
132
- sha: 'xyz',
133
- sourceBranch: 'main',
134
- pullNumber: 123,
135
- pullUrl: 'https://www.github.com/foo/bar/pull/123',
136
155
  },
137
156
  ]);
138
157
  // simulate commit is definitely not backported
@@ -140,11 +159,21 @@ describe('getCommitsWithoutBackports', () => {
140
159
  return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
141
160
  options: {},
142
161
  commit: {
143
- committedDate: currentCommitDate,
144
- expectedTargetPullRequests: [],
145
- originalMessage: 'Second commit (#2)',
146
- sha: 'abc',
162
+ sourceCommit: {
163
+ committedDate: currentCommitDate,
164
+ message: 'Second commit (#2)',
165
+ sha: 'abc',
166
+ },
167
+ sourcePullRequest: {
168
+ number: 123,
169
+ url: 'https://www.github.com/foo/bar/pull/123',
170
+ mergeCommit: {
171
+ message: 'Second commit (#2)',
172
+ sha: 'abc',
173
+ },
174
+ },
147
175
  sourceBranch: 'main',
176
+ expectedTargetPullRequests: [],
148
177
  },
149
178
  targetBranch: '7.x',
150
179
  conflictingFiles: ['/foo/bar/baz.ts'],
@@ -172,9 +201,20 @@ describe('getCommitsWithoutBackports', () => {
172
201
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
173
202
  .mockResolvedValueOnce([
174
203
  {
175
- pullUrl: 'https://www.github.com/foo/bar/pull/123',
176
- pullNumber: 123,
177
- committedDate: '10',
204
+ sourceCommit: {
205
+ committedDate: '10',
206
+ message: 'First commit (#1)',
207
+ sha: 'xyz',
208
+ },
209
+ sourcePullRequest: {
210
+ number: 123,
211
+ url: 'https://www.github.com/foo/bar/pull/123',
212
+ mergeCommit: {
213
+ message: 'First commit (#1)',
214
+ sha: 'xyz',
215
+ },
216
+ },
217
+ sourceBranch: 'main',
178
218
  expectedTargetPullRequests: [
179
219
  {
180
220
  branch: offendingCommitTargetBranch,
@@ -183,9 +223,6 @@ describe('getCommitsWithoutBackports', () => {
183
223
  number: 456,
184
224
  },
185
225
  ],
186
- originalMessage: 'First commit (#1)',
187
- sha: 'xyz',
188
- sourceBranch: 'main',
189
226
  },
190
227
  ]);
191
228
  // simulate commit is definitely not backported
@@ -194,12 +231,20 @@ describe('getCommitsWithoutBackports', () => {
194
231
  options: {},
195
232
  // commit that is being backported
196
233
  commit: {
197
- pullUrl: 'https://www.github.com/foo/bar/pull/123',
198
- pullNumber: 123,
199
- committedDate: '100',
234
+ sourceCommit: {
235
+ committedDate: '100',
236
+ message: 'Second commit (#2)',
237
+ sha: 'abc',
238
+ },
239
+ sourcePullRequest: {
240
+ url: 'https://www.github.com/foo/bar/pull/123',
241
+ number: 123,
242
+ mergeCommit: {
243
+ message: 'Second commit (#2)',
244
+ sha: 'abc',
245
+ },
246
+ },
200
247
  expectedTargetPullRequests: [],
201
- originalMessage: 'Second commit (#2)',
202
- sha: 'abc',
203
248
  sourceBranch: 'main',
204
249
  },
205
250
  targetBranch: currentCommitTargetBranch,
@@ -227,13 +272,12 @@ describe('getCommitsWithoutBackports', () => {
227
272
  .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
228
273
  .mockResolvedValueOnce([
229
274
  {
230
- // intentionally left out:
231
- // pullNumber: 33,
232
- // pullUrl: 'https://www.github.com/foo/bar/pull/123',
233
- committedDate: '10',
275
+ sourceCommit: {
276
+ committedDate: '10',
277
+ sha: 'xyz',
278
+ message: 'First commit (#1)',
279
+ },
234
280
  expectedTargetPullRequests: [],
235
- originalMessage: 'First commit (#1)',
236
- sha: 'xyz',
237
281
  sourceBranch: 'main',
238
282
  },
239
283
  ]);
@@ -242,12 +286,20 @@ describe('getCommitsWithoutBackports', () => {
242
286
  const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
243
287
  options: {},
244
288
  commit: {
245
- pullUrl: 'https://www.github.com/foo/bar/pull/123',
246
- pullNumber: 123,
247
- committedDate: '100',
289
+ sourceCommit: {
290
+ committedDate: '100',
291
+ message: 'Second commit (#2)',
292
+ sha: 'abc',
293
+ },
294
+ sourcePullRequest: {
295
+ url: 'https://www.github.com/foo/bar/pull/123',
296
+ number: 123,
297
+ mergeCommit: {
298
+ message: 'Second commit (#2)',
299
+ sha: 'abc',
300
+ },
301
+ },
248
302
  expectedTargetPullRequests: [],
249
- originalMessage: 'Second commit (#2)',
250
- sha: 'abc',
251
303
  sourceBranch: 'main',
252
304
  },
253
305
  targetBranch: '7.x',
@@ -18,7 +18,7 @@ function getTargetBranches(options, commits) {
18
18
  // automatically backport to specified target branches
19
19
  if (options.ci) {
20
20
  if ((0, lodash_1.isEmpty)(missingTargetBranches)) {
21
- throw new HandledError_1.HandledError(`There are no branches to backport to. Aborting.`);
21
+ throw new HandledError_1.HandledError({ code: 'no-branches-exception' });
22
22
  }
23
23
  return missingTargetBranches;
24
24
  }
@@ -39,11 +39,20 @@ describe('getTargetBranches', () => {
39
39
  };
40
40
  const commits = [
41
41
  {
42
- committedDate: 'aaa',
43
- originalMessage: 'hey',
44
- sha: 'abcd',
42
+ sourceCommit: {
43
+ committedDate: 'aaa',
44
+ message: 'hey',
45
+ sha: 'abcd',
46
+ },
47
+ sourcePullRequest: {
48
+ url: 'foo',
49
+ number: 1337,
50
+ mergeCommit: {
51
+ message: 'hey',
52
+ sha: 'abcd',
53
+ },
54
+ },
45
55
  sourceBranch: '7.x',
46
- pullNumber: 1337,
47
56
  expectedTargetPullRequests: [],
48
57
  },
49
58
  ];
@@ -117,11 +126,20 @@ describe('getTargetBranches', () => {
117
126
  };
118
127
  const commits = [
119
128
  {
120
- committedDate: 'bbb',
129
+ sourceCommit: {
130
+ committedDate: 'bbb',
131
+ message: '[backport] Bump to 5.1.3 (#62286)',
132
+ sha: 'my-sha',
133
+ },
134
+ sourcePullRequest: {
135
+ url: 'foo',
136
+ number: 62286,
137
+ mergeCommit: {
138
+ message: '[backport] Bump to 5.1.3 (#62286)',
139
+ sha: 'my-sha',
140
+ },
141
+ },
121
142
  sourceBranch: 'master',
122
- sha: 'my-sha',
123
- originalMessage: '[backport] Bump to 5.1.3 (#62286)',
124
- pullNumber: 62286,
125
143
  expectedTargetPullRequests: [{ branch: '7.x', state: 'MISSING' }],
126
144
  },
127
145
  ];
@@ -1,24 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.maybeSetupRepo = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const del = require("del");
4
6
  const ora = require("ora");
7
+ const env_1 = require("../services/env");
5
8
  const git_1 = require("../services/git");
6
9
  async function maybeSetupRepo(options) {
7
- const isAlreadyCloned = await (0, git_1.repoExists)(options);
10
+ const repoPath = (0, env_1.getRepoPath)(options);
11
+ const isAlreadyCloned = await getIsRepoCloned(repoPath);
8
12
  // clone repo if folder does not already exists
9
13
  if (!isAlreadyCloned) {
10
14
  const spinner = ora().start();
11
15
  try {
12
- const spinnerCloneText = 'Cloning repository (one-time operation)';
16
+ const sourcePath = await (0, git_1.getSourceRepoPath)(options);
17
+ const sourcePathHumanReadable = sourcePath.includes(options.gitHostname)
18
+ ? options.gitHostname
19
+ : sourcePath;
20
+ const spinnerCloneText = `Cloning repository from ${sourcePathHumanReadable} (one-time operation)`;
13
21
  spinner.text = `0% ${spinnerCloneText}`;
14
- await (0, git_1.cloneRepo)(options, (progress) => {
22
+ await (0, git_1.cloneRepo)({ sourcePath, targetPath: repoPath }, (progress) => {
15
23
  spinner.text = `${progress}% ${spinnerCloneText}`;
16
24
  });
17
25
  spinner.succeed(`100% ${spinnerCloneText}`);
18
26
  }
19
27
  catch (e) {
20
28
  spinner.fail();
21
- await (0, git_1.deleteRepo)(options);
29
+ await del(repoPath);
22
30
  throw e;
23
31
  }
24
32
  }
@@ -27,10 +35,22 @@ async function maybeSetupRepo(options) {
27
35
  // ensure remote are setup with latest accessToken
28
36
  await (0, git_1.deleteRemote)(options, options.authenticatedUsername);
29
37
  await (0, git_1.addRemote)(options, options.authenticatedUsername);
30
- // update remote for origin (if the above is a fork)
38
+ // add remote for non-fork repo (if the above is a fork)
31
39
  if (options.authenticatedUsername !== options.repoOwner) {
32
40
  await (0, git_1.deleteRemote)(options, options.repoOwner);
33
41
  await (0, git_1.addRemote)(options, options.repoOwner);
34
42
  }
35
43
  }
36
44
  exports.maybeSetupRepo = maybeSetupRepo;
45
+ async function getIsRepoCloned(path) {
46
+ try {
47
+ const stats = await (0, promises_1.stat)(path);
48
+ return stats.isDirectory();
49
+ }
50
+ catch (e) {
51
+ if (e.code === 'ENOENT') {
52
+ return false;
53
+ }
54
+ throw e;
55
+ }
56
+ }
@@ -22,12 +22,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const promises_1 = require("fs/promises");
25
26
  const os_1 = __importDefault(require("os"));
26
27
  const del_1 = __importDefault(require("del"));
27
- const makeDir = require("make-dir");
28
28
  const childProcess = __importStar(require("../services/child-process-promisified"));
29
- const fs = __importStar(require("../services/fs-promisified"));
29
+ const git = __importStar(require("../services/git"));
30
+ const mocks_1 = require("../test/mocks");
30
31
  const maybeSetupRepo_1 = require("./maybeSetupRepo");
32
+ const fs = { stat: promises_1.stat };
31
33
  describe('maybeSetupRepo', () => {
32
34
  let execSpy;
33
35
  beforeEach(() => {
@@ -36,33 +38,110 @@ describe('maybeSetupRepo', () => {
36
38
  .spyOn(childProcess, 'exec')
37
39
  .mockResolvedValue({ stderr: '', stdout: '' });
38
40
  });
39
- it('should delete repo if an error occurs', async () => {
40
- expect.assertions(2);
41
- makeDir.mockImplementationOnce(() => {
42
- throw new Error('makeDir failed');
41
+ afterEach(() => {
42
+ jest.restoreAllMocks();
43
+ });
44
+ describe('if an error occurs while cloning', () => {
45
+ it('should delete repo', async () => {
46
+ expect.assertions(2);
47
+ execSpy = jest
48
+ .spyOn(childProcess, 'execAsCallback')
49
+ .mockImplementation((cmd) => {
50
+ if (cmd.startsWith('git clone')) {
51
+ throw new Error('Simulated git clone failure');
52
+ }
53
+ throw new Error('unknown error');
54
+ });
55
+ await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
56
+ repoName: 'kibana',
57
+ repoOwner: 'elastic',
58
+ })).rejects.toThrowError('Simulated git clone failure');
59
+ expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
60
+ });
61
+ });
62
+ describe('while cloning the repo', () => {
63
+ it('updates the progress', async () => {
64
+ let onCloneComplete;
65
+ let dataHandler;
66
+ const oraMock = (0, mocks_1.getOraMock)();
67
+ const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
68
+ const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
69
+ jest
70
+ .spyOn(git, 'getSourceRepoPath')
71
+ .mockResolvedValue('/path/to/source/repo');
72
+ jest
73
+ .spyOn(childProcess, 'execAsCallback')
74
+ //@ts-expect-error
75
+ .mockImplementation((cmdString, cmdOptions, onComplete) => {
76
+ // callback should be called to finalize the operation
77
+ if (onComplete) {
78
+ //@ts-expect-error
79
+ onCloneComplete = onComplete;
80
+ }
81
+ return {
82
+ stderr: {
83
+ on: (name, handler) => {
84
+ dataHandler = handler;
85
+ },
86
+ },
87
+ };
88
+ });
89
+ setTimeout(() => {
90
+ dataHandler('Receiving objects: 1%');
91
+ dataHandler('Receiving objects: 10%');
92
+ dataHandler('Receiving objects: 20%');
93
+ dataHandler('Receiving objects: 100%');
94
+ dataHandler('Updating files: 1%');
95
+ dataHandler('Updating files: 10%');
96
+ dataHandler('Updating files: 20%');
97
+ dataHandler('Updating files: 100%');
98
+ onCloneComplete();
99
+ }, 50);
100
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
101
+ repoName: 'kibana',
102
+ repoOwner: 'elastic',
103
+ });
104
+ expect(spinnerTextSpy.mock.calls.map((call) => call[0]))
105
+ .toMatchInlineSnapshot(`
106
+ Array [
107
+ "0% Cloning repository from /path/to/source/repo (one-time operation)",
108
+ "1% Cloning repository from /path/to/source/repo (one-time operation)",
109
+ "9% Cloning repository from /path/to/source/repo (one-time operation)",
110
+ "18% Cloning repository from /path/to/source/repo (one-time operation)",
111
+ "90% Cloning repository from /path/to/source/repo (one-time operation)",
112
+ "90% Cloning repository from /path/to/source/repo (one-time operation)",
113
+ "91% Cloning repository from /path/to/source/repo (one-time operation)",
114
+ "92% Cloning repository from /path/to/source/repo (one-time operation)",
115
+ "100% Cloning repository from /path/to/source/repo (one-time operation)",
116
+ ]
117
+ `);
118
+ expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
43
119
  });
44
- await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
45
- accessToken: 'myAccessToken',
46
- gitHostname: 'github.com',
47
- repoName: 'kibana',
48
- repoOwner: 'elastic',
49
- })).rejects.toThrowError('makeDir failed');
50
- expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
51
120
  });
52
121
  describe('if repo already exists', () => {
53
122
  beforeEach(() => {
54
123
  // @ts-expect-error
55
124
  jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
125
+ jest
126
+ .spyOn(childProcess, 'execAsCallback')
127
+ //@ts-expect-error
128
+ .mockImplementation((cmdString, cmdOptions, callback) => {
129
+ //@ts-expect-error
130
+ callback();
131
+ return {
132
+ stderr: { on: () => null },
133
+ };
134
+ });
56
135
  });
57
136
  it('should re-create remotes for both source repo and fork', async () => {
58
137
  await (0, maybeSetupRepo_1.maybeSetupRepo)({
59
138
  accessToken: 'myAccessToken',
60
139
  authenticatedUsername: 'sqren_authenticated',
61
- gitHostname: 'github.com',
62
140
  repoName: 'kibana',
63
141
  repoOwner: 'elastic',
64
142
  });
65
143
  expect(execSpy.mock.calls.map(([cmd]) => cmd)).toEqual([
144
+ 'git remote --verbose',
66
145
  'git remote rm origin',
67
146
  'git remote rm sqren_authenticated',
68
147
  'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
@@ -71,4 +150,55 @@ describe('maybeSetupRepo', () => {
71
150
  ]);
72
151
  });
73
152
  });
153
+ describe('if repo does not exists locally', () => {
154
+ beforeEach(() => {
155
+ // @ts-expect-error
156
+ jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
157
+ jest
158
+ .spyOn(childProcess, 'execAsCallback')
159
+ //@ts-expect-error
160
+ .mockImplementation((cmdString, cmdOptions, callback) => {
161
+ //@ts-expect-error
162
+ callback();
163
+ return {
164
+ stderr: { on: () => null },
165
+ };
166
+ });
167
+ });
168
+ it('should clone it from github.com', async () => {
169
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
170
+ accessToken: 'myAccessToken',
171
+ gitHostname: 'github.com',
172
+ repoName: 'kibana',
173
+ repoOwner: 'elastic',
174
+ });
175
+ expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
176
+ });
177
+ });
178
+ describe('if repo does exist locally', () => {
179
+ beforeEach(() => {
180
+ // @ts-expect-error
181
+ jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
182
+ jest
183
+ .spyOn(git, 'getSourceRepoPath')
184
+ .mockResolvedValue('/path/to/source/repo');
185
+ jest
186
+ .spyOn(childProcess, 'execAsCallback')
187
+ //@ts-expect-error
188
+ .mockImplementation((cmdString, cmdOptions, callback) => {
189
+ //@ts-expect-error
190
+ callback();
191
+ return {
192
+ stderr: { on: () => null },
193
+ };
194
+ });
195
+ });
196
+ it('should clone it from local folder', async () => {
197
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
198
+ repoName: 'kibana',
199
+ repoOwner: 'elastic',
200
+ });
201
+ expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone /path/to/source/repo /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
202
+ });
203
+ });
74
204
  });
@@ -0,0 +1 @@
1
+ export declare function maybe<T>(value: T): T | undefined;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybe = void 0;
4
+ function maybe(value) {
5
+ return value;
6
+ }
7
+ exports.maybe = maybe;
@@ -0,0 +1 @@
1
+ export declare const PACKAGE_VERSION = "6.2.1";
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PACKAGE_VERSION = void 0;
4
+ exports.PACKAGE_VERSION = '6.2.1';
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "6.1.5",
17
+ "version": "6.3.0-beta-2",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {
@@ -22,14 +22,18 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "scripts": {
25
- "lint": "tsc --project ./tsconfig.test.json && eslint './**/*.{ts,js}'",
26
- "prepare": "husky install",
27
25
  "postinstall": "test -f ./dist/scripts/runPostinstall.js && node ./dist/scripts/runPostinstall.js || echo 'Dist folder missing'",
28
- "prepublishOnly": "tsc --project ./tsconfig.prod.json",
29
- "test": "jest",
30
- "test-private": "jest --config ./jest.config.private.js",
26
+ "postversion": "yarn extractPackageVersion && yarn build",
27
+ "prepare": "husky install",
28
+ "prepublishOnly": "yarn build",
29
+ "build": "tsc --project ./tsconfig.prod.json",
30
+ "extractPackageVersion": "node -p \"'export const PACKAGE_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" | prettier > src/utils/packageVersion.ts",
31
+ "lint": "tsc --project ./tsconfig.test.json && eslint './**/*.{ts,js}'",
32
+ "start": "ts-node --transpile-only ./src/entrypoint.cli.ts",
31
33
  "test-all": "yarn lint && jest --config ./jest.config.all.js",
32
- "start": "ts-node --transpile-only ./src/entrypoint.cli.ts"
34
+ "test-mutation": "jest --config ./jest.config.mutation.js",
35
+ "test-private": "jest --config ./jest.config.private.js",
36
+ "test": "jest"
33
37
  },
34
38
  "lint-staged": {
35
39
  "*.ts": [
@@ -59,7 +63,7 @@
59
63
  },
60
64
  "dependencies": {
61
65
  "@octokit/rest": "^18.12.0",
62
- "axios": "^0.24.0",
66
+ "axios": "^0.25.0",
63
67
  "dedent": "^0.7.0",
64
68
  "del": "^6.0.0",
65
69
  "find-up": "^5.0.0",
@@ -71,38 +75,38 @@
71
75
  "strip-json-comments": "^3.1.1",
72
76
  "terminal-link": "^2.1.1",
73
77
  "utility-types": "^3.10.0",
74
- "winston": "^3.3.3",
78
+ "winston": "^3.5.1",
75
79
  "yargs": "^17.3.1"
76
80
  },
77
81
  "devDependencies": {
78
82
  "@types/core-js": "^2.5.5",
79
83
  "@types/dedent": "^0.7.0",
80
- "@types/inquirer": "^8.1.3",
84
+ "@types/inquirer": "^8.2.0",
81
85
  "@types/jest": "^27.4.0",
82
86
  "@types/lodash": "^4.14.178",
83
- "@types/node": "^16.11.17",
87
+ "@types/node": "^17.0.8",
84
88
  "@types/safe-json-stringify": "^1.1.2",
85
89
  "@types/yargs": "^17.0.8",
86
90
  "@types/yargs-parser": "^20.2.1",
87
- "@typescript-eslint/eslint-plugin": "^5.9.0",
88
- "@typescript-eslint/parser": "^5.9.0",
89
- "eslint": "^8.6.0",
91
+ "@typescript-eslint/eslint-plugin": "^5.10.2",
92
+ "@typescript-eslint/parser": "^5.10.2",
93
+ "eslint": "^8.8.0",
90
94
  "eslint-config-prettier": "^8.3.0",
91
95
  "eslint-plugin-import": "^2.25.4",
92
- "eslint-plugin-jest": "^25.3.4",
96
+ "eslint-plugin-jest": "^26.0.0",
93
97
  "eslint-plugin-prettier": "^4.0.0",
94
- "graphql": "^16.2.0",
98
+ "graphql": "^16.3.0",
95
99
  "graphql-config": "^4.1.0",
96
100
  "graphql-tag": "^2.12.6",
97
101
  "husky": "^7.0.4",
98
102
  "jest": "^27.4.7",
99
103
  "jest-snapshot-serializer-ansi": "^1.0.0",
100
- "lint-staged": "^12.1.7",
101
- "nock": "^13.2.1",
104
+ "lint-staged": "^12.3.3",
105
+ "nock": "^13.2.4",
102
106
  "prettier": "^2.5.1",
103
107
  "strip-ansi": "^6.0.1",
104
- "ts-jest": "^27.1.2",
108
+ "ts-jest": "^27.1.3",
105
109
  "ts-node": "^10.4.0",
106
- "typescript": "^4.5.4"
110
+ "typescript": "^4.5.5"
107
111
  }
108
112
  }