Skip to content

Commit fc38a67

Browse files
Merge pull request #128 from codacy/PT-1048_fetch_workspace_projects
[PT-1048] - Fetch workspace projects
2 parents 32ebf8f + 7c5c819 commit fc38a67

File tree

4 files changed

+92
-8
lines changed

4 files changed

+92
-8
lines changed

.circleci/config.yml

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

33
orbs:
4-
codacy: codacy/base@10.9.0
4+
codacy: codacy/base@11.2.0
5+
6+
references:
7+
cache_prefix: &cache_prefix sbt-cache-20240918
58

69
workflows:
710
version: 2
811
build:
912
jobs:
1013
- codacy/checkout_and_version:
1114
write_sbt_version: true
12-
- codacy/sbt_docker:
15+
- codacy/sbt:
1316
name: test
17+
context: ExternalSystems
18+
cache_prefix: *cache_prefix
19+
save_cache: true
20+
aws_profile: maven
21+
use_sbt_native_client: true
1422
persist_to_workspace: true
1523
steps:
1624
- run:
@@ -22,9 +30,6 @@ workflows:
2230
- run:
2331
name: Check scalafmt on sbt files
2432
command: sbt scalafmtSbtCheck
25-
- run:
26-
name: Check scalafmt on sbt files
27-
command: sbt scalafmtSbtCheck
2833
- run:
2934
name: Run tests
3035
command: sbt crossTest
@@ -45,7 +50,7 @@ workflows:
4550
branches:
4651
only:
4752
- master
48-
- codacy/sbt_docker:
53+
- codacy/sbt:
4954
name: publish_sonatype
5055
context: CodacyAWS
5156
use_sbt_native_client: false
@@ -64,7 +69,7 @@ workflows:
6469
command: sbt sonatypeBundleRelease
6570
requires:
6671
- tag_version
67-
- codacy/sbt_docker:
72+
- codacy/sbt:
6873
name: publish_s3
6974
aws_profile: maven
7075
context: CodacyAWS
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)