Skip to content

Commit d00e132

Browse files
author
Fede Fernández
authored
Adds some git methods (#67)
* Adds the git ops for fetching and create commits * Adds some tests for the git ops * Disables minimum coverage for scalaz and js modules
1 parent 111be95 commit d00e132

22 files changed

Lines changed: 1831 additions & 67 deletions

File tree

build.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ lazy val root = (project in file("."))
66
.dependsOn(github4sJVM, github4sJS, scalaz, docs)
77
.aggregate(github4sJVM, github4sJS, scalaz, docs)
88
.settings(noPublishSettings: _*)
9+
.settings(Seq(coverageFailOnMinimum := false))
910

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

2728
lazy val github4sJVM = github4s.jvm
2829
lazy val github4sJS = github4s.js
30+
.settings(Seq(coverageFailOnMinimum := false))
2931

3032
lazy val docs = (project in file("docs"))
3133
.dependsOn(scalaz)
@@ -38,5 +40,6 @@ lazy val docs = (project in file("docs"))
3840
lazy val scalaz = (project in file("scalaz"))
3941
.settings(moduleName := "github4s-scalaz")
4042
.settings(scalazDependencies: _*)
43+
.settings(Seq(coverageFailOnMinimum := false))
4144
.dependsOn(github4sJVM)
4245
.enablePlugins(AutomateHeaderPlugin)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package github4s.utils.integration
23+
24+
import cats.data.NonEmptyList
25+
import github4s.Github
26+
import github4s.Github._
27+
import github4s.free.domain.{Ref, RefCommit}
28+
import github4s.js.Implicits._
29+
import github4s.utils.TestUtils
30+
import org.scalatest._
31+
32+
class GHGitDataSpec extends AsyncFlatSpec with Matchers with TestUtils {
33+
34+
override implicit val executionContext =
35+
scala.concurrent.ExecutionContext.Implicits.global
36+
37+
"GitData >> GetReference" should "return a list of references" in {
38+
val response = Github(accessToken).gitData
39+
.getReference(validRepoOwner, validRepoName, "heads")
40+
.execFuture(headerUserAgent)
41+
42+
testFutureIsRight[NonEmptyList[Ref]](response, { r =>
43+
r.result.tail.nonEmpty shouldBe true
44+
r.statusCode shouldBe okStatusCode
45+
})
46+
}
47+
48+
it should "return at least one reference" in {
49+
val response = Github(accessToken).gitData
50+
.getReference(validRepoOwner, validRepoName, validRefSingle)
51+
.execFuture(headerUserAgent)
52+
53+
testFutureIsRight[NonEmptyList[Ref]](response, { r =>
54+
r.result.head.ref.contains(validRefSingle) shouldBe true
55+
r.statusCode shouldBe okStatusCode
56+
})
57+
}
58+
59+
"GitData >> GetCommit" should "return one commit" in {
60+
val response = Github(accessToken).gitData
61+
.getCommit(validRepoOwner, validRepoName, validCommitSha)
62+
.execFuture(headerUserAgent)
63+
64+
testFutureIsRight[RefCommit](response, { r =>
65+
r.result.message shouldBe validCommitMsg
66+
r.statusCode shouldBe okStatusCode
67+
})
68+
}
69+
}

github4s/js/src/test/scala/github4s/utils/utils/TestUtils.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@ trait TestUtils extends Matchers {
109109
val validIssueState = "closed"
110110
val validIssueLabel = List("bug", "code review")
111111
val validAssignees = List(validUsername)
112+
113+
val validRefSingle = "heads/master"
114+
115+
val validCommitSha = "d3b048c1f500ee5450e5d7b3d1921ed3e7645891"
116+
val validCommitMsg = "Add SBT project settings"
112117
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package github4s.integration
23+
24+
import cats.Id
25+
import cats.implicits._
26+
import github4s.Github
27+
import github4s.Github._
28+
import github4s.jvm.Implicits._
29+
import github4s.utils.TestUtils
30+
import org.scalatest._
31+
32+
import scalaj.http.HttpResponse
33+
34+
class GHGitDataSpec extends FlatSpec with Matchers with TestUtils {
35+
36+
"GitData >> GetReference" should "return a list of references" in {
37+
val response = Github(accessToken).gitData
38+
.getReference(validRepoOwner, validRepoName, "heads")
39+
.exec[Id, HttpResponse[String]](headerUserAgent)
40+
41+
response should be('right)
42+
response.toOption map { r
43+
r.result.tail.nonEmpty shouldBe true
44+
r.statusCode shouldBe okStatusCode
45+
}
46+
}
47+
48+
it should "return at least one reference" in {
49+
val response = Github(accessToken).gitData
50+
.getReference(validRepoOwner, validRepoName, validRefSingle)
51+
.exec[Id, HttpResponse[String]](headerUserAgent)
52+
53+
response should be('right)
54+
response.toOption map { r
55+
r.result.head.ref.contains(validRefSingle) shouldBe true
56+
r.statusCode shouldBe okStatusCode
57+
}
58+
}
59+
60+
"GitData >> GetCommit" should "return one commit" in {
61+
val response = Github(accessToken).gitData
62+
.getCommit(validRepoOwner, validRepoName, validCommitSha)
63+
.exec[Id, HttpResponse[String]](headerUserAgent)
64+
65+
response should be('right)
66+
response.toOption map { r
67+
r.result.message shouldBe validCommitMsg
68+
r.statusCode shouldBe okStatusCode
69+
}
70+
}
71+
}

github4s/jvm/src/test/scala/github4s/unit/ApiSpec.scala

Lines changed: 160 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
package github4s.unit
2323

24-
import github4s.api.{Auth, Gists, Repos, Users}
24+
import github4s.api._
2525
import github4s.free.domain.{GistFile, Pagination}
2626
import github4s.utils.{DummyGithubUrls, MockGithubApiServer, TestUtils}
2727
import org.scalatest._
@@ -39,10 +39,11 @@ class ApiSpec
3939
with DummyGithubUrls
4040
with ImplicitsJVM {
4141

42-
val auth = new Auth[HttpResponse[String], Id]
43-
val repos = new Repos[HttpResponse[String], Id]
44-
val users = new Users[HttpResponse[String], Id]
45-
val gists = new Gists[HttpResponse[String], Id]
42+
val auth = new Auth[HttpResponse[String], Id]
43+
val repos = new Repos[HttpResponse[String], Id]
44+
val users = new Users[HttpResponse[String], Id]
45+
val gists = new Gists[HttpResponse[String], Id]
46+
val gitData = new GitData[HttpResponse[String], Id]
4647

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

290291
}
291292

293+
"GitData >> GetReference" should "return the single reference" in {
294+
val response =
295+
gitData.reference(
296+
accessToken,
297+
headerUserAgent,
298+
validRepoOwner,
299+
validRepoName,
300+
validRefSingle)
301+
response should be('right)
302+
303+
response.toOption map { r =>
304+
r.statusCode shouldBe okStatusCode
305+
}
306+
}
307+
308+
it should "return multiple references" in {
309+
val response =
310+
gitData.reference(
311+
accessToken,
312+
headerUserAgent,
313+
validRepoOwner,
314+
validRepoName,
315+
validRefMultiple)
316+
response should be('right)
317+
318+
response.toOption map { r =>
319+
r.statusCode shouldBe okStatusCode
320+
}
321+
}
322+
323+
it should "return error Left for non existent reference" in {
324+
val response =
325+
gitData.reference(accessToken, headerUserAgent, validRepoOwner, validRepoName, invalidRef)
326+
response should be('left)
327+
}
328+
329+
"GitData >> UpdateReference" should "return the single reference" in {
330+
val response =
331+
gitData.updateReference(
332+
accessToken,
333+
headerUserAgent,
334+
validRepoOwner,
335+
validRepoName,
336+
validRefSingle,
337+
validCommitSha)
338+
response should be('right)
339+
340+
response.toOption map { r =>
341+
r.statusCode shouldBe okStatusCode
342+
}
343+
}
344+
345+
it should "return error Left for non authenticated request" in {
346+
val response =
347+
gitData.updateReference(
348+
None,
349+
headerUserAgent,
350+
validRepoOwner,
351+
validRepoName,
352+
validRefSingle,
353+
validCommitSha)
354+
response should be('left)
355+
}
356+
357+
"GitData >> GetCommit" should "return the single commit" in {
358+
val response =
359+
gitData.commit(accessToken, headerUserAgent, validRepoOwner, validRepoName, validCommitSha)
360+
response should be('right)
361+
362+
response.toOption map { r =>
363+
r.statusCode shouldBe okStatusCode
364+
}
365+
}
366+
367+
it should "return error Left for non existent commit" in {
368+
val response =
369+
gitData.commit(accessToken, headerUserAgent, validRepoOwner, validRepoName, invalidCommitSha)
370+
response should be('left)
371+
}
372+
373+
"GitData >> CreateCommit" should "return the single commit" in {
374+
val response =
375+
gitData.createCommit(
376+
accessToken,
377+
headerUserAgent,
378+
validRepoOwner,
379+
validRepoName,
380+
validNote,
381+
validTreeSha,
382+
List(validCommitSha))
383+
response should be('right)
384+
385+
response.toOption map { r =>
386+
r.statusCode shouldBe createdStatusCode
387+
}
388+
}
389+
390+
it should "return error Left for non authenticated request" in {
391+
val response =
392+
gitData.createCommit(
393+
None,
394+
headerUserAgent,
395+
validRepoOwner,
396+
validRepoName,
397+
validNote,
398+
validTreeSha,
399+
List(validCommitSha))
400+
response should be('left)
401+
}
402+
403+
"GitData >> CreateBlob" should "return the created blob" in {
404+
val response =
405+
gitData.createBlob(accessToken, headerUserAgent, validRepoOwner, validRepoName, validNote)
406+
response should be('right)
407+
408+
response.toOption map { r =>
409+
r.statusCode shouldBe createdStatusCode
410+
}
411+
}
412+
413+
it should "return error Left for non authenticated request" in {
414+
val response =
415+
gitData.createBlob(None, headerUserAgent, validRepoOwner, validRepoName, validNote)
416+
response should be('left)
417+
}
418+
419+
"GitData >> CreateTree" should "return the created tree" in {
420+
val response =
421+
gitData.createTree(
422+
accessToken,
423+
headerUserAgent,
424+
validRepoOwner,
425+
validRepoName,
426+
Some(validTreeSha),
427+
treeDataList)
428+
response should be('right)
429+
430+
response.toOption map { r =>
431+
r.statusCode shouldBe createdStatusCode
432+
}
433+
}
434+
435+
it should "return error Left for non authenticated request" in {
436+
val response =
437+
gitData.createTree(
438+
None,
439+
headerUserAgent,
440+
validRepoOwner,
441+
validRepoName,
442+
Some(validTreeSha),
443+
treeDataList)
444+
response should be('left)
445+
}
446+
292447
}

0 commit comments

Comments
 (0)