@@ -30,13 +30,11 @@ import org.scalasteward.core.application.ExitCodePolicy.{
30
30
SuccessOnlyIfAllReposSucceed
31
31
}
32
32
import org .scalasteward .core .data .Resolver
33
- import org .scalasteward .core .forge .ForgeType
34
- import org .scalasteward .core .forge .ForgeType .{AzureRepos , GitHub }
35
- import org .scalasteward .core .forge .github .GitHubApp
33
+ import org .scalasteward .core .forge .Forge
34
+ import org .scalasteward .core .forge .Forge ._
36
35
import org .scalasteward .core .git .Author
37
36
import org .scalasteward .core .util .Nel
38
37
import org .scalasteward .core .util .dateTime .renderFiniteDuration
39
-
40
38
import scala .concurrent .duration ._
41
39
42
40
object Cli {
@@ -45,7 +43,6 @@ object Cli {
45
43
object name {
46
44
val forgeApiHost = " forge-api-host"
47
45
val forgeLogin = " forge-login"
48
- val forgeType = " forge-type"
49
46
val maxBufferSize = " max-buffer-size"
50
47
val processTimeout = " process-timeout"
51
48
}
@@ -71,11 +68,6 @@ object Cli {
71
68
Validated .fromEither(Uri .fromString(s).leftMap(_.message)).toValidatedNel
72
69
}
73
70
74
- implicit val forgeTypeArgument : Argument [ForgeType ] =
75
- Argument .from(name.forgeType) { s =>
76
- Validated .fromEither(ForgeType .parse(s)).toValidatedNel
77
- }
78
-
79
71
private val multiple = " (can be used multiple times)"
80
72
81
73
private val workspace : Opts [File ] =
@@ -109,20 +101,7 @@ object Cli {
109
101
flag(" signoff" , " Whether to signoff commits; default: false" ).orFalse
110
102
111
103
private val gitCfg : Opts [GitCfg ] =
112
- (gitAuthor, gitAskPass, signCommits, signoff).mapN(GitCfg .apply)
113
-
114
- private val vcsType =
115
- option[ForgeType ](
116
- " vcs-type" ,
117
- s " deprecated in favor of -- ${name.forgeType}" ,
118
- visibility = Visibility .Partial
119
- ).validate(s " --vcs-type is deprecated; use -- ${name.forgeType} instead " )(_ => false )
120
-
121
- private val forgeType = {
122
- val help = ForgeType .all.map(_.asString).mkString(" One of " , " , " , " " ) +
123
- s " ; default: ${GitHub .asString}"
124
- option[ForgeType ](name.forgeType, help).orElse(vcsType).withDefault(GitHub )
125
- }
104
+ (gitAuthor, signCommits, signoff).mapN(GitCfg .apply)
126
105
127
106
private val vcsApiHost =
128
107
option[Uri ](
@@ -132,9 +111,7 @@ object Cli {
132
111
).validate(s " --vcs-api-host is deprecated; use -- ${name.forgeApiHost} instead " )(_ => false )
133
112
134
113
private val forgeApiHost : Opts [Uri ] =
135
- option[Uri ](name.forgeApiHost, s " API URL of the forge; default: ${GitHub .publicApiBaseUrl}" )
136
- .orElse(vcsApiHost)
137
- .withDefault(GitHub .publicApiBaseUrl)
114
+ option[Uri ](name.forgeApiHost, s " API URL of the forge " ).orElse(vcsApiHost)
138
115
139
116
private val vcsLogin =
140
117
option[String ](
@@ -155,16 +132,6 @@ object Cli {
155
132
" Whether to add labels on pull or merge requests (if supported by the forge)"
156
133
).orFalse
157
134
158
- private val forgeCfg : Opts [ForgeCfg ] =
159
- (forgeType, forgeApiHost, forgeLogin, doNotFork, addPrLabels)
160
- .mapN(ForgeCfg .apply)
161
- .validate(
162
- s " ${ForgeType .allNot(_.supportsForking)} do not support fork mode "
163
- )(cfg => cfg.tpe.supportsForking || cfg.doNotFork)
164
- .validate(
165
- s " ${ForgeType .allNot(_.supportsLabels)} do not support pull request labels "
166
- )(cfg => cfg.tpe.supportsLabels || ! cfg.addLabels)
167
-
168
135
private val ignoreOptsFiles : Opts [Boolean ] =
169
136
flag(
170
137
" ignore-opts-files" ,
@@ -195,11 +162,11 @@ object Cli {
195
162
s " Read only directory for the sandbox $multiple"
196
163
).orEmpty
197
164
198
- private val enableSandbox : Opts [Boolean ] =
199
- flag(" enable-sandbox" , " Whether to use the sandbox" )
200
- .map(_ => true )
201
- .orElse(flag( " disable-sandbox " , " Whether to not use the sandbox " ).map(_ => false ) )
202
- .orElse( Opts ( false ))
165
+ private val enableSandbox : Opts [Boolean ] = {
166
+ val enable = flag(" enable-sandbox" , " Whether to use the sandbox" ).map(_ => true )
167
+ val disable = flag( " disable-sandbox " , " Whether to not use the sandbox " ) .map(_ => false )
168
+ enable .orElse(disable).withDefault( false )
169
+ }
203
170
204
171
private val sandboxCfg : Opts [SandboxCfg ] =
205
172
(whitelist, readOnly, enableSandbox).mapN(SandboxCfg .apply)
@@ -271,12 +238,6 @@ object Cli {
271
238
" Whether to assign the default reviewers to a bitbucket pull request; default: false"
272
239
).orFalse
273
240
274
- private val bitbucketServerCfg : Opts [BitbucketServerCfg ] =
275
- bitbucketServerUseDefaultReviewers.map(BitbucketServerCfg .apply)
276
-
277
- private val bitbucketCfg : Opts [BitbucketCfg ] =
278
- bitbucketUseDefaultReviewers.map(BitbucketCfg .apply)
279
-
280
241
private val gitlabMergeWhenPipelineSucceeds : Opts [Boolean ] =
281
242
flag(
282
243
" gitlab-merge-when-pipeline-succeeds" ,
@@ -295,11 +256,6 @@ object Cli {
295
256
" Flag indicating if a merge request should remove the source branch when merging."
296
257
).orFalse
297
258
298
- private val gitLabCfg : Opts [GitLabCfg ] =
299
- (gitlabMergeWhenPipelineSucceeds, gitlabRequiredReviewers, gitlabRemoveSourceBranch).mapN(
300
- GitLabCfg .apply
301
- )
302
-
303
259
private val githubAppId : Opts [Long ] =
304
260
option[Long ](
305
261
" github-app-id" ,
@@ -312,17 +268,11 @@ object Cli {
312
268
" GitHub application key file. Repos accessible by this app are added to the repos in repos.md. git-ask-pass is still required."
313
269
)
314
270
315
- private val gitHubApp : Opts [Option [GitHubApp ]] =
316
- (githubAppId, githubAppKeyFile).mapN(GitHubApp .apply).orNone
317
-
318
- private val azureReposOrganization : Opts [Option [String ]] =
271
+ private val azureReposOrganization : Opts [String ] =
319
272
option[String ](
320
273
" azure-repos-organization" ,
321
- s " The Azure organization (required when -- ${name.forgeType} is ${AzureRepos .asString}) "
322
- ).orNone
323
-
324
- private val azureReposCfg : Opts [AzureReposCfg ] =
325
- azureReposOrganization.map(AzureReposCfg .apply)
274
+ s " The Azure organization (required with --azure-repos) "
275
+ )
326
276
327
277
private val refreshBackoffPeriod : Opts [FiniteDuration ] = {
328
278
val default = 0 .days
@@ -353,22 +303,120 @@ object Cli {
353
303
if (ifAnyRepoSucceeds) SuccessIfAnyRepoSucceeds else SuccessOnlyIfAllReposSucceed
354
304
}
355
305
306
+ private val azureRepos : Opts [Unit ] =
307
+ flag(" azure-repos" , " " )
308
+
309
+ private val bitbucket : Opts [Unit ] =
310
+ flag(" bitbucket" , " " )
311
+
312
+ private val bitbucketServer : Opts [Unit ] =
313
+ flag(" bitbucket-server" , " " )
314
+
315
+ private val gitLab : Opts [Unit ] =
316
+ flag(" gitlab" , " " )
317
+
318
+ private val gitea : Opts [Unit ] =
319
+ flag(" gitea" , " " )
320
+
321
+ private val gitHub : Opts [Unit ] =
322
+ flag(" github" , " " ).withDefault(()) // With default to make it succeed as default option
323
+
324
+ private val forge : Opts [Forge ] = {
325
+ val azureReposOptions =
326
+ (azureRepos, forgeApiHost, forgeLogin, gitAskPass, addPrLabels, azureReposOrganization).mapN(
327
+ (_, apiUri, login, gitAskPass, addLabels, reposOrganization) =>
328
+ AzureRepos (apiUri, login, gitAskPass, addLabels, reposOrganization)
329
+ )
330
+ val bitbucketOptions =
331
+ (
332
+ bitbucket,
333
+ forgeApiHost.withDefault(Bitbucket .defaultApiUri),
334
+ forgeLogin,
335
+ gitAskPass,
336
+ doNotFork,
337
+ bitbucketUseDefaultReviewers
338
+ ).mapN((_, apiUri, login, gitAskPass, doNotFork, useDefaultReviewers) =>
339
+ Bitbucket (apiUri, login, gitAskPass, doNotFork, useDefaultReviewers)
340
+ )
341
+ val bitbucketServerOptions =
342
+ (
343
+ bitbucketServer,
344
+ forgeApiHost,
345
+ forgeLogin,
346
+ gitAskPass,
347
+ bitbucketServerUseDefaultReviewers
348
+ ).mapN((_, apiUri, login, gitAskPass, useDefaultReviewers) =>
349
+ BitbucketServer (apiUri, login, gitAskPass, useDefaultReviewers)
350
+ )
351
+ val gitLabOptions =
352
+ (
353
+ gitLab,
354
+ forgeApiHost.withDefault(GitLab .defaultApiUri),
355
+ forgeLogin,
356
+ gitAskPass,
357
+ doNotFork,
358
+ addPrLabels,
359
+ gitlabMergeWhenPipelineSucceeds,
360
+ gitlabRequiredReviewers,
361
+ gitlabRemoveSourceBranch
362
+ ).mapN(
363
+ (
364
+ _,
365
+ apiUri,
366
+ login,
367
+ gitAskPass,
368
+ doNotFork,
369
+ addLabels,
370
+ mergeWhenPipelineSucceeds,
371
+ requiredReviewers,
372
+ removeSourceBranch
373
+ ) =>
374
+ GitLab (
375
+ apiUri,
376
+ login,
377
+ gitAskPass,
378
+ doNotFork,
379
+ addLabels,
380
+ mergeWhenPipelineSucceeds,
381
+ requiredReviewers,
382
+ removeSourceBranch
383
+ )
384
+ )
385
+ val giteaOptions =
386
+ (gitea, forgeApiHost, forgeLogin, gitAskPass, doNotFork, addPrLabels).mapN(
387
+ (_, apiUri, login, gitAskPass, doNotFork, addLabels) =>
388
+ Gitea (apiUri, login, gitAskPass, doNotFork, addLabels)
389
+ )
390
+ val gitHubOptions =
391
+ (
392
+ gitHub,
393
+ forgeApiHost.withDefault(GitHub .defaultApiUri),
394
+ doNotFork,
395
+ addPrLabels,
396
+ githubAppId,
397
+ githubAppKeyFile
398
+ ).mapN((_, apiUri, doNotFork, addLabels, appId, appKeyFile) =>
399
+ GitHub (apiUri, doNotFork, addLabels, appId, appKeyFile)
400
+ )
401
+ azureReposOptions
402
+ .orElse(bitbucketOptions)
403
+ .orElse(bitbucketServerOptions)
404
+ .orElse(gitLabOptions)
405
+ .orElse(giteaOptions)
406
+ .orElse(gitHubOptions) // GitHub last as default option
407
+ }
408
+
356
409
private val regular : Opts [Usage ] = (
357
410
workspace,
358
411
reposFiles,
359
412
gitCfg,
360
- forgeCfg ,
413
+ forge ,
361
414
ignoreOptsFiles,
362
415
processCfg,
363
416
repoConfigCfg,
364
417
scalafixCfg,
365
418
artifactCfg,
366
419
cacheTtl,
367
- bitbucketCfg,
368
- bitbucketServerCfg,
369
- gitLabCfg,
370
- azureReposCfg,
371
- gitHubApp,
372
420
urlCheckerTestUrls,
373
421
defaultMavenRepo,
374
422
refreshBackoffPeriod,
0 commit comments