backport 8.3.0-beta.1 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/dist/backportRun.js +1 -1
  2. package/dist/entrypoint.module.d.ts +2 -2
  3. package/dist/entrypoint.module.js +2 -0
  4. package/dist/entrypoint.module.private.test.js +11 -10
  5. package/dist/lib/child-process-promisified.js +2 -2
  6. package/dist/lib/getCommits.js +1 -1
  7. package/dist/lib/git.js +3 -1
  8. package/dist/lib/git.test.js +26 -0
  9. package/dist/lib/github/v3/createStatusComment.js +3 -2
  10. package/dist/lib/github/v3/createStatusComment.test.js +61 -0
  11. package/dist/lib/github/v4/apiRequestV4.js +1 -1
  12. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +2 -1
  13. package/dist/{entrypoint.cli.private.test.d.ts → lib/github/v4/enablePullRequestAutoMerge.mutation.test.d.ts} +0 -0
  14. package/dist/lib/github/v4/{enablePullRequestAutoMerge.private.test.js → enablePullRequestAutoMerge.mutation.test.js} +34 -8
  15. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +5 -3
  16. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -1
  17. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +0 -1
  18. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +5 -6
  19. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +7 -3
  20. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +2 -0
  21. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +23 -7
  22. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
  23. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -0
  24. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +2 -0
  25. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +1 -0
  26. package/dist/lib/github/v4/getOptionsFromGithub/query.js +1 -0
  27. package/dist/lib/remoteConfig.d.ts +1 -1
  28. package/dist/lib/remoteConfig.js +4 -0
  29. package/dist/options/ConfigOptions.d.ts +1 -0
  30. package/dist/options/cliArgs.d.ts +3 -2
  31. package/dist/options/cliArgs.js +21 -6
  32. package/dist/options/config/config.d.ts +1 -0
  33. package/dist/options/config/readConfigFile.d.ts +1 -0
  34. package/dist/options/options.d.ts +5 -2
  35. package/dist/options/options.js +1 -1
  36. package/dist/options/options.test.js +3 -0
  37. package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/date-filters.private.test.d.ts} +0 -0
  38. package/dist/test/e2e/cli/date-filters.private.test.js +47 -0
  39. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +4 -18
  40. package/dist/utils/packageVersion.d.ts +1 -1
  41. package/dist/utils/packageVersion.js +1 -1
  42. package/package.json +14 -15
  43. package/yarn.lock +165 -171
  44. package/dist/entrypoint.cli.private.test.js +0 -47
  45. package/dist/errors/BackportError.d.ts +0 -19
  46. package/dist/errors/BackportError.js +0 -29
  47. package/dist/runSequentially.test.d.ts +0 -1
  48. package/dist/runSequentially.test.js +0 -243
  49. package/dist/services/BackportError.d.ts +0 -19
  50. package/dist/services/BackportError.js +0 -29
  51. package/dist/services/HandledBackportError.d.ts +0 -19
  52. package/dist/services/HandledBackportError.js +0 -29
  53. package/dist/services/HandledError.d.ts +0 -19
  54. package/dist/services/HandledError.js +0 -29
  55. package/dist/services/child-process-promisified.d.ts +0 -25
  56. package/dist/services/child-process-promisified.js +0 -58
  57. package/dist/services/env.d.ts +0 -7
  58. package/dist/services/env.js +0 -30
  59. package/dist/services/env.test.d.ts +0 -1
  60. package/dist/services/env.test.js +0 -21
  61. package/dist/services/git.d.ts +0 -77
  62. package/dist/services/git.integration.test.d.ts +0 -1
  63. package/dist/services/git.integration.test.js +0 -616
  64. package/dist/services/git.js +0 -439
  65. package/dist/services/git.private.test.d.ts +0 -1
  66. package/dist/services/git.private.test.js +0 -618
  67. package/dist/services/git.test.d.ts +0 -1
  68. package/dist/services/git.test.js +0 -580
  69. package/dist/services/github/commitFormatters.d.ts +0 -3
  70. package/dist/services/github/commitFormatters.js +0 -17
  71. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  72. package/dist/services/github/commitFormatters.test.js +0 -11
  73. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  74. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  75. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  76. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  77. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  78. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  79. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  80. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  81. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  82. package/dist/services/github/v3/createPullRequest.js +0 -91
  83. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  84. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  85. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  86. package/dist/services/github/v3/createStatusComment.js +0 -131
  87. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  88. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  89. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  90. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  91. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  92. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  93. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  94. package/dist/services/github/v4/apiRequestV4.js +0 -71
  95. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  96. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  97. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  98. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  99. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  100. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  101. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  102. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  103. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  104. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  105. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  106. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  108. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  110. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  111. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  112. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  113. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  114. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  115. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  116. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  117. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  118. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  119. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  120. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  121. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  122. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  123. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  124. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  125. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  126. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  127. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  128. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  129. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  130. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  131. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  132. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  133. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  134. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  135. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  136. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  137. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  138. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  139. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  140. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  141. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  142. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  143. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  144. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  145. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  146. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  147. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  148. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  149. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  150. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  151. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  152. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  153. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  154. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  155. package/dist/services/logger.d.ts +0 -9
  156. package/dist/services/logger.js +0 -74
  157. package/dist/services/prompt.test.d.ts +0 -1
  158. package/dist/services/prompt.test.js +0 -139
  159. package/dist/services/prompts.d.ts +0 -17
  160. package/dist/services/prompts.js +0 -132
  161. package/dist/services/remoteConfig.d.ts +0 -20
  162. package/dist/services/remoteConfig.js +0 -52
  163. package/dist/services/sequentially.d.ts +0 -1
  164. package/dist/services/sequentially.js +0 -10
  165. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  166. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  167. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  168. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  169. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  170. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  171. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  172. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  173. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  174. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  175. package/dist/services/test.d.ts +0 -1
  176. package/dist/services/test.js +0 -23
  177. package/dist/state.d.ts +0 -0
  178. package/dist/state.js +0 -1
  179. package/dist/test/ExecError.d.ts +0 -16
  180. package/dist/test/ExecError.js +0 -15
  181. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  182. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  183. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  184. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  185. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  186. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  187. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  188. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  189. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  190. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  191. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  192. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  193. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  194. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  195. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  196. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  197. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  199. package/dist/ui/getCommits.d.ts +0 -2
  200. package/dist/ui/getCommits.js +0 -75
  201. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  202. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  203. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  204. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  205. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  206. package/dist/ui/getGitConfigAuthor.js +0 -15
  207. package/dist/ui/getTargetBranches.d.ts +0 -5
  208. package/dist/ui/getTargetBranches.js +0 -67
  209. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  210. package/dist/ui/getTargetBranches.test.js +0 -204
  211. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  212. package/dist/ui/maybeSetupRepo.js +0 -53
  213. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  214. package/dist/ui/maybeSetupRepo.test.js +0 -238
  215. package/dist/ui/ora.d.ts +0 -2
  216. package/dist/ui/ora.js +0 -21
  217. package/dist/ui/setupRepo.d.ts +0 -2
  218. package/dist/ui/setupRepo.js +0 -56
  219. package/dist/ui/setupRepo.test.d.ts +0 -1
  220. package/dist/ui/setupRepo.test.js +0 -273
  221. package/dist/utils/filterMissingCommits.d.ts +0 -2
  222. package/dist/utils/filterMissingCommits.js +0 -7
  223. package/dist/utils/redact.d.ts +0 -1
  224. package/dist/utils/redact.js +0 -7
@@ -1,439 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getGitConfig = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
4
- const path_1 = require("path");
5
- const lodash_1 = require("lodash");
6
- const ora_1 = require("../ui/ora");
7
- const filterEmpty_1 = require("../utils/filterEmpty");
8
- const BackportError_1 = require("./BackportError");
9
- const child_process_promisified_1 = require("./child-process-promisified");
10
- const env_1 = require("./env");
11
- const commitFormatters_1 = require("./github/commitFormatters");
12
- const logger_1 = require("./logger");
13
- function getRemoteUrl({ repoName, accessToken, gitHostname = 'github.com' }, repoOwner) {
14
- return `https://x-access-token:${accessToken}@${gitHostname}/${repoOwner}/${repoName}.git`;
15
- }
16
- exports.getRemoteUrl = getRemoteUrl;
17
- async function cloneRepo({ sourcePath, targetPath }, onProgress) {
18
- return new Promise((resolve, reject) => {
19
- const subprocess = (0, child_process_promisified_1.spawnOriginal)('git', [
20
- 'clone',
21
- sourcePath,
22
- targetPath,
23
- '--progress',
24
- ]);
25
- const progress = {
26
- fileUpdate: 0,
27
- objectReceive: 0,
28
- };
29
- subprocess.on('error', (err) => reject(err));
30
- subprocess.stderr.on('data', (data) => {
31
- logger_1.logger.verbose(data);
32
- const [, objectReceiveProgress] = data.toString().match(/^Receiving objects:\s+(\d+)%/) || [];
33
- if (objectReceiveProgress) {
34
- progress.objectReceive = parseInt(objectReceiveProgress, 10);
35
- }
36
- const [, fileUpdateProgress] = data.toString().match(/^Updating files:\s+(\d+)%/) || [];
37
- if (fileUpdateProgress) {
38
- progress.objectReceive = 100;
39
- progress.fileUpdate = parseInt(fileUpdateProgress, 10);
40
- }
41
- const progressSum = Math.round(progress.fileUpdate * 0.1 + progress.objectReceive * 0.9);
42
- if (progressSum > 0) {
43
- onProgress(progressSum);
44
- }
45
- });
46
- subprocess.on('close', (code) => {
47
- if (code === 0 || code === null) {
48
- resolve();
49
- }
50
- else {
51
- reject(new Error(`Git clone failed with exit code: ${code}`));
52
- }
53
- });
54
- });
55
- }
56
- exports.cloneRepo = cloneRepo;
57
- async function getLocalConfigFileCommitDate({ cwd }) {
58
- try {
59
- const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'log', '-1', '--format=%cd', '.backportrc.json'], cwd);
60
- const timestamp = Date.parse(stdout);
61
- if (timestamp > 0) {
62
- return timestamp;
63
- }
64
- }
65
- catch (e) {
66
- return;
67
- }
68
- }
69
- exports.getLocalConfigFileCommitDate = getLocalConfigFileCommitDate;
70
- async function isLocalConfigFileUntracked({ cwd }) {
71
- try {
72
- // list untracked files
73
- const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['ls-files', '.backportrc.json', '--exclude-standard', '--others'], cwd);
74
- return !!stdout;
75
- }
76
- catch (e) {
77
- return;
78
- }
79
- }
80
- exports.isLocalConfigFileUntracked = isLocalConfigFileUntracked;
81
- async function isLocalConfigFileModified({ cwd }) {
82
- try {
83
- const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'diff', 'HEAD', '--name-only', '.backportrc.json'], cwd);
84
- return !!stdout;
85
- }
86
- catch (e) {
87
- return false;
88
- }
89
- }
90
- exports.isLocalConfigFileModified = isLocalConfigFileModified;
91
- async function getRepoInfoFromGitRemotes({ cwd }) {
92
- try {
93
- const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['remote', '--verbose'], cwd);
94
- const remotes = stdout
95
- .split('\n')
96
- .map((line) => {
97
- const match = line.match(/github.com[/|:](.+?)(.git)? \((fetch|push)\)/);
98
- return match?.[1];
99
- })
100
- .filter(filterEmpty_1.filterNil);
101
- return (0, lodash_1.uniq)(remotes).map((remote) => {
102
- const [repoOwner, repoName] = remote.split('/');
103
- return { repoOwner, repoName };
104
- });
105
- }
106
- catch (e) {
107
- return [];
108
- }
109
- }
110
- exports.getRepoInfoFromGitRemotes = getRepoInfoFromGitRemotes;
111
- async function getGitProjectRootPath(dir) {
112
- try {
113
- const cwd = dir;
114
- const { stdout } = await (0, child_process_promisified_1.spawnPromise)('git', ['rev-parse', '--show-toplevel'], cwd);
115
- return stdout.trim();
116
- }
117
- catch (e) {
118
- logger_1.logger.error('An error occurred while retrieving git project root', e);
119
- return;
120
- }
121
- }
122
- exports.getGitProjectRootPath = getGitProjectRootPath;
123
- async function getIsCommitInBranch(options, commitSha) {
124
- try {
125
- const cwd = (0, env_1.getRepoPath)(options);
126
- await (0, child_process_promisified_1.spawnPromise)('git', ['merge-base', '--is-ancestor', commitSha, 'HEAD'], cwd);
127
- return true;
128
- }
129
- catch (e) {
130
- const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
131
- if (isSpawnError) {
132
- const commitNotInBranch = e.context.code === 1 && e.context.stderr === '';
133
- const commitNotExist = e.context.code === 128 &&
134
- e.context.stderr.includes('Not a valid object name');
135
- if (commitNotInBranch || commitNotExist) {
136
- return false;
137
- }
138
- }
139
- throw e;
140
- }
141
- }
142
- exports.getIsCommitInBranch = getIsCommitInBranch;
143
- async function deleteRemote(options, remoteName) {
144
- try {
145
- const cwd = (0, env_1.getRepoPath)(options);
146
- await (0, child_process_promisified_1.spawnPromise)('git', ['remote', 'rm', remoteName], cwd);
147
- }
148
- catch (e) {
149
- const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
150
- if (isSpawnError &&
151
- e.context.code > 0 &&
152
- e.context.stderr.includes('No such remote')) {
153
- return;
154
- }
155
- // re-throw
156
- throw e;
157
- }
158
- }
159
- exports.deleteRemote = deleteRemote;
160
- async function addRemote(options, remoteName) {
161
- try {
162
- const cwd = (0, env_1.getRepoPath)(options);
163
- await (0, child_process_promisified_1.spawnPromise)('git', ['remote', 'add', remoteName, getRemoteUrl(options, remoteName)], cwd);
164
- }
165
- catch (e) {
166
- // note: swallowing error
167
- return;
168
- }
169
- }
170
- exports.addRemote = addRemote;
171
- async function fetchBranch(options, branch) {
172
- const cwd = (0, env_1.getRepoPath)(options);
173
- await (0, child_process_promisified_1.spawnPromise)('git', ['fetch', options.repoOwner, `${branch}:${branch}`, '--force'], cwd);
174
- }
175
- exports.fetchBranch = fetchBranch;
176
- async function getIsMergeCommit(options, sha) {
177
- const cwd = (0, env_1.getRepoPath)(options);
178
- const res = await (0, child_process_promisified_1.spawnPromise)('git', ['rev-list', '-1', '--merges', `${sha}~1..${sha}`], cwd);
179
- return res.stdout !== '';
180
- }
181
- exports.getIsMergeCommit = getIsMergeCommit;
182
- async function getCommitsInMergeCommit(options, sha) {
183
- try {
184
- const cwd = (0, env_1.getRepoPath)(options);
185
- const res = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'log', `${sha}^1..${sha}^2`, '--pretty=format:%H'], cwd);
186
- return res.stdout.split('\n');
187
- }
188
- catch (e) {
189
- const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
190
- // swallow error
191
- if (isSpawnError && e.context.code === 128) {
192
- return [];
193
- }
194
- throw e;
195
- }
196
- }
197
- exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
198
- async function getShaOrRange(options, sha) {
199
- if (!options.mainline) {
200
- try {
201
- const isMergeCommit = await getIsMergeCommit(options, sha);
202
- if (isMergeCommit) {
203
- const shas = await getCommitsInMergeCommit(options, sha);
204
- return `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
205
- }
206
- }
207
- catch (e) {
208
- const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
209
- // swallow error if it's a 128 exit code
210
- // exit 128 happens when the cherrypicked commit is empty which is handled below
211
- // (128 also applies to many other types of errors)
212
- if (!isSpawnError || e.context.code !== 128) {
213
- throw e;
214
- }
215
- }
216
- }
217
- return sha;
218
- }
219
- async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }) {
220
- const shaOrRange = await getShaOrRange(options, sha);
221
- const cmdArgs = [
222
- '-c',
223
- `user.name="${commitAuthor.name}"`,
224
- '-c',
225
- `user.email="${commitAuthor.email}"`,
226
- `cherry-pick`,
227
- ...(options.mainline != undefined
228
- ? ['--mainline', `${options.mainline}`]
229
- : []),
230
- ...(options.cherrypickRef === false ? [] : ['-x']),
231
- shaOrRange,
232
- ];
233
- try {
234
- const cwd = (0, env_1.getRepoPath)(options);
235
- await (0, child_process_promisified_1.spawnPromise)('git', cmdArgs, cwd);
236
- return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
237
- }
238
- catch (e) {
239
- const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
240
- if (isSpawnError) {
241
- // missing `mainline` option
242
- if (e.message.includes('is a merge but no -m option was given')) {
243
- throw new BackportError_1.BackportError('Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the `mainline` argument:\n\n> backport --mainline\n\nor:\n\n> backport --mainline <parent-number>\n\nOr refer to the git documentation for more information: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt---mainlineparent-number');
244
- }
245
- // commit was already backported
246
- if (e.message.includes('The previous cherry-pick is now empty')) {
247
- const shortSha = (0, commitFormatters_1.getShortSha)(sha);
248
- throw new BackportError_1.BackportError(`Cherrypick failed because the selected commit (${shortSha}) is empty. ${mergedTargetPullRequest?.url
249
- ? `It looks like the commit was already backported in ${mergedTargetPullRequest.url}`
250
- : 'Did you already backport this commit? '}`);
251
- }
252
- if (e.message.includes(`bad object ${sha}`)) {
253
- throw new BackportError_1.BackportError(`Cherrypick failed because commit "${sha}" was not found`);
254
- }
255
- const isCherryPickError = e.context.cmdArgs.includes('cherry-pick') && e.context.code > 0;
256
- if (isCherryPickError) {
257
- const [conflictingFiles, unstagedFiles] = await Promise.all([
258
- getConflictingFiles(options),
259
- getUnstagedFiles(options),
260
- ]);
261
- if (!(0, lodash_1.isEmpty)(conflictingFiles) || !(0, lodash_1.isEmpty)(unstagedFiles))
262
- return { conflictingFiles, unstagedFiles, needsResolving: true };
263
- }
264
- }
265
- // re-throw error if it didn't match the handled cases above
266
- throw e;
267
- }
268
- }
269
- exports.cherrypick = cherrypick;
270
- async function commitChanges(commit, options) {
271
- const noVerifyFlag = options.noVerify ? ['--no-verify'] : [];
272
- const cwd = (0, env_1.getRepoPath)(options);
273
- try {
274
- await (0, child_process_promisified_1.spawnPromise)('git', [
275
- 'commit',
276
- '--no-edit',
277
- ...noVerifyFlag, // bypass pre-commit and commit-msg hooks
278
- ], cwd);
279
- }
280
- catch (e) {
281
- const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
282
- if (isSpawnError) {
283
- if (e.context.stdout.includes('nothing to commit')) {
284
- logger_1.logger.info(`Could not run "git commit". Probably because the changes were manually committed`, e);
285
- return;
286
- }
287
- // manually set the commit message if the inferred commit message is empty
288
- // this can happen if the user runs `git reset HEAD` and thereby aborts the cherrypick process
289
- if (e.context.stderr.includes('Aborting commit due to empty commit message')) {
290
- await (0, child_process_promisified_1.spawnPromise)('git', [
291
- 'commit',
292
- `--message=${commit.sourceCommit.message}`,
293
- ...noVerifyFlag, // bypass pre-commit and commit-msg hooks
294
- ], cwd);
295
- return;
296
- }
297
- }
298
- // rethrow error if it can't be handled
299
- throw e;
300
- }
301
- }
302
- exports.commitChanges = commitChanges;
303
- async function getConflictingFiles(options) {
304
- const repoPath = (0, env_1.getRepoPath)(options);
305
- try {
306
- const cwd = repoPath;
307
- await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'diff', '--check'], cwd);
308
- return [];
309
- }
310
- catch (e) {
311
- const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
312
- const isConflictError = isSpawnError && e.context.code === 2;
313
- if (isConflictError) {
314
- const files = e.context.stdout
315
- .split('\n')
316
- .filter((line) => !!line.trim() && !line.startsWith('+') && !line.startsWith('-'))
317
- .map((line) => {
318
- const posSeparator = line.indexOf(':');
319
- const filename = line.slice(0, posSeparator).trim();
320
- return filename;
321
- });
322
- const uniqueFiles = (0, lodash_1.uniq)(files);
323
- return uniqueFiles.map((file) => {
324
- return {
325
- absolute: (0, path_1.resolve)(repoPath, file),
326
- relative: file,
327
- };
328
- });
329
- }
330
- // rethrow error since it's unrelated
331
- throw e;
332
- }
333
- }
334
- exports.getConflictingFiles = getConflictingFiles;
335
- // retrieve the list of files that could not be cleanly merged
336
- async function getUnstagedFiles(options) {
337
- const repoPath = (0, env_1.getRepoPath)(options);
338
- const cwd = repoPath;
339
- const res = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'diff', '--name-only'], cwd);
340
- const files = res.stdout
341
- .split('\n')
342
- .filter((file) => !!file)
343
- .map((file) => (0, path_1.resolve)(repoPath, file));
344
- return (0, lodash_1.uniq)(files);
345
- }
346
- exports.getUnstagedFiles = getUnstagedFiles;
347
- async function getGitConfig({ dir, key, }) {
348
- try {
349
- const cwd = dir;
350
- const res = await (0, child_process_promisified_1.spawnPromise)('git', ['config', key], cwd);
351
- return res.stdout.trim();
352
- }
353
- catch (e) {
354
- return;
355
- }
356
- }
357
- exports.getGitConfig = getGitConfig;
358
- // How the commit flows:
359
- // ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
360
- // master -> backport/7.x/pr-1234 -> 7.x
361
- async function createBackportBranch({ options, targetBranch, backportBranch, }) {
362
- const spinner = (0, ora_1.ora)(options.ci, 'Pulling latest changes').start();
363
- try {
364
- const cwd = (0, env_1.getRepoPath)(options);
365
- await (0, child_process_promisified_1.spawnPromise)('git', ['reset', '--hard'], cwd);
366
- await (0, child_process_promisified_1.spawnPromise)('git', ['clean', '-d', '--force'], cwd);
367
- await (0, child_process_promisified_1.spawnPromise)('git', ['fetch', options.repoOwner, targetBranch], cwd);
368
- await (0, child_process_promisified_1.spawnPromise)('git', [
369
- 'checkout',
370
- '-B',
371
- backportBranch,
372
- `${options.repoOwner}/${targetBranch}`,
373
- '--no-track',
374
- ], cwd);
375
- spinner.succeed();
376
- }
377
- catch (e) {
378
- spinner.fail();
379
- if (e instanceof child_process_promisified_1.SpawnError) {
380
- const isBranchInvalid = e.context.stderr.toLowerCase().includes(`couldn't find remote ref`) ||
381
- e.context.stderr.toLowerCase().includes(`invalid refspec`) ||
382
- e.context.stderr
383
- .toLowerCase()
384
- .includes(`is not a commit and a branch '${backportBranch}' cannot be created from it`);
385
- if (isBranchInvalid) {
386
- throw new BackportError_1.BackportError(`The branch "${targetBranch}" is invalid or doesn't exist`);
387
- }
388
- }
389
- throw e;
390
- }
391
- }
392
- exports.createBackportBranch = createBackportBranch;
393
- async function deleteBackportBranch({ options, backportBranch, }) {
394
- const spinner = (0, ora_1.ora)(options.ci).start();
395
- const cwd = (0, env_1.getRepoPath)(options);
396
- await (0, child_process_promisified_1.spawnPromise)('git', ['reset', '--hard'], cwd);
397
- await (0, child_process_promisified_1.spawnPromise)('git', ['checkout', options.sourceBranch], cwd);
398
- await (0, child_process_promisified_1.spawnPromise)('git', ['branch', '--delete', '--force', backportBranch], cwd);
399
- spinner.stop();
400
- }
401
- exports.deleteBackportBranch = deleteBackportBranch;
402
- /*
403
- * Returns the repo owner of the forked repo or the source repo
404
- */
405
- function getRepoForkOwner(options) {
406
- return options.fork ? options.repoForkOwner : options.repoOwner;
407
- }
408
- exports.getRepoForkOwner = getRepoForkOwner;
409
- async function pushBackportBranch({ options, backportBranch, }) {
410
- const repoForkOwner = getRepoForkOwner(options);
411
- const spinner = (0, ora_1.ora)(options.ci, `Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
412
- try {
413
- const cwd = (0, env_1.getRepoPath)(options);
414
- const res = await (0, child_process_promisified_1.spawnPromise)('git', ['push', repoForkOwner, `${backportBranch}:${backportBranch}`, '--force'], cwd);
415
- spinner.succeed();
416
- return res;
417
- }
418
- catch (e) {
419
- spinner.fail();
420
- if (e instanceof child_process_promisified_1.SpawnError &&
421
- e.context.stderr.toLowerCase().includes(`repository not found`)) {
422
- throw new BackportError_1.BackportError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode via "--no-fork".\nRead more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/configuration.md#fork`);
423
- }
424
- if (e instanceof child_process_promisified_1.SpawnError &&
425
- e.context.stderr.includes(`could not read Username for`)) {
426
- throw new BackportError_1.BackportError(`Invalid credentials: ${e.message}`);
427
- }
428
- throw e;
429
- }
430
- }
431
- exports.pushBackportBranch = pushBackportBranch;
432
- // retrieve path to local repo (cwd) if it matches `repoName` / `repoOwner`
433
- async function getLocalSourceRepoPath(options) {
434
- const remotes = await getRepoInfoFromGitRemotes({ cwd: options.cwd });
435
- const hasMatchingGitRemote = remotes.some((remote) => remote.repoName === options.repoName &&
436
- remote.repoOwner === options.repoOwner);
437
- return hasMatchingGitRemote ? getGitProjectRootPath(options.cwd) : undefined;
438
- }
439
- exports.getLocalSourceRepoPath = getLocalSourceRepoPath;
@@ -1 +0,0 @@
1
- export {};