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
@@ -4,11 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getOptionsFromCliArgs = void 0;
7
- const lodash_isstring_1 = __importDefault(require("lodash.isstring"));
8
7
  const yargs_1 = __importDefault(require("yargs"));
9
- function getOptionsFromCliArgs(configOptions, argv) {
10
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
11
- const cliArgs = yargs_1.default(argv)
8
+ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
9
+ const yargsInstance = (0, yargs_1.default)(argv)
12
10
  .parserConfiguration({
13
11
  'strip-dashed': true,
14
12
  'strip-aliased': true,
@@ -17,70 +15,80 @@ function getOptionsFromCliArgs(configOptions, argv) {
17
15
  .usage('$0 [args]')
18
16
  .wrap(Math.max(100, Math.min(120, yargs_1.default.terminalWidth())))
19
17
  .option('accessToken', {
20
- default: configOptions.accessToken,
21
18
  alias: 'accesstoken',
22
19
  description: 'Github access token',
23
20
  type: 'string',
24
21
  })
25
22
  // show users own commits
26
23
  .option('all', {
27
- default: (_a = configOptions.all) !== null && _a !== void 0 ? _a : false,
28
24
  description: 'List all commits',
29
25
  alias: 'a',
30
26
  type: 'boolean',
27
+ })
28
+ .option('assignee', {
29
+ description: 'Add assignees to the target pull request',
30
+ alias: 'assign',
31
+ type: 'array',
32
+ string: true,
33
+ conflicts: ['autoAssign'],
31
34
  })
32
35
  .option('author', {
33
- default: configOptions.author,
34
36
  description: 'Show commits by specific author',
35
37
  type: 'string',
36
- })
37
- .option('assignees', {
38
- default: configOptions.assignees || [],
39
- description: 'Add assignees to the target pull request',
40
- alias: ['assignee', 'assign'],
41
- type: 'array',
42
38
  })
43
39
  .option('autoAssign', {
44
- default: (_b = configOptions.autoAssign) !== null && _b !== void 0 ? _b : false,
45
40
  description: 'Auto assign the target pull request to yourself',
46
41
  type: 'boolean',
42
+ conflicts: ['assignees'],
43
+ })
44
+ .option('autoMerge', {
45
+ description: 'Enable auto-merge for created pull requests',
46
+ type: 'boolean',
47
+ })
48
+ .option('autoMergeMethod', {
49
+ description: 'Sets auto-merge method when using --auto-merge. Default: merge',
50
+ type: 'string',
51
+ choices: ['merge', 'rebase', 'squash'],
47
52
  })
48
53
  .option('ci', {
49
- default: (_c = configOptions.ci) !== null && _c !== void 0 ? _c : false,
50
54
  description: 'Disable interactive prompts',
51
55
  type: 'boolean',
52
56
  })
53
- .option('dryRun', {
54
- default: false,
55
- description: 'Perform backport without pushing to Github',
57
+ .option('cherrypickRef', {
58
+ description: 'Append commit message with "(cherry picked from commit...)',
59
+ type: 'boolean',
60
+ conflicts: ['noCherrypickRef'],
61
+ })
62
+ .option('details', {
63
+ description: 'Show details about each commit',
56
64
  type: 'boolean',
57
65
  })
58
66
  .option('editor', {
59
- default: configOptions.editor,
60
67
  description: 'Editor to be opened during conflict resolution',
61
68
  type: 'string',
69
+ })
70
+ .option('forceLocalConfig', {
71
+ description: 'Use local .backportrc.json config instead of loading from Github',
72
+ type: 'boolean',
62
73
  })
63
74
  // push target branch to {username}/{repoName}
64
75
  .option('fork', {
65
- default: (_d = configOptions.fork) !== null && _d !== void 0 ? _d : true,
66
76
  description: 'Create backports in fork or origin repo',
67
77
  type: 'boolean',
78
+ conflicts: ['noFork'],
68
79
  })
69
80
  .option('gitHostname', {
70
81
  hidden: true,
71
- default: (_e = configOptions.gitHostname) !== null && _e !== void 0 ? _e : 'github.com',
72
82
  description: 'Hostname for Github',
73
83
  type: 'string',
74
84
  })
75
85
  .option('githubApiBaseUrlV3', {
76
86
  hidden: true,
77
- default: (_f = configOptions.githubApiBaseUrlV3) !== null && _f !== void 0 ? _f : 'https://api.github.com',
78
87
  description: `Base url for Github's REST (v3) API`,
79
88
  type: 'string',
80
89
  })
81
90
  .option('githubApiBaseUrlV4', {
82
91
  hidden: true,
83
- default: (_g = configOptions.githubApiBaseUrlV4) !== null && _g !== void 0 ? _g : 'https://api.github.com/graphql',
84
92
  description: `Base url for Github's GraphQL (v4) API`,
85
93
  type: 'string',
86
94
  })
@@ -102,7 +110,6 @@ function getOptionsFromCliArgs(configOptions, argv) {
102
110
  })
103
111
  // display 10 commits to pick from
104
112
  .option('maxNumber', {
105
- default: (_h = configOptions.maxNumber) !== null && _h !== void 0 ? _h : 10,
106
113
  description: 'Number of commits to choose from',
107
114
  alias: ['number', 'n'],
108
115
  type: 'number',
@@ -111,154 +118,166 @@ function getOptionsFromCliArgs(configOptions, argv) {
111
118
  .option('multiple', {
112
119
  description: 'Select multiple branches/commits',
113
120
  type: 'boolean',
121
+ conflicts: ['multipleBranches', 'multipleCommits'],
114
122
  })
115
123
  // allow picking multiple target branches
116
124
  .option('multipleBranches', {
117
- default: (_j = configOptions.multipleBranches) !== null && _j !== void 0 ? _j : true,
118
125
  description: 'Backport to multiple branches',
119
126
  type: 'boolean',
127
+ conflicts: ['multiple'],
120
128
  })
121
129
  // allow picking multiple commits
122
130
  .option('multipleCommits', {
123
- default: (_k = configOptions.multipleCommits) !== null && _k !== void 0 ? _k : false,
124
131
  description: 'Backport multiple commits',
125
132
  type: 'boolean',
133
+ conflicts: ['multiple'],
134
+ })
135
+ .option('noCherrypickRef', {
136
+ description: 'Do not append commit message with "(cherry picked from commit...)"',
137
+ type: 'boolean',
138
+ conflicts: ['cherrypickRef'],
126
139
  })
127
140
  .option('noVerify', {
128
- default: (_l = configOptions.noVerify) !== null && _l !== void 0 ? _l : true,
129
- description: 'Bypasses the pre-commit and commit-msg hooks',
141
+ description: 'Bypass the pre-commit and commit-msg hooks',
142
+ type: 'boolean',
143
+ })
144
+ .option('noFork', {
145
+ description: 'Create backports in the origin repo',
130
146
  type: 'boolean',
147
+ conflicts: ['fork'],
131
148
  })
132
149
  .option('path', {
133
- default: configOptions.path,
134
150
  description: 'Only list commits touching files under the specified path',
135
151
  alias: 'p',
152
+ type: 'array',
153
+ string: true,
154
+ })
155
+ .option('prDescription', {
156
+ description: 'Description to be added to pull request',
157
+ alias: 'description',
136
158
  type: 'string',
137
159
  })
138
160
  .option('prTitle', {
139
- default: (_m = configOptions.prTitle) !== null && _m !== void 0 ? _m : '[{targetBranch}] {commitMessages}',
140
161
  description: 'Title of pull request',
141
162
  alias: 'title',
142
163
  type: 'string',
143
- })
144
- .option('prDescription', {
145
- default: configOptions.prDescription,
146
- description: 'Description to be added to pull request',
147
- alias: 'description',
148
- type: 'string',
149
164
  })
150
165
  .option('prFilter', {
151
- default: configOptions.prFilter,
152
166
  conflicts: ['pullNumber', 'sha'],
153
167
  description: `Filter source pull requests by a query`,
154
168
  type: 'string',
155
169
  })
156
170
  .option('pullNumber', {
157
- default: configOptions.pullNumber,
158
171
  conflicts: ['sha', 'prFilter'],
159
172
  description: 'Pull request to backport',
160
173
  alias: 'pr',
161
174
  type: 'number',
162
175
  })
163
176
  .option('resetAuthor', {
164
- default: (_o = configOptions.resetAuthor) !== null && _o !== void 0 ? _o : false,
165
177
  description: 'Set yourself as commit author',
166
178
  type: 'boolean',
179
+ })
180
+ .option('reviewer', {
181
+ description: 'Add reviewer to the target PR',
182
+ type: 'array',
183
+ string: true,
167
184
  })
168
185
  .option('sha', {
169
- default: configOptions.sha,
170
186
  conflicts: ['pullNumber', 'prFilter'],
171
187
  description: 'Commit sha to backport',
172
188
  alias: 'commit',
173
189
  type: 'string',
174
190
  })
175
191
  .option('sourceBranch', {
176
- default: configOptions.sourceBranch,
177
192
  description: `Specify a non-default branch (normally "master") to backport from`,
178
193
  type: 'string',
179
194
  })
180
- .option('sourcePRLabels', {
181
- default: (_p = configOptions.sourcePRLabels) !== null && _p !== void 0 ? _p : [],
195
+ .option('sourcePRLabel', {
182
196
  description: 'Add labels to the source (original) PR',
183
- alias: ['sourcePRLabel', 'sourcePrLabel', 'sourcePrLabels'],
197
+ alias: 'sourcePrLabel',
184
198
  type: 'array',
199
+ string: true,
185
200
  })
186
- .option('targetBranches', {
187
- default: configOptions.targetBranches || [],
201
+ .option('targetBranch', {
188
202
  description: 'Branch(es) to backport to',
189
- alias: ['targetBranch', 'branch', 'b'],
203
+ alias: ['branch', 'b'],
190
204
  type: 'array',
191
- string: true,
205
+ string: true, // ensure `6.0` is not coerced to `6`
192
206
  })
193
- .option('targetBranchChoices', {
194
- // backwards-compatability: `branches` was renamed `targetBranchChoices`
195
- default: (_r = (_q = configOptions.targetBranchChoices) !== null && _q !== void 0 ? _q : configOptions.branches) !== null && _r !== void 0 ? _r : [],
207
+ .option('targetBranchChoice', {
196
208
  description: 'List branches to backport to',
197
- alias: 'targetBranchChoice',
198
209
  type: 'array',
210
+ string: true,
199
211
  })
200
- .option('targetPRLabels', {
201
- // backwards-compatability: `labels` was renamed `targetPRLabels`
202
- default: (_t = (_s = configOptions.targetPRLabels) !== null && _s !== void 0 ? _s : configOptions.labels) !== null && _t !== void 0 ? _t : [],
212
+ .option('targetPRLabel', {
203
213
  description: 'Add labels to the target (backport) PR',
204
- alias: ['labels', 'label', 'l'],
214
+ alias: ['label', 'l'],
205
215
  type: 'array',
206
- })
207
- // cli-only
208
- .option('verify', {
209
- description: `Opposite of no-verify`,
210
- type: 'boolean',
216
+ string: true,
211
217
  })
212
218
  .option('upstream', {
213
- default: configOptions.upstream,
214
219
  description: 'Name of repository',
215
220
  alias: 'up',
216
221
  type: 'string',
217
222
  })
218
223
  .option('username', {
219
- default: configOptions.username,
220
224
  description: 'Github username',
221
225
  type: 'string',
222
226
  })
223
227
  .option('verbose', {
224
- default: (_u = configOptions.verbose) !== null && _u !== void 0 ? _u : false,
225
228
  description: 'Show additional debug information',
226
229
  type: 'boolean',
230
+ })
231
+ // cli-only
232
+ .option('verify', {
233
+ description: `Opposite of no-verify`,
234
+ type: 'boolean',
227
235
  })
228
236
  .alias('version', 'v')
229
237
  .alias('version', 'V')
230
238
  .help()
231
- .epilogue('For bugs, feature requests or questions: https://github.com/sqren/backport/issues\nOr contact me directly: https://twitter.com/sorenlouv').argv;
232
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
233
- const { $0, _, verify, multiple, autoAssign, ...rest } = cliArgs;
234
- return {
235
- ...rest,
236
- // `autoFixConflicts` is not available as cli argument
237
- autoFixConflicts: configOptions.autoFixConflicts,
238
- // auto-assign the current user to the target pull request or the assignees specified
239
- assignees: autoAssign ? [rest.username] : rest.assignees,
240
- // `branchLabelMapping` is not available as cli argument
241
- branchLabelMapping: configOptions.branchLabelMapping,
239
+ .epilogue('For bugs, feature requests or questions: https://github.com/sqren/backport/issues\nOr contact me directly: https://twitter.com/sorenlouv');
240
+ // don't kill process upon error
241
+ // and don't log error to console
242
+ if (!exitOnError) {
243
+ yargsInstance.fail((msg, err) => {
244
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
245
+ if (err) {
246
+ throw err;
247
+ }
248
+ throw new Error(msg);
249
+ });
250
+ }
251
+ const {
252
+ /* eslint-disable @typescript-eslint/no-unused-vars */
253
+ $0, _,
254
+ /* eslint-enable @typescript-eslint/no-unused-vars */
255
+ multiple, multipleBranches, multipleCommits,
256
+ // negations
257
+ verify, noVerify, noCherrypickRef, noFork,
258
+ // array types (should be renamed to plural form)
259
+ assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
260
+ return excludeUndefined({
261
+ ...restOptions,
242
262
  // `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
243
- multipleBranches: multiple !== null && multiple !== void 0 ? multiple : cliArgs.multipleBranches,
244
- multipleCommits: multiple !== null && multiple !== void 0 ? multiple : cliArgs.multipleCommits,
245
- // `verify` is a cli-only flag to flip the default of `no-verify`
246
- noVerify: verify !== null && verify !== void 0 ? verify : rest.noVerify,
247
- // convert from array of primitives to array of object
248
- targetBranchChoices: getTargetBranchChoicesAsObject(rest.targetBranchChoices),
249
- };
263
+ multipleBranches: multiple ?? multipleBranches,
264
+ multipleCommits: multiple ?? multipleCommits,
265
+ // rename array types to plural
266
+ assignees: assignee ?? [],
267
+ commitPaths: path ?? [],
268
+ reviewers: reviewer ?? [],
269
+ sourcePRLabels: sourcePRLabel,
270
+ targetBranchChoices: targetBranchChoice,
271
+ targetBranches: targetBranch,
272
+ targetPRLabels: targetPRLabel,
273
+ // negations (cli-only flags)
274
+ cherrypickRef: noCherrypickRef === true ? false : restOptions.cherrypickRef,
275
+ fork: noFork === true ? false : restOptions.fork,
276
+ noVerify: verify ?? noVerify,
277
+ });
250
278
  }
251
279
  exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
252
- // in the config `branches` can either be a string or an object.
253
- // We need to transform it so that it is always treated as an object troughout the application
254
- function getTargetBranchChoicesAsObject(targetBranchChoices) {
255
- return targetBranchChoices.map((choice) => {
256
- if (lodash_isstring_1.default(choice)) {
257
- return {
258
- name: choice,
259
- checked: false,
260
- };
261
- }
262
- return choice;
263
- });
280
+ function excludeUndefined(obj) {
281
+ Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);
282
+ return obj;
264
283
  }
@@ -2,171 +2,155 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const cliArgs_1 = require("./cliArgs");
4
4
  describe('getOptionsFromCliArgs', () => {
5
- it('should merge config and cli options', () => {
6
- const configOptions = {
7
- accessToken: 'myAccessToken',
8
- all: false,
9
- fork: true,
10
- gitHostname: 'github.com',
11
- githubApiBaseUrlV3: 'https://api.github.com',
12
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
13
- maxNumber: 10,
14
- multipleBranches: true,
15
- multipleCommits: false,
16
- noVerify: true,
17
- prTitle: 'myPrTitle',
18
- sourcePRLabels: [],
19
- targetBranchChoices: [],
20
- targetPRLabels: [],
21
- upstream: 'elastic/kibana',
22
- username: 'sqren',
23
- };
24
- const argv = [
25
- '--branch',
26
- '6.0',
27
- '--branch',
28
- '6.1',
29
- '--upstream',
30
- 'backport-org/backport-demo',
31
- '--all',
32
- '--username',
33
- 'sqren',
34
- ];
35
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
36
- expect(res).toEqual({
37
- accessToken: 'myAccessToken',
38
- all: true,
39
- assignees: [],
40
- ci: false,
41
- dryRun: false,
42
- fork: true,
43
- gitHostname: 'github.com',
44
- githubApiBaseUrlV3: 'https://api.github.com',
45
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
46
- maxNumber: 10,
47
- multipleBranches: true,
48
- multipleCommits: false,
49
- noVerify: true,
50
- prTitle: 'myPrTitle',
51
- resetAuthor: false,
52
- sha: undefined,
53
- sourcePRLabels: [],
54
- targetBranchChoices: [],
55
- targetBranches: ['6.0', '6.1'],
56
- targetPRLabels: [],
57
- upstream: 'backport-org/backport-demo',
58
- username: 'sqren',
59
- verbose: false,
5
+ describe('yargs settings', () => {
6
+ it('should accept both camel-case and dashed-case and convert them to camel cased', () => {
7
+ const argv = [
8
+ '--access-token',
9
+ 'my access token',
10
+ '--githubApiBaseUrlV3',
11
+ 'my api hostname',
12
+ ];
13
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
14
+ expect(res.accessToken).toEqual('my access token');
15
+ expect('access-token' in res).toEqual(false);
16
+ expect(res.githubApiBaseUrlV3).toEqual('my api hostname');
17
+ expect('api-hostname' in res).toEqual(false);
60
18
  });
19
+ it('strips undefined values from the object', () => {
20
+ const argv = [
21
+ '--access-token',
22
+ 'my access token',
23
+ '--username',
24
+ 'sqren',
25
+ '--upstream',
26
+ 'elastic/kibana',
27
+ ];
28
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
29
+ expect(res).toEqual({
30
+ accessToken: 'my access token',
31
+ upstream: 'elastic/kibana',
32
+ username: 'sqren',
33
+ mainline: 1,
34
+ reviewers: [],
35
+ assignees: [],
36
+ commitPaths: [],
37
+ });
38
+ });
39
+ });
40
+ // blocked by: https://github.com/yargs/yargs/issues/1853
41
+ describe('help', () => {
42
+ // eslint-disable-next-line jest/no-commented-out-tests
43
+ // it('should output help', () => {
44
+ // const argv = ['--help'];
45
+ // expect(() =>
46
+ // getOptionsFromCliArgs(argv, { exitOnError: false, returnHelp: true })
47
+ // ).toThrow('asa');
48
+ // });
61
49
  });
62
- it('should accept both camel-case and dashed-case and convert them to camel cased', () => {
63
- const configOptions = {};
64
- const argv = [
65
- '--access-token',
66
- 'my access token',
67
- '--githubApiBaseUrlV3',
68
- 'my api hostname',
69
- ];
70
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
71
- expect(res.accessToken).toEqual('my access token');
72
- expect('access-token' in res).toEqual(false);
73
- expect(res.githubApiBaseUrlV3).toEqual('my api hostname');
74
- expect('api-hostname' in res).toEqual(false);
50
+ describe('sourcePRLabels', () => {
51
+ it('should handle all variations', () => {
52
+ const argv = [
53
+ '--sourcePRLabel',
54
+ 'label a',
55
+ '--sourcePrLabel',
56
+ 'label b',
57
+ '--source-pr-label',
58
+ 'label c',
59
+ ];
60
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
61
+ expect(res.sourcePRLabels).toEqual(['label a', 'label b', 'label c']);
62
+ });
75
63
  });
76
64
  describe('pullNumber', () => {
77
65
  it('should accept `--pr` alias but only return the full representation (`pullNumber`)', () => {
78
- const configOptions = {};
79
66
  const argv = ['--pr', '1337'];
80
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
67
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
81
68
  expect(res.pullNumber).toEqual(1337);
82
69
  //@ts-expect-error
83
70
  expect(res.pr).toBe(undefined);
84
71
  });
85
72
  });
86
- describe('autoAssign', () => {
87
- it('should set assignees to current user if `autoAssign` is true', () => {
88
- const configOptions = { username: 'sqren' };
89
- const argv = ['--auto-assign'];
90
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
91
- expect(res.assignees).toEqual(['sqren']);
92
- });
93
- });
94
73
  describe('assignees', () => {
95
- it('should set assignees', () => {
96
- const configOptions = { username: 'sqren' };
97
- const argv = ['--assignees', 'john'];
98
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
74
+ it('--assignee', () => {
75
+ const argv = ['--assignee', 'john'];
76
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
77
+ expect(res.assignees).toEqual(['john']);
78
+ });
79
+ it('--assign', () => {
80
+ const argv = ['--assign', 'john'];
81
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
99
82
  expect(res.assignees).toEqual(['john']);
100
83
  });
101
84
  });
102
85
  describe('multipleBranches', () => {
103
- it('should be settable', () => {
104
- const configOptions = { multipleBranches: false };
86
+ it('should be undefined by default', () => {
105
87
  const argv = [];
106
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
88
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
89
+ expect(res.multipleBranches).toBe(undefined);
90
+ });
91
+ it('should set to true', () => {
92
+ const argv = ['--multiple-branches', 'true'];
93
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
94
+ expect(res.multipleBranches).toBe(true);
95
+ });
96
+ it('should set to false', () => {
97
+ const argv = ['--multiple-branches', 'false'];
98
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
107
99
  expect(res.multipleBranches).toBe(false);
108
100
  });
109
101
  it('should respect `multiple` option', () => {
110
- const configOptions = { multipleBranches: false };
111
102
  const argv = ['--multiple'];
112
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
103
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
113
104
  expect(res.multipleBranches).toBe(true);
114
105
  });
106
+ it('should conflict when using both', () => {
107
+ const argv = ['--multiple', '--multiple-branches', 'false'];
108
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrow('Arguments multiple and multipleBranches are mutually exclusive');
109
+ });
115
110
  });
116
111
  describe('noVerify', () => {
117
- it('should be settable', () => {
118
- const configOptions = { noVerify: false };
112
+ it('should be undefined by default', () => {
119
113
  const argv = [];
120
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
114
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
115
+ expect(res.noVerify).toBe(undefined);
116
+ });
117
+ it('should set to false', () => {
118
+ const argv = ['--no-verify', 'false'];
119
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
121
120
  expect(res.noVerify).toBe(false);
122
121
  });
123
- it('should be flipped by `verify`', () => {
124
- const configOptions = { noVerify: false };
122
+ it('should set to true', () => {
123
+ const argv = ['--no-verify', 'true'];
124
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
125
+ expect(res.noVerify).toBe(true);
126
+ });
127
+ it('should be enabled by `verify`', () => {
125
128
  const argv = ['--verify'];
126
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
129
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
127
130
  expect(res.noVerify).toBe(true);
128
131
  });
129
132
  });
130
133
  describe('mainline', () => {
131
134
  it('should default to 1', () => {
132
- const configOptions = {};
133
135
  const argv = ['--mainline'];
134
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
136
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
135
137
  expect(res.mainline).toEqual(1);
136
138
  });
137
139
  it('should accept numbers', () => {
138
- const configOptions = {};
139
140
  const argv = ['--mainline', '2'];
140
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
141
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
141
142
  expect(res.mainline).toEqual(2);
142
143
  });
144
+ it('should throw on invalid values', () => {
145
+ const argv = ['--mainline', 'foo'];
146
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrowError('--mainline must be an integer. Received: NaN');
147
+ });
143
148
  });
144
149
  describe('targetBranches', () => {
145
150
  it('should not coerce 6.0 to 6', () => {
146
- const configOptions = {};
147
151
  const argv = ['-b', '6.0'];
148
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
152
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
149
153
  expect(res.targetBranches).toEqual(['6.0']);
150
154
  });
151
155
  });
152
- describe('targetBranchChoices', () => {
153
- it('should support objects', () => {
154
- const configOptions = {
155
- targetBranchChoices: [{ name: '7.x', checked: false }],
156
- };
157
- const argv = [];
158
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
159
- expect(res.targetBranchChoices).toEqual([
160
- { name: '7.x', checked: false },
161
- ]);
162
- });
163
- it('should convert primitive values to objects', () => {
164
- const configOptions = {};
165
- const argv = ['--target-branch-choices', '8.x'];
166
- const res = cliArgs_1.getOptionsFromCliArgs(configOptions, argv);
167
- expect(res.targetBranchChoices).toEqual([
168
- { name: '8.x', checked: false },
169
- ]);
170
- });
171
- });
172
156
  });