Skip to content

Commit 6ae3dbe

Browse files
committed
pull request commits can commit the author username
1 parent 71eb7e7 commit 6ae3dbe

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import Dependencies._
22

33
name := """bitbucket-scala-client"""
44

5-
version := "1.3"
5+
version := "1.3.1"
66

77
scalaVersion := "2.10.5"
88

9-
crossScalaVersions := Seq("2.10.5", "2.11.6")
9+
crossScalaVersions := Seq("2.10.5", "2.11.7")
1010

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

project/Dependencies.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ object Dependencies {
66
lazy val jodaTime = "joda-time" % "joda-time" % "2.7"
77

88
// Play framework
9-
lazy val playWS = "com.typesafe.play" %% "play-ws" % "2.4.0"
9+
lazy val playWS = "com.typesafe.play" %% "play-ws" % "2.4.2"
1010

1111
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.codacy.client.bitbucket
2+
3+
import org.joda.time.DateTime
4+
import play.api.libs.json._
5+
6+
case class SimpleCommit(hash: String, authorName: Option[String], parents: Seq[String], date: DateTime, message: String)
7+
8+
object SimpleCommit {
9+
val dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZ"
10+
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
11+
12+
implicit def commitReader: Reads[SimpleCommit] = Reads { (json: JsValue) =>
13+
(for {
14+
hash <- (json \ "hash").asOpt[String]
15+
username = (json \ "author" \ "user" \ "username").asOpt[String]
16+
parents = (json \ "parents" \\ "hash").flatMap(_.asOpt[String])
17+
date <- (json \ "date").asOpt[DateTime]
18+
message <- (json \ "message").asOpt[String]
19+
} yield SimpleCommit(hash, username, parents, date, message))
20+
.map(JsSuccess(_))
21+
.getOrElse(JsError("could not read commit"))
22+
}
23+
}

src/main/scala/com/codacy/client/bitbucket/service/PullRequestServices.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.codacy.client.bitbucket.service
22

33
import com.codacy.client.bitbucket.client.{BitbucketClient, Request, RequestResponse}
4-
import com.codacy.client.bitbucket.{Commit, PullRequest}
4+
import com.codacy.client.bitbucket.{PullRequest, SimpleCommit}
55
import play.api.libs.json.{JsNull, JsObject, Json}
66

77
class PullRequestServices(client: BitbucketClient) {
@@ -22,10 +22,10 @@ class PullRequestServices(client: BitbucketClient) {
2222
* Gets the list of commits of a pull request
2323
*
2424
*/
25-
def getPullRequestCommits(owner: String, repository: String, prId: Long): RequestResponse[Seq[Commit]] = {
25+
def getPullRequestCommits(owner: String, repository: String, prId: Long): RequestResponse[Seq[SimpleCommit]] = {
2626
val url = s"https://bitbucket.org/!api/2.0/repositories/$owner/$repository/pullrequests/$prId/commits"
2727

28-
client.executePaginated(Request(url, classOf[Seq[Commit]]))
28+
client.executePaginated(Request(url, classOf[Seq[SimpleCommit]]))
2929
}
3030

3131
def create(owner: String, repository: String, title: String, sourceBranch: String, destinationBranch: String): RequestResponse[JsObject] = {

0 commit comments

Comments
 (0)