@@ -30,13 +30,11 @@ import org.scalasteward.core.application.ExitCodePolicy.{
3030 SuccessOnlyIfAllReposSucceed
3131}
3232import 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 ._
3635import org .scalasteward .core .git .Author
3736import org .scalasteward .core .util .Nel
3837import org .scalasteward .core .util .dateTime .renderFiniteDuration
39-
4038import scala .concurrent .duration ._
4139
4240object Cli {
@@ -45,7 +43,6 @@ object Cli {
4543 object name {
4644 val forgeApiHost = " forge-api-host"
4745 val forgeLogin = " forge-login"
48- val forgeType = " forge-type"
4946 val maxBufferSize = " max-buffer-size"
5047 val processTimeout = " process-timeout"
5148 }
@@ -71,11 +68,6 @@ object Cli {
7168 Validated .fromEither(Uri .fromString(s).leftMap(_.message)).toValidatedNel
7269 }
7370
74- implicit val forgeTypeArgument : Argument [ForgeType ] =
75- Argument .from(name.forgeType) { s =>
76- Validated .fromEither(ForgeType .parse(s)).toValidatedNel
77- }
78-
7971 private val multiple = " (can be used multiple times)"
8072
8173 private val workspace : Opts [File ] =
@@ -109,20 +101,7 @@ object Cli {
109101 flag(" signoff" , " Whether to signoff commits; default: false" ).orFalse
110102
111103 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)
126105
127106 private val vcsApiHost =
128107 option[Uri ](
@@ -132,9 +111,7 @@ object Cli {
132111 ).validate(s " --vcs-api-host is deprecated; use -- ${name.forgeApiHost} instead " )(_ => false )
133112
134113 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)
138115
139116 private val vcsLogin =
140117 option[String ](
@@ -155,16 +132,6 @@ object Cli {
155132 " Whether to add labels on pull or merge requests (if supported by the forge)"
156133 ).orFalse
157134
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-
168135 private val ignoreOptsFiles : Opts [Boolean ] =
169136 flag(
170137 " ignore-opts-files" ,
@@ -195,11 +162,11 @@ object Cli {
195162 s " Read only directory for the sandbox $multiple"
196163 ).orEmpty
197164
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+ }
203170
204171 private val sandboxCfg : Opts [SandboxCfg ] =
205172 (whitelist, readOnly, enableSandbox).mapN(SandboxCfg .apply)
@@ -271,12 +238,6 @@ object Cli {
271238 " Whether to assign the default reviewers to a bitbucket pull request; default: false"
272239 ).orFalse
273240
274- private val bitbucketServerCfg : Opts [BitbucketServerCfg ] =
275- bitbucketServerUseDefaultReviewers.map(BitbucketServerCfg .apply)
276-
277- private val bitbucketCfg : Opts [BitbucketCfg ] =
278- bitbucketUseDefaultReviewers.map(BitbucketCfg .apply)
279-
280241 private val gitlabMergeWhenPipelineSucceeds : Opts [Boolean ] =
281242 flag(
282243 " gitlab-merge-when-pipeline-succeeds" ,
@@ -295,11 +256,6 @@ object Cli {
295256 " Flag indicating if a merge request should remove the source branch when merging."
296257 ).orFalse
297258
298- private val gitLabCfg : Opts [GitLabCfg ] =
299- (gitlabMergeWhenPipelineSucceeds, gitlabRequiredReviewers, gitlabRemoveSourceBranch).mapN(
300- GitLabCfg .apply
301- )
302-
303259 private val githubAppId : Opts [Long ] =
304260 option[Long ](
305261 " github-app-id" ,
@@ -312,17 +268,11 @@ object Cli {
312268 " GitHub application key file. Repos accessible by this app are added to the repos in repos.md. git-ask-pass is still required."
313269 )
314270
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 ] =
319272 option[String ](
320273 " 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+ )
326276
327277 private val refreshBackoffPeriod : Opts [FiniteDuration ] = {
328278 val default = 0 .days
@@ -353,22 +303,120 @@ object Cli {
353303 if (ifAnyRepoSucceeds) SuccessIfAnyRepoSucceeds else SuccessOnlyIfAllReposSucceed
354304 }
355305
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+
356409 private val regular : Opts [Usage ] = (
357410 workspace,
358411 reposFiles,
359412 gitCfg,
360- forgeCfg ,
413+ forge ,
361414 ignoreOptsFiles,
362415 processCfg,
363416 repoConfigCfg,
364417 scalafixCfg,
365418 artifactCfg,
366419 cacheTtl,
367- bitbucketCfg,
368- bitbucketServerCfg,
369- gitLabCfg,
370- azureReposCfg,
371- gitHubApp,
372420 urlCheckerTestUrls,
373421 defaultMavenRepo,
374422 refreshBackoffPeriod,
0 commit comments