Skip to content

Commit

Permalink
Close #340 - Upgrade libraries - effectie, logger-f, http4s, `c…
Browse files Browse the repository at this point in the history
…irce`, `refined`, `hedgehog` and `extras`
  • Loading branch information
kevin-lee committed Mar 31, 2022
1 parent 6634234 commit 06a4422
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 165 deletions.
14 changes: 7 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,23 @@ lazy val props =

final val CrossSbtVersions = List(GlobalSbtVersion).distinct

final val hedgehogVersion = "0.7.0"
final val hedgehogVersion = "0.8.0"

final val newtypeVersion = "0.4.4"

final val catsVersion = "2.6.1"
final val catsEffectVersion = "2.5.1"

final val extrasCatsVersion = "0.1.0"
final val extrasCatsVersion = "0.13.0"

final val effectieVersion = "1.15.0"
final val loggerFVersion = "1.15.0"
final val effectieVersion = "2.0.0-SNAPSHOT"
final val loggerFVersion = "2.0.0-SNAPSHOT"

final val refinedVersion = "0.9.25"
final val refinedVersion = "0.9.27"

final val circeVersion = "0.13.0"
final val circeVersion = "0.14.1"

final val http4sVersion = "0.21.28"
final val http4sVersion = "0.22.12"

final val justSemVerVersion = "0.3.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import cats.effect.IO
import devoops.data.{DevOopsLogLevel, Logging}
import extras.cats.syntax.option._
import kevinlee.github.data.GitHub
import effectie.cats.fx._
import loggerf.logger.{CanLog, SbtLogger}
import loggerf.cats.instances._
import sbt.Keys._
import sbt._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import cats.instances.all._
import cats.syntax.all._
import devoops.data.SbtTaskResult.SbtTaskHistory
import devoops.data._
import effectie.cats.Effectful._
import effectie.cats._
import effectie.syntax.all._
import effectie.core._
import just.semver.SemVer
import kevinlee.git.Git
import kevinlee.git.Git.{BranchName, Repository, TagName}
Expand All @@ -17,7 +17,8 @@ import kevinlee.http.HttpClient
import kevinlee.sbt.SbtCommon.messageOnlyException
import kevinlee.sbt.io.{CaseSensitivity, Io}
import loggerf.logger.{CanLog, SbtLogger}
import org.http4s.client.blaze.BlazeClientBuilder
import loggerf.cats.instances._
import org.http4s.blaze.client.BlazeClientBuilder
import sbt.Keys._
import sbt.{AutoPlugin, File, PluginTrigger, Plugins, Setting}

Expand Down Expand Up @@ -53,6 +54,8 @@ object DevOopsGitHubReleasePlugin extends AutoPlugin {

implicit val devOopsLogLevelValue: DevOopsLogLevel = DevOopsLogLevel.fromStringUnsafe(devOopsLogLevel.value)

import effectie.cats.fx._

val run1: IO[(SbtTaskHistory, Either[SbtTaskError, Unit])] =
getTagVersion[IO](basePath, tagFrom, tagName, tagDesc, pushRepo, projectVersion)
.value
Expand Down Expand Up @@ -109,6 +112,8 @@ object DevOopsGitHubReleasePlugin extends AutoPlugin {

implicit val devOopsLogLevelValue: DevOopsLogLevel = DevOopsLogLevel.fromStringUnsafe(devOopsLogLevel.value)

import effectie.cats.fx._

implicit val log: CanLog = SbtLogger.sbtLoggerCanLog(streams.value.log)
val git = Git[IO]
val sbtTask = SbtTask[IO]
Expand Down Expand Up @@ -172,6 +177,8 @@ object DevOopsGitHubReleasePlugin extends AutoPlugin {

implicit val log: CanLog = SbtLogger.sbtLoggerCanLog(streams.value.log)

import effectie.cats.fx._

BlazeClientBuilder[IO](ec)
.withIdleTimeout(requestTimeout)
.withRequestTimeout(requestTimeout)
Expand Down Expand Up @@ -218,6 +225,8 @@ object DevOopsGitHubReleasePlugin extends AutoPlugin {

implicit val devOopsLogLevelValue: DevOopsLogLevel = DevOopsLogLevel.fromStringUnsafe(devOopsLogLevel.value)

import effectie.cats.fx._

implicit val log: CanLog = SbtLogger.sbtLoggerCanLog(streams.value.log)
val git = Git[IO]
val sbtTask = SbtTask[IO]
Expand Down Expand Up @@ -271,7 +280,7 @@ object DevOopsGitHubReleasePlugin extends AutoPlugin {
},
)

private def getTagVersion[F[_]: EffectConstructor: CanCatch: Monad](
private def getTagVersion[F[_]: Fx: Monad](
basePath: File,
tagFrom: BranchName,
tagName: TagName,
Expand Down Expand Up @@ -333,7 +342,7 @@ object DevOopsGitHubReleasePlugin extends AutoPlugin {
.fold(readOAuthToken(authTokenFile))(token => GitHub.OAuthToken(token).asRight)

@SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
private def runGitHubRelease[F[_]: EffectConstructor: CanCatch: Monad: Timer](
private def runGitHubRelease[F[_]: Fx: CanCatch: Monad: Timer](
tagName: TagName,
baseDir: File,
changelogLocation: GitHub.ChangelogLocation,
Expand Down Expand Up @@ -397,7 +406,7 @@ object DevOopsGitHubReleasePlugin extends AutoPlugin {
} yield ()

@SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
private def runUploadAssetsToGitHubRelease[F[_]: EffectConstructor: CanCatch: Monad](
private def runUploadAssetsToGitHubRelease[F[_]: Fx: CanCatch: Monad](
tagName: TagName,
assets: Vector[File],
baseDir: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package devoops.data
import SbtTaskResult.{SbtTaskHistory, SbtTaskHistoryWriter}
import cats._
import cats.data._
import cats.implicits._
import effectie.cats.Effectful._
import effectie.cats._
import cats.syntax.all._
import effectie.syntax.all._
import effectie.core._
import kevinlee.git.Git
import kevinlee.github.GitHubTask

Expand Down Expand Up @@ -73,9 +73,9 @@ object SbtTask {

def apply[F[_]: SbtTask]: SbtTask[F] = implicitly[SbtTask[F]]

implicit def sbtTaskF[F[_]: EffectConstructor: CanCatch: Monad]: SbtTask[F] = new SbtTaskF[F]
implicit def sbtTaskF[F[_]: Fx: Monad]: SbtTask[F] = new SbtTaskF[F]

final class SbtTaskF[F[_]: EffectConstructor: CanCatch: Monad] extends SbtTask[F] {
final class SbtTaskF[F[_]: Fx: Monad] extends SbtTask[F] {

override def fromNonSbtTask[A](fa: F[Either[SbtTaskError, A]])(
history: A => List[SbtTaskResult]
Expand Down
10 changes: 5 additions & 5 deletions modules/sbt-devoops-github/src/main/scala/kevinlee/git/Git.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package kevinlee.git

import cats._
import cats.data._
import cats.implicits._
import effectie.cats.Effectful._
import effectie.cats._
import cats.syntax.all._
import effectie.syntax.all._
import effectie.core._
import io.circe.{Decoder, Encoder}
import io.estatico.newtype.macros.newtype

Expand Down Expand Up @@ -114,9 +114,9 @@ object Git {

def apply[F[_]: Git]: Git[F] = implicitly[Git[F]]

implicit def gitF[F[_]: EffectConstructor: Monad]: Git[F] = new GitF[F]
implicit def gitF[F[_]: Fx: Monad]: Git[F] = new GitF[F]

final class GitF[F[_]: EffectConstructor: Monad] extends Git[F] {
final class GitF[F[_]: Fx: Monad] extends Git[F] {

override def fromProcessResultToEither[A](
gitCmd: GitCmd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import cats.data.{EitherT, NonEmptyList}
import cats.effect.Timer
import cats.syntax.all._
import devoops.data.DevOopsLogLevel
import effectie.cats.EffectConstructor
import effectie.cats.Effectful._
import effectie.cats.EitherTSupport._
import effectie.core._
import effectie.syntax.all._
import extras.cats.syntax.either._
import kevinlee.git.Git
import kevinlee.github.data.GitHub.Repo
import kevinlee.github.data.GitHubRelease.ReleaseId
import kevinlee.github.data._
import kevinlee.http.{HttpClient, HttpRequest}
import org.http4s.client.dsl.Http4sClientDsl

import java.io.File
import scala.concurrent.ExecutionContext
Expand Down Expand Up @@ -68,7 +69,7 @@ trait GitHubApi[F[_]] {
object GitHubApi {

@SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
def apply[F[_]: Monad: EffectConstructor](httpClient: HttpClient[F])(
def apply[F[_]: Monad: Fx](httpClient: HttpClient[F])(
implicit sbtLogLevel: DevOopsLogLevel
): GitHubApi[F] =
new GitHubApiF[F](httpClient)
Expand All @@ -78,10 +79,10 @@ object GitHubApi {
* https://docs.github.com/en/rest/overview/resources-in-the-rest-api#abuse-rate-limits
*/
def githubWithAbuseRateLimit[F[_]: Monad: Timer](): F[Unit] =
Timer[F].sleep(1.second).as(())
Timer[F].sleep(1.second).void

@SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
final class GitHubApiF[F[_]: Monad: EffectConstructor](
final class GitHubApiF[F[_]: Monad: Fx](
val httpClient: HttpClient[F]
)(implicit sbtLogLevel: DevOopsLogLevel)
extends GitHubApi[F] {
Expand All @@ -98,21 +99,23 @@ object GitHubApi {
map
}

implicit val dsl: Http4sClientDsl[F] = new Http4sClientDsl[F] {}

override def getTags(
repo: GitHub.GitHubRepoWithAuth
): F[Either[GitHubError, List[Repo.Tag]]] = (for {
url <- eitherTRight[GitHubError](s"$baseUrl/repos/${repo.toRepoNameString}/tags")
url <- s"$baseUrl/repos/${repo.toRepoNameString}/tags".rightTF[F, GitHubError]

httpRequest <- eitherTRight[GitHubError](
HttpRequest.withHeaders(
httpRequest <- HttpRequest
.withHeaders(
HttpRequest.Method.get,
HttpRequest.Uri(url),
defaultHeaders ++
repo
.accessToken
.toHeaderList,
)
)
.rightTF

response <- EitherT(
httpClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package kevinlee.github.data

import cats.Monad
import cats.syntax.all._
import effectie.cats.Effectful._
import effectie.cats.Fx
import effectie.core._
import effectie.syntax.all._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.collection.NonEmpty
import eu.timepit.refined.string
Expand All @@ -15,8 +15,8 @@ import io.circe.{Decoder, Encoder, HCursor, Json}
import io.estatico.newtype.macros.{newsubtype, newtype}
import just.sysprocess.{ProcessError, ProcessResult, SysProcess}
import kevinlee.http.HttpRequest
import loggerf.cats._
import loggerf.syntax._
import loggerf.core._
import loggerf.core.syntax.all._

/** @author Kevin Lee
* @since 2019-03-09
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import cats.data.EitherT
import cats.effect._
import cats.syntax.all._
import devoops.data.DevOopsLogLevel
import effectie.cats.EffectConstructor
import effectie.cats.EitherTSupport._
import effectie.core._
import extras.cats.syntax.either._
import fs2.text
import io.circe.Decoder
import loggerf.cats._
import loggerf.syntax._
import loggerf.cats.syntax.all._
import loggerf.core._
import org.http4s.Status.Successful
import org.http4s._
import org.http4s.circe.CirceEntityCodec._
import org.http4s.client.Client
import org.http4s.client.dsl.Http4sClientDsl
import org.http4s.headers._

/** @author Kevin Lee
Expand All @@ -27,6 +28,7 @@ trait HttpClient[F[_]] {
httpRequest: HttpRequest
)(
implicit entityDecoderA: Decoder[A],
dsl: Http4sClientDsl[F],
sbtLogLevel: DevOopsLogLevel
): F[Either[HttpError, A]]

Expand All @@ -35,13 +37,13 @@ trait HttpClient[F[_]] {
object HttpClient {

def apply[
F[_]: Monad: EffectConstructor: ConcurrentEffect: ContextShift: Log
F[_]: Monad: Fx: ConcurrentEffect: ContextShift: Log
](client: Client[F]): HttpClient[F] =
new HttpClientF[F](client)

@SuppressWarnings(Array("org.wartremover.warts.Any", "org.wartremover.warts.Nothing"))
final class HttpClientF[
F[_]: Monad: EffectConstructor: ConcurrentEffect: ContextShift: Log
F[_]: Monad: Fx: ConcurrentEffect: ContextShift: Log
](
client: Client[F]
) extends HttpClient[F] {
Expand All @@ -51,6 +53,7 @@ object HttpClient {
httpRequest: HttpRequest
)(
implicit entityDecoderA: Decoder[A],
dsl: Http4sClientDsl[F],
sbtLogLevel: DevOopsLogLevel
): F[Either[HttpError, A]] =
sendRequest[A](httpRequest).value
Expand All @@ -60,22 +63,19 @@ object HttpClient {
httpRequest: HttpRequest
)(
implicit entityDecoderA: Decoder[A],
dsl: Http4sClientDsl[F],
sbtLogLevel: DevOopsLogLevel
): EitherT[F, HttpError, A] =
for {
request <- EitherT.fromEither(
httpRequest.toHttp4s[F]
)
request <- httpRequest.toHttp4s[F].eitherT

postProcessedReq <- eitherTRightF[HttpError](
postProcessRequest(
request,
postProcessedReq <- postProcessRequest(
request,
// if (httpRequest.isBodyMultipart)
// Set.empty[MediaRange]
// else
implicitly[EntityDecoder[F, A]].consumes,
)
)
EntityDecoder[F, A].consumes,
).rightTF[F, HttpError]

res <-
log(
Expand All @@ -91,15 +91,14 @@ object HttpClient {
)
} yield res

private[this] def postProcessRequest(request: F[Request[F]], mediaRanges: Set[MediaRange]): F[Request[F]] =
request.map { req =>
val mediaRangeList = mediaRanges.toList
mediaRangeList.headOption.fold(req) { head =>
req.putHeaders(
Accept(MediaRangeAndQValue(head), mediaRangeList.drop(1).map(MediaRangeAndQValue(_)): _*)
)
}
private[this] def postProcessRequest(request: Request[F], mediaRanges: Set[MediaRange]): Request[F] = {
val mediaRangeList = mediaRanges.toList
mediaRangeList.headOption.fold(request) { head =>
request.putHeaders(
Accept(MediaRangeAndQValue(head), mediaRangeList.drop(1).map(MediaRangeAndQValue(_)): _*)
)
}
}

private[this] def responseHandler[A](
httpRequest: HttpRequest
Expand Down
Loading

0 comments on commit 06a4422

Please sign in to comment.