backport 5.6.3 → 6.0.0

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