-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cda862
commit 7ab87af
Showing
7 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
modules/core/src/main/scala/org/scalasteward/core/application/SupportedVCS.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2018-2019 scala-steward contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.scalasteward.core.application | ||
|
||
import cats.Eq | ||
import cats.implicits._ | ||
import caseapp.core.Error.MalformedValue | ||
import caseapp.core.argparser.ArgParser | ||
|
||
sealed trait SupportedVCS { | ||
import SupportedVCS.{GitHub, Gitlab} | ||
val asString = this match { | ||
case GitHub => "github" | ||
case Gitlab => "gitlab" | ||
} | ||
} | ||
|
||
object SupportedVCS { | ||
case object GitHub extends SupportedVCS | ||
case object Gitlab extends SupportedVCS | ||
|
||
implicit val supportedVCSEq: Eq[SupportedVCS] = | ||
Eq.fromUniversalEquals | ||
|
||
def parse(value: String): Either[String, SupportedVCS] = value match { | ||
case "github" => Right(GitHub) | ||
case "gitlab" => Right(Gitlab) | ||
case unknown => Left(s"Unexpected string '$unknown'") | ||
} | ||
|
||
implicit val supportedVCSParser: ArgParser[SupportedVCS] = | ||
ArgParser[String].xmapError( | ||
_.asString, | ||
s => SupportedVCS.parse(s).leftMap(error => MalformedValue("SupportedVCS", error)) | ||
) | ||
} |
49 changes: 49 additions & 0 deletions
49
modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSelection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2018-2019 scala-steward contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.scalasteward.core.vcs | ||
|
||
import org.scalasteward.core.application.Config | ||
import org.scalasteward.core.util.HttpJsonClient | ||
import org.scalasteward.core.github.GitHubSpecifics | ||
import org.scalasteward.core.github.http4s.Http4sGitHubApiAlg | ||
import org.scalasteward.core.gitlab.http4s.Http4sGitLabApiAlg | ||
import org.scalasteward.core.gitlab.GitlabSpecifics | ||
import org.scalasteward.core.vcs.data.AuthenticatedUser | ||
import cats.effect.Sync | ||
import org.scalasteward.core.application.SupportedVCS.GitHub | ||
import org.scalasteward.core.application.SupportedVCS.Gitlab | ||
|
||
class VCSSelection[F[_]: Sync](implicit client: HttpJsonClient[F], user: AuthenticatedUser) { | ||
private def github(config: Config): (Http4sGitHubApiAlg[F], GitHubSpecifics) = { | ||
import org.scalasteward.core.github.http4s.authentication.addCredentials | ||
|
||
val alg = new Http4sGitHubApiAlg[F](config.vcsApiHost, _ => addCredentials(user)) | ||
val specifics = new GitHubSpecifics(config) | ||
(alg, specifics) | ||
} | ||
private def gitlab(config: Config): (Http4sGitLabApiAlg[F], GitlabSpecifics) = { | ||
import org.scalasteward.core.gitlab.http4s.authentication.addCredentials | ||
|
||
val alg = new Http4sGitLabApiAlg[F](config.vcsApiHost, user, _ => addCredentials(user)) | ||
val specifics = new GitlabSpecifics() | ||
(alg, specifics) | ||
} | ||
def build(config: Config): (VCSApiAlg[F], VCSSpecifics) = config.vcsType match { | ||
case GitHub => github(config) | ||
case Gitlab => gitlab(config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters