backport 5.6.4 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/README.md +166 -41
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +33 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +56 -39
  12. package/dist/options/cliArgs.d.ts +38 -45
  13. package/dist/options/cliArgs.js +123 -104
  14. package/dist/options/cliArgs.test.js +106 -119
  15. package/dist/options/config/config.d.ts +56 -2
  16. package/dist/options/config/config.js +12 -6
  17. package/dist/options/config/config.test.js +11 -6
  18. package/dist/options/config/getOptionsFromGit.d.ts +4 -0
  19. package/dist/options/config/getOptionsFromGit.js +8 -0
  20. package/dist/options/config/globalConfig.d.ts +2 -1
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -1
  24. package/dist/options/config/projectConfig.js +3 -3
  25. package/dist/options/config/projectConfig.test.js +54 -17
  26. package/dist/options/config/readConfigFile.d.ts +53 -2
  27. package/dist/options/config/readConfigFile.js +31 -5
  28. package/dist/options/options.d.ts +67 -35
  29. package/dist/options/options.js +99 -16
  30. package/dist/options/options.test.js +214 -67
  31. package/dist/options/parseRequiredOptions.d.ts +71 -0
  32. package/dist/options/parseRequiredOptions.js +68 -0
  33. package/dist/options/parseRequiredOptions.test.d.ts +1 -0
  34. package/dist/options/parseRequiredOptions.test.js +122 -0
  35. package/dist/runSequentially.d.ts +20 -0
  36. package/dist/runSequentially.js +41 -0
  37. package/dist/runSequentially.test.d.ts +1 -0
  38. package/dist/runSequentially.test.js +192 -0
  39. package/dist/runWithOptions.js +7 -14
  40. package/dist/runWithOptions.test.js +142 -16
  41. package/dist/scripts/generate-gql.d.ts +1 -0
  42. package/dist/scripts/generate-gql.js +15 -0
  43. package/dist/scripts/postinstall.js +4 -4
  44. package/dist/scripts/postinstall.test.js +9 -2
  45. package/dist/scripts/runPostinstall.js +1 -1
  46. package/dist/services/HandledError.d.ts +11 -1
  47. package/dist/services/HandledError.js +2 -1
  48. package/dist/services/child-process-promisified.d.ts +1 -1
  49. package/dist/services/child-process-promisified.js +2 -2
  50. package/dist/services/env.js +5 -5
  51. package/dist/services/env.test.js +11 -4
  52. package/dist/services/fs-promisified.js +4 -4
  53. package/dist/services/getExpectedTarget.d.ts +9 -0
  54. package/dist/services/getExpectedTarget.js +77 -0
  55. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  56. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  57. package/dist/services/git.d.ts +23 -5
  58. package/dist/services/git.integration.test.d.ts +1 -0
  59. package/dist/services/git.integration.test.js +168 -0
  60. package/dist/services/git.js +133 -60
  61. package/dist/services/git.test.js +160 -53
  62. package/dist/services/github/commitFormatters.d.ts +3 -7
  63. package/dist/services/github/commitFormatters.js +10 -19
  64. package/dist/services/github/commitFormatters.test.js +2 -24
  65. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  66. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  67. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  68. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  69. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  70. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  71. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  72. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  73. package/dist/services/github/v3/createPullRequest.js +32 -26
  74. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  75. package/dist/services/github/v3/createPullRequest.test.js +78 -0
  76. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  77. package/dist/services/github/v3/createStatusComment.js +97 -0
  78. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  79. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  80. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  81. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  82. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  83. package/dist/services/github/v4/apiRequestV4.js +9 -11
  84. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  85. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
  86. package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
  87. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
  88. package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
  89. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  91. package/dist/services/github/v4/fetchAuthorId.d.ts +10 -2
  92. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  93. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  94. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  95. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
  96. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  97. package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
  98. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  110. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  114. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  115. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  119. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  120. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  121. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  122. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
  123. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  124. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
  125. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  126. package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
  127. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  128. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
  129. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
  130. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
  131. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
  132. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
  133. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
  134. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
  135. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
  136. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
  137. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
  138. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  139. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  140. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
  141. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
  142. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  143. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  144. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  145. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  146. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  147. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  148. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  149. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  150. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  151. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
  152. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  153. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
  154. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  155. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  156. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  157. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  158. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  159. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  160. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  161. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +63 -0
  162. package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
  163. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
  164. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +147 -0
  165. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +37 -0
  166. package/dist/services/github/v4/getOptionsFromGithub/query.js +47 -0
  167. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  168. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  169. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  170. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  171. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  172. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
  173. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  174. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
  175. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
  176. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  177. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  178. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  179. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  180. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  181. package/dist/services/logger.d.ts +3 -3
  182. package/dist/services/logger.js +24 -24
  183. package/dist/services/prompt.test.d.ts +1 -0
  184. package/dist/services/prompt.test.js +87 -0
  185. package/dist/services/prompts.d.ts +10 -4
  186. package/dist/services/prompts.js +85 -22
  187. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  188. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  189. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  190. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  191. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  192. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  193. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  194. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  195. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  196. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  197. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  198. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  199. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  200. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  201. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  202. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  203. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  204. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  205. package/dist/services/sourceCommit.d.ts +78 -0
  206. package/dist/services/sourceCommit.js +86 -0
  207. package/dist/services/sourceCommit.test.d.ts +1 -0
  208. package/dist/services/sourceCommit.test.js +280 -0
  209. package/dist/test/inquirer.private.test.js +105 -61
  210. package/dist/test/integration/createSpies.d.ts +1 -1
  211. package/dist/test/integration/createSpies.js +21 -9
  212. package/dist/test/integration/envConstants.js +5 -6
  213. package/dist/test/integration/helpers.js +1 -1
  214. package/dist/test/integration/integration.private.test.d.ts +1 -0
  215. package/dist/test/integration/integration.private.test.js +317 -0
  216. package/dist/test/integration/integration.test.js +30 -31
  217. package/dist/test/mockConfigFiles.d.ts +5 -0
  218. package/dist/test/mockConfigFiles.js +37 -0
  219. package/dist/test/nockHelpers.d.ts +3 -3
  220. package/dist/test/nockHelpers.js +7 -11
  221. package/dist/test/private/getDevAccessToken.js +1 -1
  222. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  223. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  224. package/dist/types/Commit.d.ts +85 -0
  225. package/dist/types/Commit.js +139 -0
  226. package/dist/types/commitNode.d.ts +89 -0
  227. package/dist/types/commitNode.js +139 -0
  228. package/dist/types/commitNode.test.d.ts +1 -0
  229. package/dist/types/commitNode.test.js +255 -0
  230. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  231. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  232. package/dist/ui/cherrypickAndCreatePullRequest.test.js +333 -76
  233. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  234. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
  235. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  236. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  237. package/dist/ui/getCommits.d.ts +1 -1
  238. package/dist/ui/getCommits.js +55 -25
  239. package/dist/ui/getTargetBranches.d.ts +3 -2
  240. package/dist/ui/getTargetBranches.js +33 -18
  241. package/dist/ui/getTargetBranches.test.js +75 -99
  242. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  243. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  244. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  245. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  246. package/dist/ui/maybeSetupRepo.js +11 -10
  247. package/dist/ui/maybeSetupRepo.test.js +54 -4
  248. package/dist/utils/excludeUndefined.d.ts +6 -0
  249. package/dist/utils/excludeUndefined.js +7 -0
  250. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  251. package/dist/utils/excludeUndefined.test.js +24 -0
  252. package/package.json +37 -51
  253. package/yarn.lock +2416 -2987
@@ -18,12 +18,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
21
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const os_1 = __importDefault(require("os"));
22
26
  const childProcess = __importStar(require("../services/child-process-promisified"));
23
- const git_1 = require("../services/git");
24
27
  const ExecError_1 = require("../test/ExecError");
28
+ const git_1 = require("./git");
25
29
  beforeEach(() => {
26
- jest.clearAllMocks();
30
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
31
+ });
32
+ afterEach(() => {
33
+ jest.restoreAllMocks();
27
34
  });
28
35
  describe('getUnstagedFiles', () => {
29
36
  it('should split lines and remove empty', async () => {
@@ -35,7 +42,7 @@ describe('getUnstagedFiles', () => {
35
42
  repoOwner: 'elastic',
36
43
  repoName: 'kibana',
37
44
  };
38
- await expect(await git_1.getUnstagedFiles(options)).toEqual([
45
+ await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([
39
46
  '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
40
47
  '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file2.txt',
41
48
  ]);
@@ -49,7 +56,117 @@ describe('getUnstagedFiles', () => {
49
56
  repoOwner: 'elastic',
50
57
  repoName: 'kibana',
51
58
  };
52
- await expect(await git_1.getUnstagedFiles(options)).toEqual([]);
59
+ await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([]);
60
+ });
61
+ });
62
+ describe('getLocalConfigFileCommitDate', () => {
63
+ it('returns a timestamp the file exists', async () => {
64
+ const res = {
65
+ stdout: 'Wed Dec 16 10:10:39 2020 -0800\n',
66
+ stderr: '',
67
+ };
68
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
69
+ expect(await (0, git_1.getLocalConfigFileCommitDate)()).toEqual(1608142239000);
70
+ });
71
+ it('returns empty when file does not exists', async () => {
72
+ const res = { stdout: '', stderr: '' };
73
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
74
+ expect(await (0, git_1.getLocalConfigFileCommitDate)()).toEqual(undefined);
75
+ });
76
+ it('handles errors', async () => {
77
+ const err = {
78
+ killed: false,
79
+ code: 128,
80
+ signal: null,
81
+ cmd: 'any command...',
82
+ stdout: '',
83
+ stderr: 'any error',
84
+ };
85
+ jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
86
+ expect(await (0, git_1.getLocalConfigFileCommitDate)()).toEqual(undefined);
87
+ });
88
+ });
89
+ describe('isLocalConfigFileUntracked', () => {
90
+ it('returns "false" if file does not exist', async () => {
91
+ const res = { stdout: '', stderr: '' };
92
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
93
+ expect(await (0, git_1.isLocalConfigFileUntracked)()).toEqual(false);
94
+ });
95
+ it('returns "true" if file is untracked', async () => {
96
+ const res = { stdout: '.backportrc.json\n', stderr: '' };
97
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
98
+ expect(await (0, git_1.isLocalConfigFileUntracked)()).toEqual(true);
99
+ });
100
+ it('handles errors', async () => {
101
+ const err = {
102
+ killed: false,
103
+ code: 128,
104
+ signal: null,
105
+ cmd: 'any command...',
106
+ stdout: '',
107
+ stderr: 'any error',
108
+ };
109
+ jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
110
+ expect(await (0, git_1.isLocalConfigFileUntracked)()).toEqual(undefined);
111
+ });
112
+ });
113
+ describe('isLocalConfigFileModified', () => {
114
+ it('returns "false" if file does not exist', async () => {
115
+ const res = { stdout: '', stderr: '' };
116
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
117
+ expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(false);
118
+ });
119
+ it('returns "false" if file is untracked', async () => {
120
+ const res = { stdout: '', stderr: '' };
121
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
122
+ expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(false);
123
+ });
124
+ it('returns "true" if file is staged', async () => {
125
+ const res = { stdout: '.backportrc.json\n', stderr: '' };
126
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
127
+ expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(true);
128
+ });
129
+ it('handles errors', async () => {
130
+ const err = {
131
+ killed: false,
132
+ code: 128,
133
+ signal: null,
134
+ cmd: 'any command...',
135
+ stdout: '',
136
+ stderr: 'any error',
137
+ };
138
+ jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
139
+ expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(undefined);
140
+ });
141
+ });
142
+ describe('getRepoOwnerAndNameFromGitRemote', () => {
143
+ it('returns first matching pattern', async () => {
144
+ const res = {
145
+ stdout: 'origin\tgit@github.com:elastic/kibana.git (fetch)\norigin\tgit@github.com:elastic/kibana.git (push)\nsqren\tgit@github.com:sqren/kibana.git (fetch)\nsqren\tgit@github.com:sqren/kibana.git (push)\n',
146
+ stderr: '',
147
+ };
148
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
149
+ expect(await (0, git_1.getRepoOwnerAndNameFromGitRemote)()).toEqual({
150
+ repoOwner: 'elastic',
151
+ repoName: 'kibana',
152
+ });
153
+ });
154
+ it('returns undefined when no remotes exist', async () => {
155
+ const res = { stdout: '', stderr: '' };
156
+ jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
157
+ expect(await (0, git_1.getRepoOwnerAndNameFromGitRemote)()).toEqual(undefined);
158
+ });
159
+ it('handles errors', async () => {
160
+ const err = {
161
+ killed: false,
162
+ code: 128,
163
+ signal: null,
164
+ cmd: 'git ls-files .backportrc.js* --exclude-standard --others',
165
+ stdout: '',
166
+ stderr: 'fatal: not a git repository (or any of the parent directories): .git\n',
167
+ };
168
+ jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
169
+ expect(await (0, git_1.getRepoOwnerAndNameFromGitRemote)()).toEqual(undefined);
53
170
  });
54
171
  });
55
172
  describe('getConflictingFiles', () => {
@@ -67,8 +184,11 @@ describe('getConflictingFiles', () => {
67
184
  repoOwner: 'elastic',
68
185
  repoName: 'kibana',
69
186
  };
70
- expect(await git_1.getConflictingFiles(options)).toEqual([
71
- '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
187
+ expect(await (0, git_1.getConflictingFiles)(options)).toEqual([
188
+ {
189
+ absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
190
+ relative: 'conflicting-file.txt',
191
+ },
72
192
  ]);
73
193
  });
74
194
  });
@@ -90,7 +210,7 @@ describe('createFeatureBranch', () => {
90
210
  stderr: "fatal: couldn't find remote ref 4.x\n",
91
211
  };
92
212
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
93
- await expect(git_1.createBackportBranch({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
213
+ await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
94
214
  });
95
215
  it('should throw "Invalid refspec" error', async () => {
96
216
  expect.assertions(1);
@@ -103,14 +223,14 @@ describe('createFeatureBranch', () => {
103
223
  stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
104
224
  };
105
225
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
106
- await expect(git_1.createBackportBranch({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
226
+ await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
107
227
  });
108
228
  it('should rethrow normal error', async () => {
109
229
  expect.assertions(1);
110
230
  const err = new Error('just a normal error');
111
231
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
112
232
  expect.assertions(1);
113
- await expect(git_1.createBackportBranch({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
233
+ await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
114
234
  });
115
235
  });
116
236
  describe('deleteRemote', () => {
@@ -129,13 +249,13 @@ describe('deleteRemote', () => {
129
249
  stderr: "fatal: No such remote: 'origin'\n",
130
250
  };
131
251
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
132
- await expect(await git_1.deleteRemote(options, remoteName)).toBe(undefined);
252
+ await expect(await (0, git_1.deleteRemote)(options, remoteName)).toBe(undefined);
133
253
  });
134
254
  it('should rethrow normal error', async () => {
135
255
  const err = new Error('just a normal error');
136
256
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
137
257
  expect.assertions(1);
138
- await expect(git_1.deleteRemote(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
258
+ await expect((0, git_1.deleteRemote)(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
139
259
  });
140
260
  });
141
261
  describe('cherrypick', () => {
@@ -143,45 +263,33 @@ describe('cherrypick', () => {
143
263
  repoOwner: 'elastic',
144
264
  repoName: 'kibana',
145
265
  };
146
- const commit = {
147
- sourceBranch: '7.x',
148
- formattedMessage: '',
149
- originalMessage: '',
150
- sha: 'abcd',
151
- targetBranchesFromLabels: [],
152
- existingTargetPullRequests: [],
153
- };
154
266
  it('should return `needsResolving: false` when no errors are encountered', async () => {
155
267
  jest
156
268
  .spyOn(childProcess, 'exec')
157
- // mock git fetch
158
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
159
269
  // mock cherry pick command
160
270
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
161
- expect(await git_1.cherrypick(options, commit)).toEqual({
271
+ expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
272
+ conflictingFiles: [],
273
+ unstagedFiles: [],
162
274
  needsResolving: false,
163
275
  });
164
276
  });
165
277
  it('should use mainline option when specified', async () => {
166
278
  const execSpy = jest
167
279
  .spyOn(childProcess, 'exec')
168
- // mock git fetch
169
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
170
280
  // mock cherry pick command
171
281
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
172
- await git_1.cherrypick({ ...options, mainline: 1 }, commit);
173
- expect(execSpy.mock.calls[1][0]).toBe('git cherry-pick --mainline 1 abcd');
282
+ await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
283
+ expect(execSpy.mock.calls[0][0]).toBe('git cherry-pick -x --mainline 1 abcd');
174
284
  });
175
285
  it('should return `needsResolving: true` upon cherrypick error', async () => {
176
286
  jest
177
287
  .spyOn(childProcess, 'exec')
178
- // mock git fetch
179
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
180
288
  // mock cherry pick command
181
289
  .mockRejectedValueOnce(new ExecError_1.ExecError({
182
290
  killed: false,
183
291
  code: 128,
184
- cmd: 'git cherry-pick abcd',
292
+ cmd: 'git cherry-pick -x abcd',
185
293
  stdout: '',
186
294
  stderr: '',
187
295
  }))
@@ -194,15 +302,20 @@ describe('cherrypick', () => {
194
302
  }))
195
303
  // mock getUnstagedFiles
196
304
  .mockResolvedValueOnce({ stdout: '', stderr: '' });
197
- expect(await git_1.cherrypick(options, commit)).toEqual({
305
+ expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
306
+ conflictingFiles: [
307
+ {
308
+ absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
309
+ relative: 'conflicting-file.txt',
310
+ },
311
+ ],
198
312
  needsResolving: true,
313
+ unstagedFiles: [],
199
314
  });
200
315
  });
201
316
  it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
202
317
  jest
203
318
  .spyOn(childProcess, 'exec')
204
- // mock git fetch
205
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
206
319
  // mock cherry pick command
207
320
  .mockRejectedValueOnce(new ExecError_1.ExecError({
208
321
  killed: false,
@@ -212,7 +325,7 @@ describe('cherrypick', () => {
212
325
  stdout: '',
213
326
  stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
214
327
  }));
215
- await expect(git_1.cherrypick(options, commit)).rejects
328
+ await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
216
329
  .toThrowError(`Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the \`mainline\` argument:
217
330
 
218
331
  > backport --mainline
@@ -226,8 +339,6 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
226
339
  it('should gracefully handle empty commits', async () => {
227
340
  jest
228
341
  .spyOn(childProcess, 'exec')
229
- // mock git fetch
230
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
231
342
  // mock cherry pick command
232
343
  .mockRejectedValueOnce(new ExecError_1.ExecError({
233
344
  killed: false,
@@ -237,13 +348,11 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
237
348
  stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
238
349
  stderr: "The previous cherry-pick is now empty, possibly due to conflict resolution.\nIf you wish to commit it anyway, use:\n\n git commit --allow-empty\n\nOtherwise, please use 'git cherry-pick --skip'\n",
239
350
  }));
240
- await expect(git_1.cherrypick(options, commit)).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
351
+ await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
241
352
  });
242
353
  it('gracefully handles missing git info', async () => {
243
354
  jest
244
355
  .spyOn(childProcess, 'exec')
245
- // mock git fetch
246
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
247
356
  // mock cherry pick command
248
357
  .mockRejectedValueOnce(new ExecError_1.ExecError({
249
358
  killed: false,
@@ -251,9 +360,9 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
251
360
  signal: null,
252
361
  cmd: 'git cherry-pick 83ad852b6ba1a64c8047f07201018eb6fb020db8',
253
362
  stdout: '',
254
- stderr: '\n*** Please tell me who you are.\n\nRun\n\n git config --global user.email "you@example.com"\n git config --global user.name "Your Name"\n\nto set your account\'s default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <runner@fv-az40.ayh1iyn3zmsehf4wcd4usluype.bx.internal.cloudapp.net>) not allowed\n',
363
+ stderr: '\n*** Please tell me who you are.\n\nRun\n\n git config --global user.email "you@example.com"\n git config --global user.name "Your Name"\n\nto set your account\'s default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <foo@bar.net>) not allowed\n',
255
364
  }));
256
- await expect(git_1.cherrypick(options, commit)).rejects
365
+ await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
257
366
  .toThrowErrorMatchingInlineSnapshot(`
258
367
  "Cherrypick failed:
259
368
 
@@ -267,22 +376,20 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
267
376
  to set your account's default identity.
268
377
  Omit --global to set the identity only in this repository.
269
378
 
270
- fatal: empty ident name (for <runner@fv-az40.ayh1iyn3zmsehf4wcd4usluype.bx.internal.cloudapp.net>) not allowed
379
+ fatal: empty ident name (for <foo@bar.net>) not allowed
271
380
  "
272
381
  `);
273
382
  });
274
383
  it('should re-throw non-cherrypick errors', async () => {
275
384
  jest
276
385
  .spyOn(childProcess, 'exec')
277
- // mock git fetch
278
- .mockResolvedValueOnce({ stderr: '', stdout: '' })
279
386
  // mock cherry pick command
280
387
  .mockRejectedValueOnce(new Error('non-cherrypick error'))
281
388
  // getConflictingFiles
282
389
  .mockResolvedValueOnce({ stdout: '', stderr: '' })
283
390
  // getUnstagedFiles
284
391
  .mockResolvedValueOnce({ stdout: '', stderr: '' });
285
- await expect(git_1.cherrypick(options, commit)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
392
+ await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
286
393
  });
287
394
  });
288
395
  describe('commitChanges', () => {
@@ -297,7 +404,7 @@ describe('commitChanges', () => {
297
404
  jest
298
405
  .spyOn(childProcess, 'exec')
299
406
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
300
- await expect(await git_1.commitChanges(commit, options)).toBe(undefined);
407
+ await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
301
408
  });
302
409
  it('should swallow error if changes have already been committed manaully', async () => {
303
410
  const err = {
@@ -309,7 +416,7 @@ describe('commitChanges', () => {
309
416
  stderr: '',
310
417
  };
311
418
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
312
- await expect(await git_1.commitChanges(commit, options)).toBe(undefined);
419
+ await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
313
420
  });
314
421
  describe('when commit fails due to empty message', () => {
315
422
  let spy;
@@ -327,7 +434,7 @@ describe('commitChanges', () => {
327
434
  .spyOn(childProcess, 'exec')
328
435
  .mockRejectedValueOnce(err)
329
436
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
330
- res = await git_1.commitChanges(commit, options);
437
+ res = await (0, git_1.commitChanges)(commit, options);
331
438
  });
332
439
  it('should manually set the commit message', () => {
333
440
  expect(spy).toHaveBeenCalledTimes(2);
@@ -342,7 +449,7 @@ describe('commitChanges', () => {
342
449
  const err = new Error('non-cherrypick error');
343
450
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
344
451
  expect.assertions(1);
345
- await expect(git_1.commitChanges(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
452
+ await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
346
453
  });
347
454
  });
348
455
  describe('addRemote', () => {
@@ -356,28 +463,28 @@ describe('addRemote', () => {
356
463
  const spy = jest
357
464
  .spyOn(childProcess, 'exec')
358
465
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
359
- await git_1.addRemote(options, 'elastic');
466
+ await (0, git_1.addRemote)(options, 'elastic');
360
467
  return expect(spy).toHaveBeenCalledWith('git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
361
468
  });
362
469
  it('add correct user remote', async () => {
363
470
  const spy = jest
364
471
  .spyOn(childProcess, 'exec')
365
472
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
366
- await git_1.addRemote(options, 'sqren');
473
+ await (0, git_1.addRemote)(options, 'sqren');
367
474
  return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
368
475
  });
369
476
  it('allows custom github url', async () => {
370
477
  const spy = jest
371
478
  .spyOn(childProcess, 'exec')
372
479
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
373
- await git_1.addRemote({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
480
+ await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
374
481
  return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.my-company.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
375
482
  });
376
483
  });
377
484
  describe('pushBackportBranch', () => {
378
485
  const options = {
486
+ authenticatedUsername: 'sqren_authenticated',
379
487
  fork: true,
380
- username: 'sqren',
381
488
  repoOwner: 'elastic',
382
489
  repoName: 'kibana',
383
490
  };
@@ -391,6 +498,6 @@ describe('pushBackportBranch', () => {
391
498
  stdout: '',
392
499
  stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
393
500
  });
394
- await expect(git_1.pushBackportBranch({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/sqren/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--fork false\\". Read more about \\"fork mode\\" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork"`);
501
+ await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/sqren_authenticated/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--no-fork\\". Read more about \\"fork mode\\" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork"`);
395
502
  });
396
503
  });
@@ -1,8 +1,4 @@
1
1
  export declare function getShortSha(sha: string): string;
2
- export declare function getFirstCommitMessageLine(message: string): string;
3
- export declare function getFormattedCommitMessage({ message, pullNumber, sha, }: {
4
- message: string;
5
- pullNumber?: number;
6
- sha: string;
7
- }): string;
8
- export declare function getPullNumberFromMessage(firstMessageLine: string): number | undefined;
2
+ export declare function getFirstLine(message: string): string;
3
+ export declare function stripPullNumber(message: string): string;
4
+ export declare function extractPullNumber(firstMessageLine: string): number | undefined;
@@ -1,33 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPullNumberFromMessage = exports.getFormattedCommitMessage = exports.getFirstCommitMessageLine = exports.getShortSha = void 0;
3
+ exports.extractPullNumber = exports.stripPullNumber = exports.getFirstLine = exports.getShortSha = void 0;
4
4
  function getShortSha(sha) {
5
5
  return sha.slice(0, 8);
6
6
  }
7
7
  exports.getShortSha = getShortSha;
8
- function getFirstCommitMessageLine(message) {
8
+ function getFirstLine(message) {
9
9
  return message.split('\n')[0];
10
10
  }
11
- exports.getFirstCommitMessageLine = getFirstCommitMessageLine;
12
- function getFormattedCommitMessage({ message, pullNumber, sha, }) {
13
- const firstMessageLine = getFirstCommitMessageLine(message);
14
- const messageHasPullNumber = firstMessageLine.match(/.+ \(#\d+\)/);
15
- // message already contains pull number
16
- if (messageHasPullNumber) {
17
- return firstMessageLine;
18
- }
19
- // message doesn't contain pull number. Add it
20
- if (pullNumber) {
21
- return `${firstMessageLine} (#${pullNumber})`;
22
- }
23
- // pull number not available. Add commit
24
- return `${firstMessageLine} (${getShortSha(sha)})`;
11
+ exports.getFirstLine = getFirstLine;
12
+ function stripPullNumber(message) {
13
+ const firstMessageLine = getFirstLine(message);
14
+ const messageWithoutPullNumber = firstMessageLine.replace(/( \(#\d+\))$/, '');
15
+ return messageWithoutPullNumber;
25
16
  }
26
- exports.getFormattedCommitMessage = getFormattedCommitMessage;
27
- function getPullNumberFromMessage(firstMessageLine) {
17
+ exports.stripPullNumber = stripPullNumber;
18
+ function extractPullNumber(firstMessageLine) {
28
19
  const matches = firstMessageLine.match(/\(#(\d+)\)/);
29
20
  if (matches) {
30
21
  return parseInt(matches[1], 10);
31
22
  }
32
23
  }
33
- exports.getPullNumberFromMessage = getPullNumberFromMessage;
24
+ exports.extractPullNumber = extractPullNumber;
@@ -3,31 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const commitFormatters_1 = require("./commitFormatters");
4
4
  describe('getFirstCommitMessageLine', () => {
5
5
  it('should only return the first line of the message', () => {
6
- expect(commitFormatters_1.getFirstCommitMessageLine('My commit message (#1234)\n\n Additional commit message body')).toEqual('My commit message (#1234)');
6
+ expect((0, commitFormatters_1.getFirstLine)('My commit message (#1234)\n\n Additional commit message body')).toEqual('My commit message (#1234)');
7
7
  });
8
8
  it('should return the commit message as-is', () => {
9
- expect(commitFormatters_1.getFirstCommitMessageLine('My commit message')).toEqual('My commit message');
10
- });
11
- });
12
- describe('getFormattedCommitMessage', () => {
13
- it('should return the first message line verbatim', () => {
14
- expect(commitFormatters_1.getFormattedCommitMessage({
15
- message: 'This is my commit message (#1234)\n\nthis is a second line',
16
- pullNumber: 1234,
17
- sha: 'sha123456789',
18
- })).toBe('This is my commit message (#1234)');
19
- });
20
- it('should add pullNumber as suffix', () => {
21
- expect(commitFormatters_1.getFormattedCommitMessage({
22
- message: 'This is my commit message\n\nthis is a second line',
23
- pullNumber: 1234,
24
- sha: 'sha123456789',
25
- })).toBe('This is my commit message (#1234)');
26
- });
27
- it('should add commit sha as suffix', () => {
28
- expect(commitFormatters_1.getFormattedCommitMessage({
29
- message: 'This is my commit message\n\nthis is a second line',
30
- sha: 'sha123456789',
31
- })).toBe('This is my commit message (sha12345)');
9
+ expect((0, commitFormatters_1.getFirstLine)('My commit message')).toEqual('My commit message');
32
10
  });
33
11
  });
@@ -1,2 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, username, dryRun, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
2
+ export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
@@ -7,18 +7,13 @@ exports.addAssigneesToPullRequest = void 0;
7
7
  const rest_1 = require("@octokit/rest");
8
8
  const ora_1 = __importDefault(require("ora"));
9
9
  const logger_1 = require("../../logger");
10
- async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, username, dryRun, }, pullNumber, assignees) {
11
- const isSelfAssigning = assignees.length === 1 && assignees[0] === username;
12
- const text = isSelfAssigning
10
+ async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }, pullNumber, assignees) {
11
+ const text = autoAssign
13
12
  ? `Self-assigning to #${pullNumber}`
14
13
  : `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`;
15
14
  logger_1.logger.info(text);
16
- const spinner = ora_1.default(text).start();
15
+ const spinner = (0, ora_1.default)(text).start();
17
16
  try {
18
- if (dryRun) {
19
- spinner.succeed(`Dry run: ${text}`);
20
- return;
21
- }
22
17
  const octokit = new rest_1.Octokit({
23
18
  auth: accessToken,
24
19
  baseUrl: githubApiBaseUrlV3,
@@ -9,18 +9,16 @@ describe('addAssigneesToPullRequest', () => {
9
9
  it('should add assignees to PR', async () => {
10
10
  const pullNumber = 216;
11
11
  const assignees = ['sqren'];
12
- const scope = nock_1.default('https://api.github.com')
13
- .post('/repos/backport-org/backport-demo/issues/216/assignees', {
12
+ const scope = (0, nock_1.default)('https://api.github.com')
13
+ .post('/repos/elastic/kibana/issues/216/assignees', {
14
14
  assignees: ['sqren'],
15
15
  })
16
16
  .reply(200, 'some response');
17
- const res = await addAssigneesToPullRequest_1.addAssigneesToPullRequest({
18
- githubApiBaseUrlV3: 'https://api.github.com',
19
- repoName: 'backport-demo',
20
- repoOwner: 'backport-org',
17
+ const res = await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)({
18
+ author: 'sqren',
19
+ repoName: 'kibana',
20
+ repoOwner: 'elastic',
21
21
  accessToken: 'my-token',
22
- username: 'sqren',
23
- dryRun: false,
24
22
  }, pullNumber, assignees);
25
23
  expect(res).toBe(undefined);
26
24
  scope.done();
@@ -1,2 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, dryRun, }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
2
+ export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
@@ -7,15 +7,11 @@ exports.addLabelsToPullRequest = void 0;
7
7
  const rest_1 = require("@octokit/rest");
8
8
  const ora_1 = __importDefault(require("ora"));
9
9
  const logger_1 = require("../../logger");
10
- async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, dryRun, }, pullNumber, labels) {
10
+ async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, labels) {
11
11
  const text = `Adding labels: ${labels.join(', ')}`;
12
12
  logger_1.logger.info(text);
13
- const spinner = ora_1.default(text).start();
13
+ const spinner = (0, ora_1.default)(text).start();
14
14
  try {
15
- if (dryRun) {
16
- spinner.succeed(`Dry run: ${text}`);
17
- return;
18
- }
19
15
  const octokit = new rest_1.Octokit({
20
16
  auth: accessToken,
21
17
  baseUrl: githubApiBaseUrlV3,
@@ -0,0 +1,2 @@
1
+ import { ValidConfigOptions } from '../../../options/options';
2
+ export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
@@ -0,0 +1,34 @@
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
+ exports.addReviewersToPullRequest = void 0;
7
+ const rest_1 = require("@octokit/rest");
8
+ const ora_1 = __importDefault(require("ora"));
9
+ const logger_1 = require("../../logger");
10
+ async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, reviewers) {
11
+ const text = `Adding reviewers: ${reviewers}`;
12
+ logger_1.logger.info(text);
13
+ const spinner = (0, ora_1.default)(text).start();
14
+ try {
15
+ const octokit = new rest_1.Octokit({
16
+ auth: accessToken,
17
+ baseUrl: githubApiBaseUrlV3,
18
+ log: logger_1.logger,
19
+ });
20
+ await octokit.pulls.requestReviewers({
21
+ owner: repoOwner,
22
+ repo: repoName,
23
+ pull_number: pullNumber,
24
+ reviewers,
25
+ });
26
+ spinner.succeed();
27
+ }
28
+ catch (e) {
29
+ const message = e.response?.data?.message;
30
+ spinner.fail(`Adding reviewers. ${message ? message : ''}`);
31
+ logger_1.logger.info(`Could not add reviewers to PR ${pullNumber}`, e.stack);
32
+ }
33
+ }
34
+ exports.addReviewersToPullRequest = addReviewersToPullRequest;