Skip to content

Commit

Permalink
feature: Cross-compile for Scala 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Oct 23, 2023
1 parent c475ef0 commit 1f79db2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
18 changes: 15 additions & 3 deletions build.sbt
@@ -1,16 +1,19 @@
name := """bitbucket-scala-client"""

val scala212 = "2.12.10"
val scala213 = "2.13.12"
val scalaVersions = Seq(scala212, scala213)

val play27 = "2.7.4"
val play28 = "2.8.2"

lazy val playJsonVersion = settingKey[String]("The version of play-json used for building.")
ThisBuild / playJsonVersion := play27

scalaVersion := scala212
ThisBuild / scalaVersion := scala212
ThisBuild / crossScalaVersions := scalaVersions

scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Ywarn-adapted-args", "-Xlint")
scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Xlint")

resolvers +=
"Typesafe maven repository" at "https://repo.typesafe.com/typesafe/maven-releases/"
Expand All @@ -19,6 +22,15 @@ libraryDependencies ++= Dependencies.playJson(playJsonVersion.value) ++ Seq(
"org.scalatest" %% "scalatest" % "3.0.8" % Test
)

libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, major)) if major <= 12 =>
Seq()
case _ =>
Seq("org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4")
}
}

organizationName := "Codacy"

organizationHomepage := Some(new URL("https://www.codacy.com"))
Expand Down Expand Up @@ -49,7 +61,7 @@ name := s"${name.value}_playjson${playJsonVersion.value.split('.').take(2).mkStr
* (which is not an allowed sbt alias name)
*/
def addCrossAlias(command: String) = {
val matrix = Seq(scala212 -> Seq(play27, play28))
val matrix = Seq(scala212 -> Seq(play27, play28), scala213 -> Seq(play28))

addCommandAlias(
s"cross${command.split(':').map(_.capitalize).mkString}",
Expand Down
Expand Up @@ -14,6 +14,7 @@ import com.codacy.client.bitbucket.util.UrlHelper._
import scala.compat.Platform.EOL
import scala.concurrent.Await
import scala.concurrent.duration.{Duration, SECONDS}
import scala.collection.parallel.immutable.ParRange
import scala.util.{Failure, Properties, Success, Try}

object BitbucketClientBase {
Expand Down Expand Up @@ -102,20 +103,18 @@ abstract class BitbucketClientBase(val client: WSClient, credentials: Credential
pagelen <- (json \ "pagelen").asOpt[Double]
} yield {
val lastPage = math.ceil(size / pagelen).toInt
(FIRST_PAGE + 1 to lastPage).par
.map { page =>
val nextUrl = new URI(request.url).addQuery(s"page=$page").toString
get(nextUrl) match {
case Right(nextJson) => extractValues(nextJson)
case Left(error) => FailedResponse(error.detail)
}
new ParRange(FIRST_PAGE + 1 to lastPage).map { page =>
val nextUrl = new URI(request.url).addQuery(s"page=$page").toString
get(nextUrl) match {
case Right(nextJson) => extractValues(nextJson)
case Left(error) => FailedResponse(error.detail)
}
.to[Seq]
}.toSeq
}).getOrElse(Seq(SuccessfulResponse(Seq.empty)))

val values = extractValues(json)

(values +: nextPages).foldLeft[RequestResponse[Seq[T]]](SuccessfulResponse(Seq.empty[T])) { (a, b) =>
(Seq(values) ++ nextPages).foldLeft[RequestResponse[Seq[T]]](SuccessfulResponse(Seq.empty[T])) { (a, b) =>
RequestResponse.applyDiscardingPaginationInfo(a, b)
}

Expand Down
Expand Up @@ -84,6 +84,6 @@ object PullRequest {
links.flatMap {
case (linkTypeStr, link) =>
ApiUrlType.find(linkTypeStr).map(ApiUrl(_, link))
}(collection.breakOut)
}.toSeq
}
}
Expand Up @@ -23,7 +23,7 @@ object SimpleCommit {
parents = (json \ "parents" \\ "hash").flatMap(_.asOpt[String])
date <- (json \ "date").asOpt[LocalDateTime]
message <- (json \ "message").asOpt[String]
} yield SimpleCommit(hash, username, parents, date, message))
} yield SimpleCommit(hash, username, parents.toSeq, date, message))
.map(JsSuccess(_))
.getOrElse(JsError("could not read commit"))
}
Expand Down

0 comments on commit 1f79db2

Please sign in to comment.