Skip to content

Commit

Permalink
Merge pull request #2 from 47deg/rafa-add-sonatype-settings
Browse files Browse the repository at this point in the history
Add setting for publishing on Sonatype
  • Loading branch information
Rafa Paradela committed May 12, 2016
2 parents b75a6a2 + 6c365dd commit 1bab446
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 57 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ language: scala
scala:
- 2.11.8
jdk:
- oraclejdk8
- oraclejdk8
script:
- sbt -Dtoken=$GITHUB4S_ACCESS_TOKEN test
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ libraryDependencies ++= Seq(
"io.circe" %% "circe-parser" % "0.3.0",
"org.scalatest" %% "scalatest" % "2.2.6" % "test",
"com.ironcorelabs" %% "cats-scalatest" % "1.1.2" % "test"
)
)

licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt"))
4 changes: 3 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
logLevel := Level.Warn
logLevel := Level.Warn

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
54 changes: 54 additions & 0 deletions publish.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
organizationName := "47 Degrees"

organizationHomepage := Some(new URL("http://47deg.com"))

publishMavenStyle := true

startYear := Some(2016)

description := "GitHub API wrapper written in Scala"

homepage := Some(url("http://47deg.com"))

scmInfo := Some(ScmInfo(url("https://github.com/47deg/github4s"), "https://github.com/47deg/github4s.git"))

pomExtra :=
<developers>
<developer>
<name>47 Degrees (twitter: @47deg)</name>
<email>hello@47deg.com</email>
</developer>
<developer>
<name>47 Degrees</name>
</developer>
</developers>

publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

lazy val gpgFolder = sys.env.getOrElse("GPG_FOLDER", ".")

pgpPassphrase := Some(sys.env.getOrElse("GPG_PASSPHRASE", "").toCharArray)

pgpPublicRing := file(s"$gpgFolder/pubring.gpg")

pgpSecretRing := file(s"$gpgFolder/secring.gpg")

credentials += Credentials("Sonatype Nexus Repository Manager",
"oss.sonatype.org",
sys.env.getOrElse("PUBLISH_USERNAME", ""),
sys.env.getOrElse("PUBLISH_PASSWORD", ""))

publishArtifact in Test := false

lazy val publishSnapshot = taskKey[Unit]("Publish only if the version is a SNAPSHOT")

publishSnapshot := Def.taskDyn {
if (isSnapshot.value) Def.task { PgpKeys.publishSigned.value }
else Def.task(println("Actual version is not a Snapshot. Skipping publish."))
}.value
4 changes: 2 additions & 2 deletions src/main/scala/com/fortysevendeg/github4s/GithubAPIs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GHUsers(accessToken : Option[String] = None)(implicit O : UserOps[GitHub4s

class GHRepos(accessToken : Option[String] = None)(implicit O : RepositoryOps[GitHub4s]){

def get(owner : String, repo: String): GHIO[GHResponse[Repository]] = O.getRepo(owner, repo)
def get(owner : String, repo: String): GHIO[GHResponse[Repository]] = O.getRepo(owner, repo, accessToken)

def listCommits(
owner: String,
Expand All @@ -28,7 +28,7 @@ class GHRepos(accessToken : Option[String] = None)(implicit O : RepositoryOps[Gi
since: Option[String] = None,
until: Option[String] = None,
pagination: Option[Pagination] = None): GHIO[GHResponse[List[Commit]]] =
O.listCommits(owner, repo, sha, path, author, since, until, pagination)
O.listCommits(owner, repo, sha, path, author, since, until, pagination, accessToken)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ package com.fortysevendeg.github4s.free.domain

case class Repository(
id: Int,
//owner: Collaborator,
name: String)
36 changes: 0 additions & 36 deletions src/test/scala/GHReposSpec.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package com.fortysevendeg.github4s

trait TestUtils {

val accessToken = sys.props.get("token")

val validUsername = "rafaparadela"
val invalidUsername = "GHInvalidaUserName"
val invalidPassword = "invalidPassword"
Expand All @@ -16,5 +21,8 @@ trait TestUtils {
val validSinceInt = 100
val invalidSinceInt = -1

val statusCodeOK = 200
val okStatusCode = 200
val unauthorizedStatusCode = 401
val notFoundStatusCode = 404

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.fortysevendeg.github4s.integration

import cats.Id
import cats.scalatest.{XorMatchers, XorValues}
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.GithubResponses._
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
import com.fortysevendeg.github4s.Github
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.{Github, TestUtils}
import org.scalatest._
import cats.scalatest.{XorValues, XorMatchers}

class GHAuthSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {

Expand All @@ -17,7 +19,7 @@ class GHAuthSpec extends FlatSpec with Matchers with XorMatchers with XorValues
val response = Github().auth.authorizeUrl(validClientId, validRedirectUri, validScopes).exec[Id]
response shouldBe right
response.value.entity.url.contains(validRedirectUri) shouldBe true
response.value.statusCode shouldBe statusCodeOK
response.value.statusCode shouldBe okStatusCode
}

"Auth >> GetAccessToken" should "return error on Left for invalid code value" in {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.fortysevendeg.github4s.integration

import cats.Id
import cats.scalatest.{XorMatchers, XorValues}
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.GithubResponses._
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
import com.fortysevendeg.github4s.{Github, TestUtils}
import org.scalatest.{Matchers, FlatSpec}


class GHReposSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {

"Repos >> Get" should "return the expected name when valid repo is provided" in {

val response = Github(accessToken).repos.get(validRepoOwner, validRepoName).exec[Id]
response shouldBe right
response.value.entity.name shouldBe validRepoName
response.value.statusCode shouldBe okStatusCode
}

it should "return error when an invalid repo name is passed" in {
val response = Github(accessToken).repos.get(validRepoOwner, invalidRepoName).exec[Id]
response shouldBe left
}

"Repos >> ListCommits" should "return the expected list of commits for valid data" in {
val response = Github(accessToken).repos.listCommits(validRepoOwner, validRepoName).exec[Id]
response shouldBe right
response.value.entity.nonEmpty shouldBe true
response.value.statusCode shouldBe okStatusCode
}

it should "return error for invalid repo name" in {
val response = Github(accessToken).repos.listCommits(invalidRepoName, validRepoName).exec[Id]
response shouldBe left
}

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package com.fortysevendeg.github4s.integration

import cats.Id
import cats.scalatest.{XorMatchers, XorValues}
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.GithubResponses._
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
import com.fortysevendeg.github4s.Github
import com.fortysevendeg.github4s.Github._
import com.fortysevendeg.github4s.{Github, TestUtils}
import org.scalatest._
import cats.scalatest.{XorValues, XorMatchers}


class GHUsersSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {

"Users >> Get" should "return the expected login for a valid username" in {
val response = Github().users.get(validUsername).exec[Id]
val response = Github(accessToken).users.get(validUsername).exec[Id]
response shouldBe right
response.value.entity.login shouldBe validUsername
response.value.statusCode shouldBe statusCodeOK
response.value.statusCode shouldBe okStatusCode
}

it should "return error on Left for invalid username" in {
val response = Github().users.get(invalidUsername).exec[Id]
val response = Github(accessToken).users.get(invalidUsername).exec[Id]
response shouldBe left
}

Expand All @@ -27,17 +29,17 @@ class GHUsersSpec extends FlatSpec with Matchers with XorMatchers with XorValues
}

"Users >> GetUsers" should "return users for a valid since value" in {
val response = Github().users.getUsers(validSinceInt).exec[Id]
val response = Github(accessToken).users.getUsers(validSinceInt).exec[Id]
response shouldBe right
response.value.entity.nonEmpty shouldBe true
response.value.statusCode shouldBe statusCodeOK
response.value.statusCode shouldBe okStatusCode
}

it should "return error on Left when a invalid since value is provided" in {
val response = Github().users.getUsers(invalidSinceInt).exec[Id]
val response = Github(accessToken).users.getUsers(invalidSinceInt).exec[Id]
response shouldBe right
response.value.entity.nonEmpty shouldBe true
response.value.statusCode shouldBe statusCodeOK
response.value.statusCode shouldBe okStatusCode
}

}

0 comments on commit 1bab446

Please sign in to comment.