Skip to content

Commit 42e4d36

Browse files
committed
[PT-1048] - Fetch workspace projects
1 parent 32ebf8f commit 42e4d36

File tree

6 files changed

+86
-7
lines changed

6 files changed

+86
-7
lines changed

.circleci/config.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2.1
22

33
orbs:
4-
codacy: codacy/base@10.9.0
4+
codacy: codacy/base@12.0.0
55

66
workflows:
77
version: 2
@@ -22,12 +22,9 @@ workflows:
2222
- run:
2323
name: Check scalafmt on sbt files
2424
command: sbt scalafmtSbtCheck
25-
- run:
26-
name: Check scalafmt on sbt files
27-
command: sbt scalafmtSbtCheck
2825
- run:
2926
name: Run tests
30-
command: sbt crossTest
27+
command: sbt test
3128
- run:
3229
name: Generate coverage report
3330
command: sbt coverageReport

build.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pgpPassphrase := Option(System.getenv("SONATYPE_GPG_PASSPHRASE"))
5555

5656
name := s"${name.value}_playjson${playJsonVersion.value.split('.').take(2).mkString}"
5757

58+
coverageEnabled := true
59+
coverageOutputXML := true
60+
5861
/**
5962
* Given a command it creates an alias to run the command
6063
* on the entire matrix of play and scala versions.

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.2.0")
22

33
addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "25.0.0")
44

5-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
5+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
66

77
ThisBuild / libraryDependencySchemes +=
88
"org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.codacy.client.bitbucket.v2
2+
3+
import play.api.libs.functional.syntax._
4+
import play.api.libs.json._
5+
6+
case class Project(name: String, key: String)
7+
8+
object Project {
9+
implicit val reads: Reads[Project] = (
10+
(__ \ "name").read[String] and
11+
(__ \ "key").read[String]
12+
)(Project.apply _)
13+
}

src/main/scala/com/codacy/client/bitbucket/v2/service/WorkspaceServices.scala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.codacy.client.bitbucket.v2.service
33
import java.net.URLEncoder
44
import com.codacy.client.bitbucket.util.UrlHelper._
55
import com.codacy.client.bitbucket.client.{BitbucketClient, PageRequest, RequestResponse}
6-
import com.codacy.client.bitbucket.v2.{UserIdentifiers, UserIdentifiersApi, Workspace, WorkspacePermission}
6+
import com.codacy.client.bitbucket.v2.{Project, UserIdentifiers, UserIdentifiersApi, Workspace, WorkspacePermission}
77

88
class WorkspaceServices(client: BitbucketClient) {
99

@@ -102,4 +102,22 @@ class WorkspaceServices(client: BitbucketClient) {
102102
val requestResponse = client.executePaginated[WorkspacePermission](baseRequestUrl)
103103
requestResponse.map(_.headOption)
104104
}
105+
106+
def getWorkspaceProjects(
107+
workspace: String,
108+
pageRequest: Option[PageRequest] = None,
109+
pageLength: Option[Int] = None
110+
): RequestResponse[Seq[Project]] = {
111+
val url = s"${client.workspacesBaseUrl}/$workspace/projects"
112+
113+
pageRequest match {
114+
case Some(request) =>
115+
client.executeWithCursor[Project](url, request, pageLength)
116+
case None =>
117+
val length = pageLength.fold("")(pagelen => s"pagelen=$pagelen")
118+
val urlWithPageLength = joinQueryParameters(url, length)
119+
client.executePaginated[Project](urlWithPageLength)
120+
}
121+
}
122+
105123
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.codacy.client.bitbucket.v2
2+
3+
import org.scalatest.{FlatSpec, Matchers}
4+
import play.api.libs.json.Json
5+
6+
class WorkspaceSpecs extends FlatSpec with Matchers {
7+
8+
"WorkspaceSpecs" should "successfully parse Projects" in {
9+
val input =
10+
"""
11+
| {
12+
| "type":"<string>",
13+
| "links":{
14+
| "html":{
15+
| "href":"<string>",
16+
| "name":"<string>"
17+
| },
18+
| "avatar":{
19+
| "href":"<string>",
20+
| "name":"<string>"
21+
| }
22+
| },
23+
| "uuid":"<string>",
24+
| "key":"some key",
25+
| "owner":{
26+
| "type":"<string>"
27+
| },
28+
| "name":"Pluto",
29+
| "description":"<string>",
30+
| "is_private":true,
31+
| "created_on":"<string>",
32+
| "updated_on":"<string>",
33+
| "has_publicly_visible_repos":true
34+
| }
35+
|
36+
37+
""".stripMargin
38+
39+
val json = Json.parse(input)
40+
val value = json.validate[Project]
41+
42+
value.fold(e => fail(s"$e"), p => {
43+
p.name shouldBe "Pluto"
44+
p.key shouldBe "some key"
45+
})
46+
}
47+
48+
}

0 commit comments

Comments
 (0)