Skip to content
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

Adds some git methods #67

Merged
merged 3 commits into from
Mar 28, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ lazy val root = (project in file("."))
.dependsOn(github4sJVM, github4sJS, scalaz, docs)
.aggregate(github4sJVM, github4sJS, scalaz, docs)
.settings(noPublishSettings: _*)
.settings(Seq(coverageFailOnMinimum := false))

lazy val github4s = (crossProject in file("github4s"))
.settings(moduleName := "github4s")
Expand All @@ -26,6 +27,7 @@ lazy val github4s = (crossProject in file("github4s"))

lazy val github4sJVM = github4s.jvm
lazy val github4sJS = github4s.js
.settings(Seq(coverageFailOnMinimum := false))

lazy val docs = (project in file("docs"))
.dependsOn(scalaz)
Expand All @@ -38,5 +40,6 @@ lazy val docs = (project in file("docs"))
lazy val scalaz = (project in file("scalaz"))
.settings(moduleName := "github4s-scalaz")
.settings(scalazDependencies: _*)
.settings(Seq(coverageFailOnMinimum := false))
.dependsOn(github4sJVM)
.enablePlugins(AutomateHeaderPlugin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package github4s.utils.integration

import cats.data.NonEmptyList
import github4s.Github
import github4s.Github._
import github4s.free.domain.{Ref, RefCommit}
import github4s.js.Implicits._
import github4s.utils.TestUtils
import org.scalatest._

class GHGitDataSpec extends AsyncFlatSpec with Matchers with TestUtils {

override implicit val executionContext =
scala.concurrent.ExecutionContext.Implicits.global

"GitData >> GetReference" should "return a list of references" in {
val response = Github(accessToken).gitData
.getReference(validRepoOwner, validRepoName, "heads")
.execFuture(headerUserAgent)

testFutureIsRight[NonEmptyList[Ref]](response, { r =>
r.result.tail.nonEmpty shouldBe true
r.statusCode shouldBe okStatusCode
})
}

it should "return at least one reference" in {
val response = Github(accessToken).gitData
.getReference(validRepoOwner, validRepoName, validRefSingle)
.execFuture(headerUserAgent)

testFutureIsRight[NonEmptyList[Ref]](response, { r =>
r.result.head.ref.contains(validRefSingle) shouldBe true
r.statusCode shouldBe okStatusCode
})
}

"GitData >> GetCommit" should "return one commit" in {
val response = Github(accessToken).gitData
.getCommit(validRepoOwner, validRepoName, validCommitSha)
.execFuture(headerUserAgent)

testFutureIsRight[RefCommit](response, { r =>
r.result.message shouldBe validCommitMsg
r.statusCode shouldBe okStatusCode
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ trait TestUtils extends Matchers {
val validIssueState = "closed"
val validIssueLabel = List("bug", "code review")
val validAssignees = List(validUsername)

val validRefSingle = "heads/master"

val validCommitSha = "d3b048c1f500ee5450e5d7b3d1921ed3e7645891"
val validCommitMsg = "Add SBT project settings"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package github4s.integration

import cats.Id
import cats.implicits._
import github4s.Github
import github4s.Github._
import github4s.jvm.Implicits._
import github4s.utils.TestUtils
import org.scalatest._

import scalaj.http.HttpResponse

class GHGitDataSpec extends FlatSpec with Matchers with TestUtils {

"GitData >> GetReference" should "return a list of references" in {
val response = Github(accessToken).gitData
.getReference(validRepoOwner, validRepoName, "heads")
.exec[Id, HttpResponse[String]](headerUserAgent)

response should be('right)
response.toOption map { r ⇒
r.result.tail.nonEmpty shouldBe true
r.statusCode shouldBe okStatusCode
}
}

it should "return at least one reference" in {
val response = Github(accessToken).gitData
.getReference(validRepoOwner, validRepoName, validRefSingle)
.exec[Id, HttpResponse[String]](headerUserAgent)

response should be('right)
response.toOption map { r ⇒
r.result.head.ref.contains(validRefSingle) shouldBe true
r.statusCode shouldBe okStatusCode
}
}

"GitData >> GetCommit" should "return one commit" in {
val response = Github(accessToken).gitData
.getCommit(validRepoOwner, validRepoName, validCommitSha)
.exec[Id, HttpResponse[String]](headerUserAgent)

response should be('right)
response.toOption map { r ⇒
r.result.message shouldBe validCommitMsg
r.statusCode shouldBe okStatusCode
}
}
}
165 changes: 160 additions & 5 deletions github4s/jvm/src/test/scala/github4s/unit/ApiSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package github4s.unit

import github4s.api.{Auth, Gists, Repos, Users}
import github4s.api._
import github4s.free.domain.{GistFile, Pagination}
import github4s.utils.{DummyGithubUrls, MockGithubApiServer, TestUtils}
import org.scalatest._
Expand All @@ -39,10 +39,11 @@ class ApiSpec
with DummyGithubUrls
with ImplicitsJVM {

val auth = new Auth[HttpResponse[String], Id]
val repos = new Repos[HttpResponse[String], Id]
val users = new Users[HttpResponse[String], Id]
val gists = new Gists[HttpResponse[String], Id]
val auth = new Auth[HttpResponse[String], Id]
val repos = new Repos[HttpResponse[String], Id]
val users = new Users[HttpResponse[String], Id]
val gists = new Gists[HttpResponse[String], Id]
val gitData = new GitData[HttpResponse[String], Id]

"Auth >> NewAuth" should "return a valid token when valid credential is provided" in {
val response = auth.newAuth(
Expand Down Expand Up @@ -289,4 +290,158 @@ class ApiSpec

}

"GitData >> GetReference" should "return the single reference" in {
val response =
gitData.reference(
accessToken,
headerUserAgent,
validRepoOwner,
validRepoName,
validRefSingle)
response should be('right)

response.toOption map { r =>
r.statusCode shouldBe okStatusCode
}
}

it should "return multiple references" in {
val response =
gitData.reference(
accessToken,
headerUserAgent,
validRepoOwner,
validRepoName,
validRefMultiple)
response should be('right)

response.toOption map { r =>
r.statusCode shouldBe okStatusCode
}
}

it should "return error Left for non existent reference" in {
val response =
gitData.reference(accessToken, headerUserAgent, validRepoOwner, validRepoName, invalidRef)
response should be('left)
}

"GitData >> UpdateReference" should "return the single reference" in {
val response =
gitData.updateReference(
accessToken,
headerUserAgent,
validRepoOwner,
validRepoName,
validRefSingle,
validCommitSha)
response should be('right)

response.toOption map { r =>
r.statusCode shouldBe okStatusCode
}
}

it should "return error Left for non authenticated request" in {
val response =
gitData.updateReference(
None,
headerUserAgent,
validRepoOwner,
validRepoName,
validRefSingle,
validCommitSha)
response should be('left)
}

"GitData >> GetCommit" should "return the single commit" in {
val response =
gitData.commit(accessToken, headerUserAgent, validRepoOwner, validRepoName, validCommitSha)
response should be('right)

response.toOption map { r =>
r.statusCode shouldBe okStatusCode
}
}

it should "return error Left for non existent commit" in {
val response =
gitData.commit(accessToken, headerUserAgent, validRepoOwner, validRepoName, invalidCommitSha)
response should be('left)
}

"GitData >> CreateCommit" should "return the single commit" in {
val response =
gitData.createCommit(
accessToken,
headerUserAgent,
validRepoOwner,
validRepoName,
validNote,
validTreeSha,
List(validCommitSha))
response should be('right)

response.toOption map { r =>
r.statusCode shouldBe createdStatusCode
}
}

it should "return error Left for non authenticated request" in {
val response =
gitData.createCommit(
None,
headerUserAgent,
validRepoOwner,
validRepoName,
validNote,
validTreeSha,
List(validCommitSha))
response should be('left)
}

"GitData >> CreateBlob" should "return the created blob" in {
val response =
gitData.createBlob(accessToken, headerUserAgent, validRepoOwner, validRepoName, validNote)
response should be('right)

response.toOption map { r =>
r.statusCode shouldBe createdStatusCode
}
}

it should "return error Left for non authenticated request" in {
val response =
gitData.createBlob(None, headerUserAgent, validRepoOwner, validRepoName, validNote)
response should be('left)
}

"GitData >> CreateTree" should "return the created tree" in {
val response =
gitData.createTree(
accessToken,
headerUserAgent,
validRepoOwner,
validRepoName,
Some(validTreeSha),
treeDataList)
response should be('right)

response.toOption map { r =>
r.statusCode shouldBe createdStatusCode
}
}

it should "return error Left for non authenticated request" in {
val response =
gitData.createTree(
None,
headerUserAgent,
validRepoOwner,
validRepoName,
Some(validTreeSha),
treeDataList)
response should be('left)
}

}