From 834be62e9fa8df27117abe75512870671f949d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Herna=CC=81ndez?= Date: Mon, 10 Jul 2023 08:52:41 +0200 Subject: [PATCH] Fix collaborators & release URLs decoding --- .../sbt/github/github/Repository.scala | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/sbt-github/src/main/scala/com/alejandrohdezma/sbt/github/github/Repository.scala b/modules/sbt-github/src/main/scala/com/alejandrohdezma/sbt/github/github/Repository.scala index b3bd7d31..68dbec70 100644 --- a/modules/sbt-github/src/main/scala/com/alejandrohdezma/sbt/github/github/Repository.scala +++ b/modules/sbt-github/src/main/scala/com/alejandrohdezma/sbt/github/github/Repository.scala @@ -30,6 +30,8 @@ import com.alejandrohdezma.sbt.github.github.urls.RepositoryEntryPoint import com.alejandrohdezma.sbt.github.http.Authentication import com.alejandrohdezma.sbt.github.http.client import com.alejandrohdezma.sbt.github.json.Decoder +import com.alejandrohdezma.sbt.github.json.Json +import com.alejandrohdezma.sbt.github.json.error.NotAUrl import com.alejandrohdezma.sbt.github.syntax.json._ import com.alejandrohdezma.sbt.github.syntax.list._ import com.alejandrohdezma.sbt.github.syntax.scalatry._ @@ -162,17 +164,19 @@ object Repository { implicit val RepositoryDecoder: Decoder[Repository] = json => for { - name <- json.get[String]("full_name") - description <- json.get[String]("description") - license <- json.get[License]("license") - url <- json.get[URL]("html_url") - startYear <- json.get[ZonedDateTime]("created_at") - defaultBranch <- json.get[String]("default_branch") - contributors <- json.get[URL]("contributors_url") - collaborators <- json.get[URL]("collaborators_url") - organizationUrl <- json.get[Option[URL]]("organization", "url") - releases <- json.get[URL]("releases_url") - ownerUrl <- json.get[URL]("owner", "url") + name <- json.get[String]("full_name") + description <- json.get[String]("description") + license <- json.get[License]("license") + url <- json.get[URL]("html_url") + startYear <- json.get[ZonedDateTime]("created_at") + defaultBranch <- json.get[String]("default_branch") + contributors <- json.get[URL]("contributors_url") + collaborators <- json.get[String]("collaborators_url").map(_.replace("{/collaborator}", "")) + collaboratorsUrl <- Try(sbt.url(collaborators)).failAs(NotAUrl(Json.Text(collaborators))) + organizationUrl <- json.get[Option[URL]]("organization", "url") + releases <- json.get[String]("releases_url").map(_.replace("{/id}", "")) + releasesUrl <- Try(sbt.url(releases)).failAs(NotAUrl(Json.Text(releases))) + ownerUrl <- json.get[URL]("owner", "url") } yield Repository( name, description, @@ -181,8 +185,8 @@ object Repository { startYear.getYear, defaultBranch, contributors, - sbt.url(s"$collaborators".replace("{/collaborator}", "")), - sbt.url(s"$releases".replace("{/id}", "")), + collaboratorsUrl, + releasesUrl, organizationUrl, ownerUrl )