Skip to content

Commit

Permalink
wip gitlab: get organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan José Vázquez committed Dec 11, 2017
1 parent 270ec59 commit 1fd71a9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ object ScmConfig {
s"$api/user"

val userOrgsEndpoint: String =
s"$userEndpoint/orgs"
s"$api/groups"

def orgEndpoint(login: String): String =
s"$api/orgs/$login"
s"$api/groups/$login"

def repoEndpoint(page: Int = 1): String =
s"$api/user/repos?affiliation=owner,organization_member&visibility=all&direction=asc&page=$page"
Expand Down
41 changes: 35 additions & 6 deletions core/src/main/scala/Gitlab.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package nelson

import argonaut.Argonaut.{ casecodec1, casecodec4 }
import argonaut.Argonaut.{casecodec1, casecodec2, casecodec4}
import argonaut.{CodecJson, DecodeJson, EncodeJson}
import nelson.Github._
import org.http4s
import org.http4s._
import org.http4s.argonaut._
import org.http4s.client.Client
import org.http4s.headers.Authorization
import scalaz._, Scalaz._
import scalaz.concurrent.Task
import scalaz.~>
import java.net.{ MalformedURLException, URI }
import java.net.{MalformedURLException, URI}

object Gitlab {

Expand All @@ -31,11 +31,25 @@ object Gitlab {
case GetUser(token: AccessToken) =>
fetch[Github.User](cfg.userEndpoint) { uri =>
http4s.Request(
headers = Headers(Authorization(OAuth2BearerToken(token.value))),
headers = Headers(Header("PRIVATE-TOKEN", token.value)),
// headers = Headers(Authorization(OAuth2BearerToken(token.value))),
uri = uri)
}
case GetUserOrgKeys(token: AccessToken) => ???
case GetOrganizations(keys: List[Github.OrgKey], t: AccessToken) => ???
case GetUserOrgKeys(token: AccessToken) =>
fetch[List[Github.OrgKey]](cfg.userOrgsEndpoint) { uri =>
http4s.Request(
headers = Headers(Header("PRIVATE-TOKEN", token.value)),
uri = uri)
}
case GetOrganizations(keys: List[Github.OrgKey], t: AccessToken) =>
Nondeterminism[Task].gatherUnordered(
keys.map(key => fetch[Organization](cfg.orgEndpoint(key.slug)) { uri =>
http4s.Request(
headers = Headers(Header("PRIVATE-TOKEN", t.value)),
uri = uri)
})
)
//fetch[List[Organization]](cfg.orgEndpoint())
case GetReleaseAssetContent(asset: Github.Asset, t: AccessToken) => ???
case GetRelease(slug: Slug, releaseId: ID, t: AccessToken) => ???
case GetUserRepositories(t: AccessToken) => ???
Expand All @@ -55,6 +69,21 @@ object Gitlab {
casecodec4(Github.User.apply, Github.User.unapply
)("username", "avatar_url", "name", "email")

implicit lazy val GithubOrg: CodecJson[Github.OrgKey] =
casecodec2(Github.OrgKey.apply, Github.OrgKey.unapply)("id", "full_path")

// implicit lazy val OrganizationCodec: CodecJson[Organization] =
// casecodec4(Organization.apply, Organization.unapply)("id", "name", "full_path", "avatar_url")

implicit lazy val OrganizationDecoder: DecodeJson[Organization] =
DecodeJson(c =>
((c --\ "id").as[Long] |@|
(c --\ "name").as[Option[String]] |@|
(c --\ "full_path").as[String]
//(c --\ "avatar_url").as[URI]
) { case (id, name, login) => Organization(id, name, login, new URI("https://localhost:8080")) } // TODO
)

implicit lazy val AccessTokenCodec: CodecJson[AccessToken] =
casecodec1(AccessToken.apply, AccessToken.unapply)("access_token")

Expand Down

0 comments on commit 1fd71a9

Please sign in to comment.