@@ -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 ] =
@@ -106,20 +98,7 @@ object Cli {
106
98
flag(" sign-commits" , " Whether to sign commits; default: false" ).orFalse
107
99
108
100
private val gitCfg : Opts [GitCfg ] =
109
- (gitAuthor, gitAskPass, signCommits).mapN(GitCfg .apply)
110
-
111
- private val vcsType =
112
- option[ForgeType ](
113
- " vcs-type" ,
114
- s " deprecated in favor of -- ${name.forgeType}" ,
115
- visibility = Visibility .Partial
116
- ).validate(s " --vcs-type is deprecated; use -- ${name.forgeType} instead " )(_ => false )
117
-
118
- private val forgeType = {
119
- val help = ForgeType .all.map(_.asString).mkString(" One of " , " , " , " " ) +
120
- s " ; default: ${GitHub .asString}"
121
- option[ForgeType ](name.forgeType, help).orElse(vcsType).withDefault(GitHub )
122
- }
101
+ (gitAuthor, signCommits).mapN(GitCfg .apply)
123
102
124
103
private val vcsApiHost =
125
104
option[Uri ](
@@ -129,9 +108,7 @@ object Cli {
129
108
).validate(s " --vcs-api-host is deprecated; use -- ${name.forgeApiHost} instead " )(_ => false )
130
109
131
110
private val forgeApiHost : Opts [Uri ] =
132
- option[Uri ](name.forgeApiHost, s " API URL of the forge; default: ${GitHub .publicApiBaseUrl}" )
133
- .orElse(vcsApiHost)
134
- .withDefault(GitHub .publicApiBaseUrl)
111
+ option[Uri ](name.forgeApiHost, s " API URL of the forge " ).orElse(vcsApiHost)
135
112
136
113
private val vcsLogin =
137
114
option[String ](
@@ -152,16 +129,6 @@ object Cli {
152
129
" Whether to add labels on pull or merge requests (if supported by the forge)"
153
130
).orFalse
154
131
155
- private val forgeCfg : Opts [ForgeCfg ] =
156
- (forgeType, forgeApiHost, forgeLogin, doNotFork, addPrLabels)
157
- .mapN(ForgeCfg .apply)
158
- .validate(
159
- s " ${ForgeType .allNot(_.supportsForking)} do not support fork mode "
160
- )(cfg => cfg.tpe.supportsForking || cfg.doNotFork)
161
- .validate(
162
- s " ${ForgeType .allNot(_.supportsLabels)} do not support pull request labels "
163
- )(cfg => cfg.tpe.supportsLabels || ! cfg.addLabels)
164
-
165
132
private val ignoreOptsFiles : Opts [Boolean ] =
166
133
flag(
167
134
" ignore-opts-files" ,
@@ -192,11 +159,11 @@ object Cli {
192
159
s " Read only directory for the sandbox $multiple"
193
160
).orEmpty
194
161
195
- private val enableSandbox : Opts [Boolean ] =
196
- flag(" enable-sandbox" , " Whether to use the sandbox" )
197
- .map(_ => true )
198
- .orElse(flag( " disable-sandbox " , " Whether to not use the sandbox " ).map(_ => false ) )
199
- .orElse( Opts ( false ))
162
+ private val enableSandbox : Opts [Boolean ] = {
163
+ val enable = flag(" enable-sandbox" , " Whether to use the sandbox" ).map(_ => true )
164
+ val disable = flag( " disable-sandbox " , " Whether to not use the sandbox " ) .map(_ => false )
165
+ enable .orElse(disable).withDefault( false )
166
+ }
200
167
201
168
private val sandboxCfg : Opts [SandboxCfg ] =
202
169
(whitelist, readOnly, enableSandbox).mapN(SandboxCfg .apply)
@@ -268,12 +235,6 @@ object Cli {
268
235
" Whether to assign the default reviewers to a bitbucket pull request; default: false"
269
236
).orFalse
270
237
271
- private val bitbucketServerCfg : Opts [BitbucketServerCfg ] =
272
- bitbucketServerUseDefaultReviewers.map(BitbucketServerCfg .apply)
273
-
274
- private val bitbucketCfg : Opts [BitbucketCfg ] =
275
- bitbucketUseDefaultReviewers.map(BitbucketCfg .apply)
276
-
277
238
private val gitlabMergeWhenPipelineSucceeds : Opts [Boolean ] =
278
239
flag(
279
240
" gitlab-merge-when-pipeline-succeeds" ,
@@ -292,11 +253,6 @@ object Cli {
292
253
" Flag indicating if a merge request should remove the source branch when merging."
293
254
).orFalse
294
255
295
- private val gitLabCfg : Opts [GitLabCfg ] =
296
- (gitlabMergeWhenPipelineSucceeds, gitlabRequiredReviewers, gitlabRemoveSourceBranch).mapN(
297
- GitLabCfg .apply
298
- )
299
-
300
256
private val githubAppId : Opts [Long ] =
301
257
option[Long ](
302
258
" github-app-id" ,
@@ -309,17 +265,11 @@ object Cli {
309
265
" GitHub application key file. Repos accessible by this app are added to the repos in repos.md. git-ask-pass is still required."
310
266
)
311
267
312
- private val gitHubApp : Opts [Option [GitHubApp ]] =
313
- (githubAppId, githubAppKeyFile).mapN(GitHubApp .apply).orNone
314
-
315
- private val azureReposOrganization : Opts [Option [String ]] =
268
+ private val azureReposOrganization : Opts [String ] =
316
269
option[String ](
317
270
" azure-repos-organization" ,
318
- s " The Azure organization (required when -- ${name.forgeType} is ${AzureRepos .asString}) "
319
- ).orNone
320
-
321
- private val azureReposCfg : Opts [AzureReposCfg ] =
322
- azureReposOrganization.map(AzureReposCfg .apply)
271
+ s " The Azure organization (required with --azure-repos) "
272
+ )
323
273
324
274
private val refreshBackoffPeriod : Opts [FiniteDuration ] = {
325
275
val default = 0 .days
@@ -350,22 +300,120 @@ object Cli {
350
300
if (ifAnyRepoSucceeds) SuccessIfAnyRepoSucceeds else SuccessOnlyIfAllReposSucceed
351
301
}
352
302
303
+ private val azureRepos : Opts [Unit ] =
304
+ flag(" azure-repos" , " " )
305
+
306
+ private val bitbucket : Opts [Unit ] =
307
+ flag(" bitbucket" , " " )
308
+
309
+ private val bitbucketServer : Opts [Unit ] =
310
+ flag(" bitbucket-server" , " " )
311
+
312
+ private val gitLab : Opts [Unit ] =
313
+ flag(" gitlab" , " " )
314
+
315
+ private val gitea : Opts [Unit ] =
316
+ flag(" gitea" , " " )
317
+
318
+ private val gitHub : Opts [Unit ] =
319
+ flag(" github" , " " ).withDefault(()) // With default to make it succeed as default option
320
+
321
+ private val forge : Opts [Forge ] = {
322
+ val azureReposOptions =
323
+ (azureRepos, forgeApiHost, forgeLogin, gitAskPass, addPrLabels, azureReposOrganization).mapN(
324
+ (_, apiUri, login, gitAskPass, addLabels, reposOrganization) =>
325
+ AzureRepos (apiUri, login, gitAskPass, addLabels, reposOrganization)
326
+ )
327
+ val bitbucketOptions =
328
+ (
329
+ bitbucket,
330
+ forgeApiHost.withDefault(Bitbucket .defaultApiUri),
331
+ forgeLogin,
332
+ gitAskPass,
333
+ doNotFork,
334
+ bitbucketUseDefaultReviewers
335
+ ).mapN((_, apiUri, login, gitAskPass, doNotFork, useDefaultReviewers) =>
336
+ Bitbucket (apiUri, login, gitAskPass, doNotFork, useDefaultReviewers)
337
+ )
338
+ val bitbucketServerOptions =
339
+ (
340
+ bitbucketServer,
341
+ forgeApiHost,
342
+ forgeLogin,
343
+ gitAskPass,
344
+ bitbucketServerUseDefaultReviewers
345
+ ).mapN((_, apiUri, login, gitAskPass, useDefaultReviewers) =>
346
+ BitbucketServer (apiUri, login, gitAskPass, useDefaultReviewers)
347
+ )
348
+ val gitLabOptions =
349
+ (
350
+ gitLab,
351
+ forgeApiHost.withDefault(GitLab .defaultApiUri),
352
+ forgeLogin,
353
+ gitAskPass,
354
+ doNotFork,
355
+ addPrLabels,
356
+ gitlabMergeWhenPipelineSucceeds,
357
+ gitlabRequiredReviewers,
358
+ gitlabRemoveSourceBranch
359
+ ).mapN(
360
+ (
361
+ _,
362
+ apiUri,
363
+ login,
364
+ gitAskPass,
365
+ doNotFork,
366
+ addLabels,
367
+ mergeWhenPipelineSucceeds,
368
+ requiredReviewers,
369
+ removeSourceBranch
370
+ ) =>
371
+ GitLab (
372
+ apiUri,
373
+ login,
374
+ gitAskPass,
375
+ doNotFork,
376
+ addLabels,
377
+ mergeWhenPipelineSucceeds,
378
+ requiredReviewers,
379
+ removeSourceBranch
380
+ )
381
+ )
382
+ val giteaOptions =
383
+ (gitea, forgeApiHost, forgeLogin, gitAskPass, doNotFork, addPrLabels).mapN(
384
+ (_, apiUri, login, gitAskPass, doNotFork, addLabels) =>
385
+ Gitea (apiUri, login, gitAskPass, doNotFork, addLabels)
386
+ )
387
+ val gitHubOptions =
388
+ (
389
+ gitHub,
390
+ forgeApiHost.withDefault(GitHub .defaultApiUri),
391
+ doNotFork,
392
+ addPrLabels,
393
+ githubAppId,
394
+ githubAppKeyFile
395
+ ).mapN((_, apiUri, doNotFork, addLabels, appId, appKeyFile) =>
396
+ GitHub (apiUri, doNotFork, addLabels, appId, appKeyFile)
397
+ )
398
+ azureReposOptions
399
+ .orElse(bitbucketOptions)
400
+ .orElse(bitbucketServerOptions)
401
+ .orElse(gitLabOptions)
402
+ .orElse(giteaOptions)
403
+ .orElse(gitHubOptions) // GitHub last as default option
404
+ }
405
+
353
406
private val regular : Opts [Usage ] = (
354
407
workspace,
355
408
reposFiles,
356
409
gitCfg,
357
- forgeCfg ,
410
+ forge ,
358
411
ignoreOptsFiles,
359
412
processCfg,
360
413
repoConfigCfg,
361
414
scalafixCfg,
362
415
artifactCfg,
363
416
cacheTtl,
364
- bitbucketCfg,
365
- bitbucketServerCfg,
366
- gitLabCfg,
367
- azureReposCfg,
368
- gitHubApp,
369
417
urlCheckerTestUrls,
370
418
defaultMavenRepo,
371
419
refreshBackoffPeriod,
0 commit comments