Skip to content

[PT-1048] - Fetch workspace projects #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
version: 2.1

orbs:
codacy: codacy/[email protected]
codacy: codacy/[email protected]

references:
cache_prefix: &cache_prefix sbt-cache-20240918

workflows:
version: 2
build:
jobs:
- codacy/checkout_and_version:
write_sbt_version: true
- codacy/sbt_docker:
- codacy/sbt:
name: test
context: ExternalSystems
cache_prefix: *cache_prefix
save_cache: true
aws_profile: maven
use_sbt_native_client: true
persist_to_workspace: true
steps:
- run:
Expand All @@ -22,9 +30,6 @@ workflows:
- run:
name: Check scalafmt on sbt files
command: sbt scalafmtSbtCheck
- run:
name: Check scalafmt on sbt files
command: sbt scalafmtSbtCheck
- run:
name: Run tests
command: sbt crossTest
Expand All @@ -45,7 +50,7 @@ workflows:
branches:
only:
- master
- codacy/sbt_docker:
- codacy/sbt:
name: publish_sonatype
context: CodacyAWS
use_sbt_native_client: false
Expand All @@ -64,7 +69,7 @@ workflows:
command: sbt sonatypeBundleRelease
requires:
- tag_version
- codacy/sbt_docker:
- codacy/sbt:
name: publish_s3
aws_profile: maven
context: CodacyAWS
Expand Down
13 changes: 13 additions & 0 deletions src/main/scala/com/codacy/client/bitbucket/v2/Project.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codacy.client.bitbucket.v2

import play.api.libs.functional.syntax._
import play.api.libs.json._

case class Project(name: String, key: String)

object Project {
implicit val reads: Reads[Project] = (
(__ \ "name").read[String] and
(__ \ "key").read[String]
)(Project.apply _)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.codacy.client.bitbucket.v2.service
import java.net.URLEncoder
import com.codacy.client.bitbucket.util.UrlHelper._
import com.codacy.client.bitbucket.client.{BitbucketClient, PageRequest, RequestResponse}
import com.codacy.client.bitbucket.v2.{UserIdentifiers, UserIdentifiersApi, Workspace, WorkspacePermission}
import com.codacy.client.bitbucket.v2.{Project, UserIdentifiers, UserIdentifiersApi, Workspace, WorkspacePermission}

class WorkspaceServices(client: BitbucketClient) {

Expand Down Expand Up @@ -102,4 +102,22 @@ class WorkspaceServices(client: BitbucketClient) {
val requestResponse = client.executePaginated[WorkspacePermission](baseRequestUrl)
requestResponse.map(_.headOption)
}

def getWorkspaceProjects(
workspace: String,
pageRequest: Option[PageRequest] = None,
pageLength: Option[Int] = None
): RequestResponse[Seq[Project]] = {
val url = s"${client.workspacesBaseUrl}/$workspace/projects"

pageRequest match {
case Some(request) =>
client.executeWithCursor[Project](url, request, pageLength)
case None =>
val length = pageLength.fold("")(pagelen => s"pagelen=$pagelen")
val urlWithPageLength = joinQueryParameters(url, length)
client.executePaginated[Project](urlWithPageLength)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.codacy.client.bitbucket.v2

import org.scalatest.{FlatSpec, Matchers}
import play.api.libs.json.Json

class WorkspaceSpecs extends FlatSpec with Matchers {

"WorkspaceSpecs" should "successfully parse Projects" in {
val input =
"""
| {
| "type":"<string>",
| "links":{
| "html":{
| "href":"<string>",
| "name":"<string>"
| },
| "avatar":{
| "href":"<string>",
| "name":"<string>"
| }
| },
| "uuid":"<string>",
| "key":"some key",
| "owner":{
| "type":"<string>"
| },
| "name":"Pluto",
| "description":"<string>",
| "is_private":true,
| "created_on":"<string>",
| "updated_on":"<string>",
| "has_publicly_visible_repos":true
| }
|

""".stripMargin

val json = Json.parse(input)
val value = json.validate[Project]

value.fold(e => fail(s"$e"), p => {
p.name shouldBe "Pluto"
p.key shouldBe "some key"
})
}

}