Skip to content

Commit 1bab446

Browse files
author
Rafa Paradela
committed
Merge pull request #2 from 47deg/rafa-add-sonatype-settings
Add setting for publishing on Sonatype
2 parents b75a6a2 + 6c365dd commit 1bab446

11 files changed

Lines changed: 131 additions & 57 deletions

File tree

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ language: scala
22
scala:
33
- 2.11.8
44
jdk:
5-
- oraclejdk8
5+
- oraclejdk8
6+
script:
7+
- sbt -Dtoken=$GITHUB4S_ACCESS_TOKEN test

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ libraryDependencies ++= Seq(
1515
"io.circe" %% "circe-parser" % "0.3.0",
1616
"org.scalatest" %% "scalatest" % "2.2.6" % "test",
1717
"com.ironcorelabs" %% "cats-scalatest" % "1.1.2" % "test"
18-
)
18+
)
19+
20+
licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt"))

project/plugins.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
logLevel := Level.Warn
1+
logLevel := Level.Warn
2+
3+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

publish.sbt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
organizationName := "47 Degrees"
2+
3+
organizationHomepage := Some(new URL("http://47deg.com"))
4+
5+
publishMavenStyle := true
6+
7+
startYear := Some(2016)
8+
9+
description := "GitHub API wrapper written in Scala"
10+
11+
homepage := Some(url("http://47deg.com"))
12+
13+
scmInfo := Some(ScmInfo(url("https://github.com/47deg/github4s"), "https://github.com/47deg/github4s.git"))
14+
15+
pomExtra :=
16+
<developers>
17+
<developer>
18+
<name>47 Degrees (twitter: @47deg)</name>
19+
<email>hello@47deg.com</email>
20+
</developer>
21+
<developer>
22+
<name>47 Degrees</name>
23+
</developer>
24+
</developers>
25+
26+
publishTo := {
27+
val nexus = "https://oss.sonatype.org/"
28+
if (isSnapshot.value)
29+
Some("snapshots" at nexus + "content/repositories/snapshots")
30+
else
31+
Some("releases" at nexus + "service/local/staging/deploy/maven2")
32+
}
33+
34+
lazy val gpgFolder = sys.env.getOrElse("GPG_FOLDER", ".")
35+
36+
pgpPassphrase := Some(sys.env.getOrElse("GPG_PASSPHRASE", "").toCharArray)
37+
38+
pgpPublicRing := file(s"$gpgFolder/pubring.gpg")
39+
40+
pgpSecretRing := file(s"$gpgFolder/secring.gpg")
41+
42+
credentials += Credentials("Sonatype Nexus Repository Manager",
43+
"oss.sonatype.org",
44+
sys.env.getOrElse("PUBLISH_USERNAME", ""),
45+
sys.env.getOrElse("PUBLISH_PASSWORD", ""))
46+
47+
publishArtifact in Test := false
48+
49+
lazy val publishSnapshot = taskKey[Unit]("Publish only if the version is a SNAPSHOT")
50+
51+
publishSnapshot := Def.taskDyn {
52+
if (isSnapshot.value) Def.task { PgpKeys.publishSigned.value }
53+
else Def.task(println("Actual version is not a Snapshot. Skipping publish."))
54+
}.value

src/main/scala/com/fortysevendeg/github4s/GithubAPIs.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GHUsers(accessToken : Option[String] = None)(implicit O : UserOps[GitHub4s
1717

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

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

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

3333
}
3434

src/main/scala/com/fortysevendeg/github4s/free/domain/Repository.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ package com.fortysevendeg.github4s.free.domain
22

33
case class Repository(
44
id: Int,
5-
//owner: Collaborator,
65
name: String)

src/test/scala/GHReposSpec.scala

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/test/scala/testUtils.scala renamed to src/test/scala/com.fortysevendeg.github4s/TestUtils.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
package com.fortysevendeg.github4s
2+
13
trait TestUtils {
4+
5+
val accessToken = sys.props.get("token")
6+
27
val validUsername = "rafaparadela"
38
val invalidUsername = "GHInvalidaUserName"
49
val invalidPassword = "invalidPassword"
@@ -16,5 +21,8 @@ trait TestUtils {
1621
val validSinceInt = 100
1722
val invalidSinceInt = -1
1823

19-
val statusCodeOK = 200
24+
val okStatusCode = 200
25+
val unauthorizedStatusCode = 401
26+
val notFoundStatusCode = 404
27+
2028
}

src/test/scala/GHAuthSpec.scala renamed to src/test/scala/com.fortysevendeg.github4s/integration/GHAuthSpec.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
package com.fortysevendeg.github4s.integration
2+
13
import cats.Id
4+
import cats.scalatest.{XorMatchers, XorValues}
5+
import com.fortysevendeg.github4s.Github._
26
import com.fortysevendeg.github4s.GithubResponses._
37
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
4-
import com.fortysevendeg.github4s.Github
5-
import com.fortysevendeg.github4s.Github._
8+
import com.fortysevendeg.github4s.{Github, TestUtils}
69
import org.scalatest._
7-
import cats.scalatest.{XorValues, XorMatchers}
810

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

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

2325
"Auth >> GetAccessToken" should "return error on Left for invalid code value" in {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fortysevendeg.github4s.integration
2+
3+
import cats.Id
4+
import cats.scalatest.{XorMatchers, XorValues}
5+
import com.fortysevendeg.github4s.Github._
6+
import com.fortysevendeg.github4s.GithubResponses._
7+
import com.fortysevendeg.github4s.free.interpreters.IdInterpreters._
8+
import com.fortysevendeg.github4s.{Github, TestUtils}
9+
import org.scalatest.{Matchers, FlatSpec}
10+
11+
12+
class GHReposSpec extends FlatSpec with Matchers with XorMatchers with XorValues with TestUtils {
13+
14+
"Repos >> Get" should "return the expected name when valid repo is provided" in {
15+
16+
val response = Github(accessToken).repos.get(validRepoOwner, validRepoName).exec[Id]
17+
response shouldBe right
18+
response.value.entity.name shouldBe validRepoName
19+
response.value.statusCode shouldBe okStatusCode
20+
}
21+
22+
it should "return error when an invalid repo name is passed" in {
23+
val response = Github(accessToken).repos.get(validRepoOwner, invalidRepoName).exec[Id]
24+
response shouldBe left
25+
}
26+
27+
"Repos >> ListCommits" should "return the expected list of commits for valid data" in {
28+
val response = Github(accessToken).repos.listCommits(validRepoOwner, validRepoName).exec[Id]
29+
response shouldBe right
30+
response.value.entity.nonEmpty shouldBe true
31+
response.value.statusCode shouldBe okStatusCode
32+
}
33+
34+
it should "return error for invalid repo name" in {
35+
val response = Github(accessToken).repos.listCommits(invalidRepoName, validRepoName).exec[Id]
36+
response shouldBe left
37+
}
38+
39+
}

0 commit comments

Comments
 (0)