Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update github4s to 0.30.0 #618

Merged
merged 11 commits into from
Jan 24, 2022
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ lazy val pluginSettings: Seq[Def.Setting[_]] = Seq(
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3"),
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1"),
libraryDependencies ++= Seq(
"com.47deg" %% "github4s" % "0.28.5",
"org.http4s" %% "http4s-blaze-client" % "0.21.31",
"com.47deg" %% "github4s" % "0.30.0",
"org.http4s" %% "http4s-blaze-client" % "0.23.7",
"net.jcazevedo" %% "moultingyaml" % "0.4.2",
"com.lihaoyi" %% "scalatags" % "0.11.1",
"com.sksamuel.scrimage" %% "scrimage-scala" % "4.0.25",
Expand Down
9 changes: 5 additions & 4 deletions project/dependencies.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ unmanagedResourceDirectories in Compile +=
baseDirectory.in(ThisBuild).value.getParentFile / "src" / "main" / "resources"

libraryDependencies ++= Seq(
"com.47deg" %% "github4s" % "0.24.0",
"net.jcazevedo" %% "moultingyaml" % "0.4.2",
"com.lihaoyi" %% "scalatags" % "0.11.1",
"com.sksamuel.scrimage" %% "scrimage-scala" % "4.0.25"
"com.47deg" %% "github4s" % "0.30.0",
"org.http4s" %% "http4s-blaze-client" % "0.23.7",
"net.jcazevedo" %% "moultingyaml" % "0.4.2",
"com.lihaoyi" %% "scalatags" % "0.11.1",
"com.sksamuel.scrimage" %% "scrimage-scala" % "4.0.25"
)
11 changes: 5 additions & 6 deletions src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package microsites

import java.nio.file._

import cats.effect.{ContextShift, IO, Timer}
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import com.typesafe.sbt.sbtghpages.GhpagesPlugin.autoImport._
import com.typesafe.sbt.site.SitePlugin.autoImport.makeSite
import io.circe._
Expand All @@ -30,7 +31,7 @@ import microsites.ioops.FileWriter._
import microsites.ioops._
import microsites.ioops.syntax._
import microsites.util.MicrositeHelper
import org.http4s.client.blaze.BlazeClientBuilder
import org.http4s.blaze.client.BlazeClientBuilder
import sbt.Keys._
import sbt._
import sbt.complete.DefaultParsers.OptNotSpace
Expand Down Expand Up @@ -476,9 +477,7 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
val githubRepo: String = micrositeGithubRepo.value
val githubToken: Option[String] = micrositeGithubToken.value

implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
implicit val ec: ExecutionContext = ExecutionContext.global
implicit val t: Timer[IO] = IO.timer(ExecutionContext.global)
implicit val executionContext: ExecutionContext = ExecutionContext.global

lazy val log: Logger = streams.value.log

Expand All @@ -492,7 +491,7 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
| * repo: $githubOwner/$githubRepo
| * commitMessage: $commitMessage""".stripMargin)

BlazeClientBuilder[IO](ec).resource
BlazeClientBuilder[IO].resource
.use { client =>
val ghOps: GitHubOps[IO] =
new GitHubOps[IO](client, githubOwner, githubRepo, githubToken)
Expand Down
20 changes: 15 additions & 5 deletions src/main/scala/microsites/github/GitHubOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package microsites.github
import java.io.File

import cats.data.{NonEmptyList, OptionT}
import cats.effect._
import cats.effect.{Ref => _, _}
import cats.effect.kernel.Temporal
import cats.implicits._
import com.github.marklister.base64.Base64._
import github4s._
import github4s.domain._
import microsites.Exceptions._
Expand All @@ -32,7 +32,9 @@ import org.http4s.client._
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

class GitHubOps[F[_]: ConcurrentEffect: Timer](
import java.util.Base64

class GitHubOps[F[_]: Async: Temporal](
client: Client[F],
owner: String,
repo: String,
Expand Down Expand Up @@ -113,7 +115,15 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer](
): F[TreeDataSha] =
for {
gh <- ghWithRateLimit
res <- run(gh.gitData.createBlob(owner, repo, array.toBase64, Some("base64"), headers))
res <- run(
gh.gitData.createBlob(
owner,
repo,
Base64.getEncoder().encode(array).mkString(""),
Some("base64"),
headers
)
)
.map(refInfo => TreeDataSha(filePath, blobMode, blobType, refInfo.sha))
} yield res

Expand Down Expand Up @@ -210,5 +220,5 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer](

// Due to GitHub abuse rate limits, we should wait 1 sec between each request
// https://developer.github.com/guides/best-practices-for-integrators/#dealing-with-abuse-rate-limits
def ghWithRateLimit: F[Github[F]] = Timer[F].sleep(1.second).as(gh)
def ghWithRateLimit: F[Github[F]] = Temporal[F].sleep(1.second).as(gh)
}