Skip to content

Commit 0a3b520

Browse files
committed
initial client
0 parents  commit 0a3b520

22 files changed

+516
-0
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
logs
2+
project/project
3+
project/target
4+
target
5+
tmp
6+
.history
7+
dist
8+
/.idea
9+
/*.iml
10+
.cache
11+
/out
12+
/.idea_modules
13+
.classpath
14+
.project
15+
/RUNNING_PID
16+
/.settings
17+
.DS_Store
18+
*.iml
19+
codacy.pylint.conf
20+
npm-debug.log
21+
config

build.sbt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Dependencies._
2+
3+
name := """bitbucket-scala-client"""
4+
5+
version := "1.0"
6+
7+
scalaVersion := "2.11.1"
8+
9+
resolvers += "Typesafe maven repository" at "http://repo.typesafe.com/typesafe/maven-releases/"
10+
11+
libraryDependencies ++= Seq(
12+
jodaTime,
13+
playWS
14+
)

project/Dependencies.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sbt._
2+
3+
object Dependencies {
4+
5+
// Generic
6+
lazy val jodaTime = "joda-time" % "joda-time" % "2.3"
7+
8+
// Play framework
9+
lazy val playWS = "com.typesafe.play" %% "play-ws" % "2.3.1"
10+
11+
}

project/build.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Activator-generated Properties
2+
#Sat Jul 12 15:51:18 WEST 2014
3+
template.uuid=a855816c-0367-44ba-9adb-6a903f6ad599
4+
sbt.version=0.13.5
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.codacy.client.bitbucket
2+
3+
import org.joda.time.DateTime
4+
import play.api.libs.functional.syntax._
5+
import play.api.libs.json._
6+
7+
case class CommitComment(id: Long, username: String, commit: String, display_name: String, content: String, created_on: DateTime)
8+
9+
object CommitComment {
10+
val dateFormat = "yyyy-MM-dd HH:mm:ssZZ"
11+
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
12+
13+
implicit val reader: Reads[CommitComment] = (
14+
(__ \ "comment_id").read[Long] and
15+
(__ \ "username").read[String] and
16+
(__ \ "node").read[String] and
17+
(__ \ "display_name").read[String] and
18+
(__ \ "content").read[String] and
19+
(__ \ "utc_created_on").read[DateTime]
20+
)(CommitComment.apply _)
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.codacy.client.bitbucket
2+
3+
import org.joda.time.DateTime
4+
import play.api.libs.functional.syntax._
5+
import play.api.libs.json._
6+
7+
case class Issue(id: Long, status: String, priority: String, title: String, content: String, owner: String,
8+
created_on: DateTime, kind: String)
9+
10+
object Issue {
11+
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
12+
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
13+
14+
implicit val reader: Reads[Issue] = (
15+
(__ \ "local_id").read[Long] and
16+
(__ \ "status").read[String] and
17+
(__ \ "priority").read[String] and
18+
(__ \ "title").read[String] and
19+
(__ \ "content").read[String] and
20+
(__ \ "reported_by" \ "username").read[String] and
21+
(__ \ "created_on").read[DateTime] and
22+
(__ \ "metadata" \ "kind").read[String]
23+
)(Issue.apply _)
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.codacy.client.bitbucket
2+
3+
import org.joda.time.DateTime
4+
import play.api.libs.functional.syntax._
5+
import play.api.libs.json._
6+
7+
case class PullRequest(id: Long, title: String, description: String, author: String,
8+
state: String, created_on: DateTime, updated_on: DateTime,
9+
destBranch: String, destCommit: String)
10+
11+
object PullRequest {
12+
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ"
13+
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
14+
15+
implicit val reader: Reads[PullRequest] = (
16+
(__ \ "id").read[Long] and
17+
(__ \ "title").read[String] and
18+
(__ \ "description").read[String] and
19+
(__ \ "author" \ "username").read[String] and
20+
(__ \ "state").read[String] and
21+
(__ \ "created_on").read[DateTime] and
22+
(__ \ "updated_on").read[DateTime] and
23+
(__ \ "destination" \ "branch" \ "name").read[String] and
24+
(__ \ "destination" \ "commit" \ "hash").read[String]
25+
)(PullRequest.apply _)
26+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.codacy.client.bitbucket
2+
3+
import org.joda.time.DateTime
4+
import play.api.libs.functional.syntax._
5+
import play.api.libs.json._
6+
7+
case class Repository(name: String, full_name: String, description: String,
8+
scm: String, created_on: DateTime, updated_on: DateTime,
9+
httpsUrl: String, sshUrl: String, owner: String, size: Long,
10+
has_issues: Boolean, is_private: Boolean, language: String)
11+
12+
object Repository {
13+
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ"
14+
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
15+
16+
implicit val reader: Reads[Repository] = {
17+
val url1 = (__ \ "links" \ "clone")(0).read[Url]
18+
val url2 = (__ \ "links" \ "clone")(1).read[Url]
19+
20+
val httpUrl = url1.filter(_.name == "https").orElse(url2).map(_.href)
21+
val sshUrl = url2.filter(_.name == "ssh").orElse(url1).map(_.href)
22+
23+
((__ \ "name").read[String] and
24+
(__ \ "full_name").read[String] and
25+
(__ \ "description").read[String] and
26+
(__ \ "scm").read[String] and
27+
(__ \ "created_on").read[DateTime] and
28+
(__ \ "updated_on").read[DateTime] and
29+
httpUrl and
30+
sshUrl and
31+
(__ \ "owner" \ "username").read[String] and
32+
(__ \ "size").read[Long] and
33+
(__ \ "has_issues").read[Boolean] and
34+
(__ \ "is_private").read[Boolean] and
35+
(__ \ "language").read[String]
36+
)(Repository.apply _)
37+
}
38+
}
39+
40+
case class Url(name: String, href: String)
41+
42+
object Url {
43+
implicit val reader: Reads[Url] = (
44+
(__ \ "name").read[String] and
45+
(__ \ "href").read[String]
46+
)(Url.apply _)
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.codacy.client.bitbucket
2+
3+
import org.joda.time.DateTime
4+
import play.api.libs.functional.syntax._
5+
import play.api.libs.json._
6+
7+
case class SimpleRepository(name: String, description: String, scm: String, created_on: DateTime, updated_on: DateTime,
8+
owner: String, size: Long, has_issues: Boolean, is_private: Boolean, language: String) {
9+
10+
val full_name: String = s"$owner/$name"
11+
val sshUrl: String = s"ssh://$scm@bitbucket.org/$owner/$name"
12+
val httpsUrl: String = s"https://$owner@bitbucket.org/$owner/$name"
13+
}
14+
15+
object SimpleRepository {
16+
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
17+
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
18+
19+
implicit val reader: Reads[SimpleRepository] =
20+
((__ \ "slug").read[String] and
21+
(__ \ "description").read[String] and
22+
(__ \ "scm").read[String] and
23+
(__ \ "created_on").read[DateTime] and
24+
(__ \ "last_updated").read[DateTime] and
25+
(__ \ "owner").read[String] and
26+
(__ \ "size").read[Long] and
27+
(__ \ "has_issues").read[Boolean] and
28+
(__ \ "is_private").read[Boolean] and
29+
(__ \ "language").read[String]
30+
)(SimpleRepository.apply _)
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.codacy.client.bitbucket
2+
3+
import play.api.libs.functional.syntax._
4+
import play.api.libs.json._
5+
6+
case class SshKey(pk: Long, key: String, label: String)
7+
8+
object SshKey {
9+
implicit val reader: Reads[SshKey] = (
10+
(__ \ "pk").read[Long] and
11+
(__ \ "key").read[String] and
12+
(__ \ "label").read[String]
13+
)(SshKey.apply _)
14+
}

0 commit comments

Comments
 (0)