Skip to content

Commit

Permalink
Merge pull request #3255 from scala-steward-org/topic/mv-uri-encoder
Browse files Browse the repository at this point in the history
Move `Encoder[Uri]` to `util.uri`
  • Loading branch information
fthomas authored Dec 28, 2023
2 parents ce93c01 + c024435 commit 0ab0c50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,32 @@ package org.scalasteward.core.forge.gitea

import cats._
import cats.implicits._
import org.scalasteward.core.git.Branch
import org.scalasteward.core.git.Sha1
import org.scalasteward.core.util.HttpJsonClient
import io.circe._
import io.circe.generic.semiauto.{deriveCodec, deriveEncoder}
import org.http4s.{Request, Uri}
import org.scalasteward.core.application.Config.ForgeCfg
import org.scalasteward.core.data.Repo
import org.scalasteward.core.forge.ForgeApiAlg
import org.scalasteward.core.forge.data._
import org.scalasteward.core.forge.gitea.GiteaApiAlg._
import org.scalasteward.core.git.{Branch, Sha1}
import org.scalasteward.core.util.uri._
import org.scalasteward.core.util.{intellijThisImportIsUsed, HttpJsonClient}
import org.typelevel.log4cats.Logger

// docs
// - https://docs.gitea.io/en-us/api-usage/
// - https://try.gitea.io/api/swagger
// - https://codeberg.org/api/swagger
object GiteaApiAlg {
import io.circe._
import io.circe.generic.semiauto.deriveCodec
import org.scalasteward.core.util.uri._
implicit val uriEncoder: Encoder[Uri] = Encoder[String].contramap[Uri](_.renderString)

val DefaultLabelColor = "#e01060"

case class CreateForkOption(
name: Option[String], // name of the forked repository
organization: Option[String] // organization name, if forking into an organization
)
implicit val createForkOptionCodec: Encoder[CreateForkOption] = deriveCodec
implicit val createForkOptionEncoder: Encoder[CreateForkOption] = deriveEncoder

case class User(
login: String,
Expand Down Expand Up @@ -116,14 +115,15 @@ object GiteaApiAlg {

case class AttachLabelReq(labels: Vector[Int])
implicit val attachLabelReqCodec: Codec[AttachLabelReq] = deriveCodec

intellijThisImportIsUsed(uriEncoder)
}

final class GiteaApiAlg[F[_]: HttpJsonClient](
vcs: ForgeCfg,
modify: Request[F] => F[Request[F]]
)(implicit logger: Logger[F], F: MonadThrow[F])
extends ForgeApiAlg[F] {
import GiteaApiAlg._

def client: HttpJsonClient[F] = implicitly
val url = new Url(vcs.apiHost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.scalasteward.core.util

import cats.syntax.all._
import io.circe.{Decoder, KeyDecoder, KeyEncoder}
import io.circe.{Decoder, Encoder, KeyDecoder, KeyEncoder}
import monocle.Optional
import org.http4s.Uri
import org.http4s.Uri.{Authority, Scheme, UserInfo}
Expand All @@ -26,16 +26,19 @@ object uri {
implicit val uriDecoder: Decoder[Uri] =
Decoder[String].emap(s => Uri.fromString(s).leftMap(_.getMessage))

implicit val uriEncoder: Encoder[Uri] =
Encoder[String].contramap[Uri](_.renderString)

implicit val uriKeyDecoder: KeyDecoder[Uri] =
KeyDecoder.instance(Uri.fromString(_).toOption)

implicit val uriKeyEncoder: KeyEncoder[Uri] =
KeyEncoder.instance(_.renderString)

val withAuthority: Optional[Uri, Authority] =
private val withAuthority: Optional[Uri, Authority] =
Optional[Uri, Authority](_.authority)(authority => _.copy(authority = Some(authority)))

val authorityWithUserInfo: Optional[Authority, UserInfo] =
private val authorityWithUserInfo: Optional[Authority, UserInfo] =
Optional[Authority, UserInfo](_.userInfo)(userInfo => _.copy(userInfo = Some(userInfo)))

val withUserInfo: Optional[Uri, UserInfo] =
Expand Down

0 comments on commit 0ab0c50

Please # to comment.