Skip to content

Commit e67e240

Browse files
committed
Apply scalafmt
1 parent acdc04f commit e67e240

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+429
-248
lines changed

.scalafmt.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version = "1.5.1"
2+
style = IntelliJ
3+
4+
align = none
5+
assumeStandardLibraryStripMargin = false
6+
binPack.literalArgumentLists = true
7+
binPack.parentConstructors = false
8+
continuationIndent.defnSite = 4
9+
danglingParentheses = true
10+
docstrings = ScalaDoc
11+
includeCurlyBraceInSelectChains = true
12+
lineEndings = unix
13+
maxColumn = 120
14+
newlines.alwaysBeforeTopLevelStatements = true
15+
newlines.penalizeSingleSelectMultiArgList = false
16+
newlines.sometimesBeforeColonInMethodReturnType = true
17+
optIn.breakChainOnFirstMethodDot = true
18+
project.git = true
19+
# rewrite.rules = [ AvoidInfix, SortImports, PreferCurlyFors ]
20+
# https://github.com/scalameta/scalafmt/issues/932 removing AvoidInfix
21+
rewrite.rules = [ SortImports, PreferCurlyFors ]
22+
spaces.afterKeywordBeforeParen = true
23+
24+
project.includeFilters = [".*\\.sbt$", ".*\\.scala$"]
25+
project.excludeFilters = [".*\\.scala.html$", "target/.*", "modules/admin/target/.*"]
26+
onTestFailure = "To fix this, run `scalafmt` within sbt or `sbt scalafmt` on the project base directory"

build.sbt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,25 @@ name := """bitbucket-scala-client"""
77

88
scalaVersion := "2.11.12"
99

10-
scalacOptions := Seq("-deprecation",
11-
"-feature",
12-
"-unchecked",
13-
"-Ywarn-adapted-args",
14-
"-Xlint")
10+
scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Ywarn-adapted-args", "-Xlint")
1511

1612
resolvers += "Typesafe maven repository" at "http://repo.typesafe.com/typesafe/maven-releases/"
1713

18-
libraryDependencies ++= Seq(
19-
playWs,
20-
playJson,
21-
scalatest % Test
22-
)
14+
libraryDependencies ++= Seq(playWs, playJson, scalatest % Test)
2315

2416
mimaPreviousArtifacts := {
2517
val latestVersion = JSON
2618
.parseFull(
2719
Source
28-
.fromURL(
29-
"https://api.github.com/repos/codacy/bitbucket-scala-client/releases/latest")
20+
.fromURL("https://api.github.com/repos/codacy/bitbucket-scala-client/releases/latest")
3021
.mkString
3122
)
3223
.flatMap(_.asInstanceOf[Map[String, String]].get("tag_name"))
3324
.getOrElse("5.0.0")
3425
Set("com.codacy" %% "bitbucket-scala-client" % latestVersion)
3526
}
3627
mimaBinaryIssueFilters ++= ignoredABIProblems
28+
3729
val ignoredABIProblems = {
3830
import com.typesafe.tools.mima.core._
3931
import com.typesafe.tools.mima.core.ProblemFilters._
@@ -51,8 +43,10 @@ description := "Bitbucket Scala Client"
5143
homepage := Some(url("https://github.com/codacy/bitbucket-scala-client.git"))
5244

5345
scmInfo := Some(
54-
ScmInfo(url("https://github.com/codacy/bitbucket-scala-client.git"),
55-
"scm:git:[email protected]:codacy/bitbucket-scala-client.git")
46+
ScmInfo(
47+
url("https://github.com/codacy/bitbucket-scala-client.git"),
48+
"scm:git:[email protected]:codacy/bitbucket-scala-client.git"
49+
)
5650
)
5751

5852
pgpPassphrase := Option(System.getenv("SONATYPE_GPG_PASSPHRASE"))

src/main/scala/com/codacy/client/bitbucket/client/Authentication.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ object Authentication {
2222
*/
2323
case class BasicAuthCredentials(username: String, password: String) extends Credentials
2424

25-
2625
sealed trait Authenticator {
2726
def authenticate(req: WSRequest): WSRequest
2827
}
2928

3029
object Authenticator {
31-
def fromCredentials(credentials: Credentials): Authenticator = {
30+
31+
def fromCredentials(credentials: Credentials): Authenticator = {
3232
credentials match {
33-
case c: OAuthCredentials => new OAuthAuthenticator(c)
34-
case c: OAuth2Credentials => new OAuth2Authenticator(c)
33+
case c: OAuthCredentials => new OAuthAuthenticator(c)
34+
case c: OAuth2Credentials => new OAuth2Authenticator(c)
3535
case c: BasicAuthCredentials => new BasicAuthAuthenticator(c)
3636
}
3737
}
@@ -47,11 +47,14 @@ object Authentication {
4747
}
4848

4949
class OAuth2Authenticator(credentials: OAuth2Credentials) extends Authenticator {
50-
override def authenticate(req: WSRequest): WSRequest = req.withQueryString("access_token" -> credentials.accessToken)
50+
override def authenticate(req: WSRequest): WSRequest =
51+
req.withQueryString("access_token" -> credentials.accessToken)
5152
}
5253

5354
class BasicAuthAuthenticator(credentials: BasicAuthCredentials) extends Authenticator {
54-
def authenticate(req: WSRequest): WSRequest = req.withAuth(credentials.username, credentials.password, WSAuthScheme.BASIC)
55+
56+
def authenticate(req: WSRequest): WSRequest =
57+
req.withAuth(credentials.username, credentials.password, WSAuthScheme.BASIC)
5558
}
5659

5760
/**

src/main/scala/com/codacy/client/bitbucket/client/BitbucketClient.scala

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import scala.concurrent.Await
1515
import scala.concurrent.duration.{Duration, SECONDS}
1616
import scala.util.{Failure, Properties, Success, Try}
1717

18-
1918
class BitbucketClient(credentials: Credentials) {
2019

2120
private lazy val requestTimeout = Duration(10, SECONDS)
@@ -27,7 +26,8 @@ class BitbucketClient(credentials: Credentials) {
2726
*/
2827
def execute[T](request: Request[T])(implicit reader: Reads[T]): RequestResponse[T] = {
2928
get(request.url) match {
30-
case Right(json) => json.validate[T].fold(e => FailedResponse(s"Failed to parse json ($e): $json"), a => SuccessfulResponse(a))
29+
case Right(json) =>
30+
json.validate[T].fold(e => FailedResponse(s"Failed to parse json ($e): $json"), a => SuccessfulResponse(a))
3131
case Left(error) => FailedResponse(error.detail)
3232
}
3333
}
@@ -39,7 +39,9 @@ class BitbucketClient(credentials: Credentials) {
3939
val FIRST_PAGE = 1
4040

4141
def extractValues(json: JsValue): RequestResponse[Seq[T]] =
42-
(json \ "values").validate[Seq[T]].fold(e => FailedResponse(s"Failed to parse json ($e): $json"), a => SuccessfulResponse(a))
42+
(json \ "values")
43+
.validate[Seq[T]]
44+
.fold(e => FailedResponse(s"Failed to parse json ($e): $json"), a => SuccessfulResponse(a))
4345

4446
get(request.url) match {
4547
case Right(json) =>
@@ -48,20 +50,21 @@ class BitbucketClient(credentials: Credentials) {
4850
pagelen <- (json \ "pagelen").asOpt[Double]
4951
} yield {
5052
val lastPage = math.ceil(size / pagelen).toInt
51-
(FIRST_PAGE + 1 to lastPage).par.map { page =>
52-
val nextUrl = new URI(request.url).addQuery(s"page=$page").toString
53-
get(nextUrl) match {
54-
case Right(nextJson) => extractValues(nextJson)
55-
case Left(error) => FailedResponse(error.detail)
53+
(FIRST_PAGE + 1 to lastPage).par
54+
.map { page =>
55+
val nextUrl = new URI(request.url).addQuery(s"page=$page").toString
56+
get(nextUrl) match {
57+
case Right(nextJson) => extractValues(nextJson)
58+
case Left(error) => FailedResponse(error.detail)
59+
}
5660
}
57-
}.to[Seq]
61+
.to[Seq]
5862
}).getOrElse(Seq(SuccessfulResponse(Seq.empty)))
5963

6064
val values = extractValues(json)
6165

62-
(values +: nextPages).foldLeft[RequestResponse[Seq[T]]](SuccessfulResponse(Seq.empty[T])) {
63-
(a, b) =>
64-
RequestResponse.apply(a, b)
66+
(values +: nextPages).foldLeft[RequestResponse[Seq[T]]](SuccessfulResponse(Seq.empty[T])) { (a, b) =>
67+
RequestResponse.apply(a, b)
6568
}
6669

6770
case Left(error) =>
@@ -72,11 +75,17 @@ class BitbucketClient(credentials: Credentials) {
7275
/*
7376
* Does an API request
7477
*/
75-
private def performRequest[D, T](method: String, request: Request[T], values: D)(implicit reader: Reads[T], writer: Writeable[D]): RequestResponse[T] = withClientRequest { client =>
76-
val jpromise = client.url(request.url)
78+
private def performRequest[D, T](method: String, request: Request[T], values: D)(
79+
implicit reader: Reads[T],
80+
writer: Writeable[D]
81+
): RequestResponse[T] = withClientRequest { client =>
82+
val jpromise = client
83+
.url(request.url)
7784
.authenticate(authenticator)
7885
.withFollowRedirects(follow = true)
79-
.withMethod(method).withBody(values).execute()
86+
.withMethod(method)
87+
.withBody(values)
88+
.execute()
8089
val result = Await.result(jpromise, requestTimeout)
8190

8291
val value = if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED).contains(result.status)) {
@@ -108,15 +117,20 @@ class BitbucketClient(credentials: Credentials) {
108117
value
109118
}
110119

111-
def postForm[D, T](request: Request[T], values: D)(implicit reader: Reads[T], writer: Writeable[D]): RequestResponse[T] = {
120+
def postForm[D, T](
121+
request: Request[T],
122+
values: D
123+
)(implicit reader: Reads[T], writer: Writeable[D]): RequestResponse[T] = {
112124
performRequest("POST", request, values)
113125
}
114126

115127
def postJson[T](request: Request[T], values: JsValue)(implicit reader: Reads[T]): RequestResponse[T] = {
116128
performRequest("POST", request, values)
117129
}
118130

119-
def putForm[T](request: Request[T], values: Map[String, Seq[String]])(implicit reader: Reads[T]): RequestResponse[T] = {
131+
def putForm[T](request: Request[T], values: Map[String, Seq[String]])(
132+
implicit reader: Reads[T]
133+
): RequestResponse[T] = {
120134
performRequest("PUT", request, values)
121135
}
122136

@@ -126,23 +140,26 @@ class BitbucketClient(credentials: Credentials) {
126140

127141
/* copy paste from post ... */
128142
def delete[T](url: String): RequestResponse[Boolean] = withClientRequest { client =>
129-
val jpromise = client.url(url)
143+
val jpromise = client
144+
.url(url)
130145
.authenticate(authenticator)
131146
.withFollowRedirects(follow = true)
132147
.delete()
133148
val result = Await.result(jpromise, requestTimeout)
134149

135-
val value = if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED, HTTPStatusCodes.NO_CONTENT).contains(result.status)) {
136-
SuccessfulResponse(true)
137-
} else {
138-
FailedResponse(result.statusText)
139-
}
150+
val value =
151+
if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED, HTTPStatusCodes.NO_CONTENT).contains(result.status)) {
152+
SuccessfulResponse(true)
153+
} else {
154+
FailedResponse(result.statusText)
155+
}
140156

141157
value
142158
}
143159

144160
private def get(url: String): Either[ResponseError, JsValue] = withClientEither { client =>
145-
val jpromise = client.url(url)
161+
val jpromise = client
162+
.url(url)
146163
.authenticate(authenticator)
147164
.withFollowRedirects(follow = true)
148165
.get()
@@ -163,10 +180,11 @@ class BitbucketClient(credentials: Credentials) {
163180
val json = Json.parse(input)
164181
val errorOpt = (json \ "error").asOpt[ResponseError]
165182

166-
errorOpt.map {
167-
error =>
183+
errorOpt
184+
.map { error =>
168185
Left(error)
169-
}.getOrElse(Right(json))
186+
}
187+
.getOrElse(Right(json))
170188
} match {
171189
case Success(jsValue) =>
172190
jsValue
@@ -207,10 +225,12 @@ class BitbucketClient(credentials: Credentials) {
207225
}
208226

209227
private def getFullStackTrace(throwableOpt: Throwable, accumulator: String = ""): String = {
210-
Option(throwableOpt).map { throwable =>
211-
val newAccumulator = s"$accumulator${Properties.lineSeparator}${throwable.getStackTrace.mkString("", EOL, EOL)}"
212-
getFullStackTrace(throwable.getCause, newAccumulator)
213-
}.getOrElse(accumulator)
228+
Option(throwableOpt)
229+
.map { throwable =>
230+
val newAccumulator = s"$accumulator${Properties.lineSeparator}${throwable.getStackTrace.mkString("", EOL, EOL)}"
231+
getFullStackTrace(throwable.getCause, newAccumulator)
232+
}
233+
.getOrElse(accumulator)
214234
}
215235

216236
}

src/main/scala/com/codacy/client/bitbucket/client/RequestResponse.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ object RequestResponse {
3131
r2 match {
3232
case SuccessfulResponse(v2) =>
3333
SuccessfulResponse(v1 ++ v2)
34-
case f@FailedResponse(_) => f
34+
case f @ FailedResponse(_) => f
3535
}
36-
case f@FailedResponse(_) => f
36+
case f @ FailedResponse(_) => f
3737
}
3838
}
3939

src/main/scala/com/codacy/client/bitbucket/util/CommitHelper.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codacy.client.bitbucket.util
22

33
object CommitHelper {
4+
45
def anchor(commitUUID: String): String = {
56
commitUUID.take(12)
67
}

src/main/scala/com/codacy/client/bitbucket/util/Implicits.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ object Implicits {
1212
implicit def enumWrites[E <: Enumeration#Value]: Writes[E] = Writes((e: E) => Json.toJson(e.toString))
1313

1414
implicit def enumReads[E <: Enumeration](e: E): Reads[e.Value] = {
15-
Reads.StringReads.map { value => e.values.find(_.toString == value) }
15+
Reads.StringReads
16+
.map { value =>
17+
e.values.find(_.toString == value)
18+
}
1619
.collect(ValidationError("Invalid enumeration value")) { case Some(v) => v }
1720
}
1821

1922
implicit class URIQueryParam(uri: URI) {
23+
2024
def addQuery(q: String): URI = {
2125
val newQuery = if (Option.apply(uri.getQuery).isEmpty) {
2226
q

src/main/scala/com/codacy/client/bitbucket/util/JsonEnumeration.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ trait JsonEnumeration extends Enumeration {
1111
values.find(p => p.toString.toLowerCase == name.toLowerCase)
1212
}
1313

14-
}
14+
}

src/main/scala/com/codacy/client/bitbucket/v1/CommitComment.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import java.time.LocalDateTime
55
import play.api.libs.functional.syntax._
66
import play.api.libs.json._
77

8-
case class CommitComment(id: Long, username: String, commit: String, display_name: String, content: String, created_on: LocalDateTime)
8+
case class CommitComment(
9+
id: Long,
10+
username: String,
11+
commit: String,
12+
display_name: String,
13+
content: String,
14+
created_on: LocalDateTime
15+
)
916

1017
object CommitComment {
1118
val dateFormat = "yyyy-MM-dd HH:mm:ssXXX"

src/main/scala/com/codacy/client/bitbucket/v1/Issue.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ import java.time.LocalDateTime
55
import play.api.libs.functional.syntax._
66
import play.api.libs.json._
77

8-
case class Issue(id: Long, status: String, priority: String, title: String, content: String, owner: String,
9-
created_on: LocalDateTime, kind: String)
8+
case class Issue(
9+
id: Long,
10+
status: String,
11+
priority: String,
12+
title: String,
13+
content: String,
14+
owner: String,
15+
created_on: LocalDateTime,
16+
kind: String
17+
)
1018

1119
object Issue {
1220
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"

0 commit comments

Comments
 (0)