From 13f2528bef3e626663f73b1f80d1a3fcfb946007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Thu, 19 Mar 2020 09:42:54 +0100 Subject: [PATCH] Fixes commit files method (#1271) * Fixes commit files method * Fixes failing tests Co-authored-by: franciscodr --- .../sbtorgpolicies/github/GitHubOps.scala | 28 ++- .../arbitraries/GitHubArbitraries.scala | 22 +- .../sbtorgpolicies/github/GitHubOpsTest.scala | 222 ++++++++++-------- project/ProjectPlugin.scala | 2 +- 4 files changed, 159 insertions(+), 115 deletions(-) diff --git a/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala b/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala index ec1719f..c2ee346 100644 --- a/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala +++ b/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala @@ -79,7 +79,7 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer]( path <- EitherT.right(Sync[F].delay(file.getAbsolutePath())) content <- EitherT(Sync[F].delay(fileReader.getFileContent(path))) relativePath <- EitherT.right(relativePath(file)) - } yield (content, relativePath) + } yield (relativePath, content) } readFileContents @@ -105,10 +105,11 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer]( def fetchFileContents( path: String, commitSha: String - ): EitherT[F, GitHubException, (String, Option[String])] = - run( + ): EitherT[F, GitHubException, (String, Option[String])] = { + runOption( gh.repos.getContents(owner = owner, repo = repo, path = path, ref = Some(commitSha)) - ).map(res => res.map(content => path -> content.content).head) + ).map(res => path -> res.flatMap(_.head.content)) + } filesAndContents.map(_._1).traverse(fetchFileContents(_, commitSha)) } @@ -369,8 +370,9 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer]( refs.find(_.ref == s"refs/heads/$branch") match { case Some(ref) => EitherT.rightT(ref) case None => - val e = UnexpectedException(s"Branch $branch not found") - EitherT.leftT(GitHubException(s"GitHub returned an error: ${e.getMessage}", Some(e))) + EitherT.leftT( + GitHubException(s"GitHub returned an error: Branch $branch not found", None) + ) } run(gh.gitData.getReference(owner, repo, s"heads/$branch")).flatMap(findReference) @@ -381,8 +383,18 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer]( def run[A](f: F[GHResponse[A]]): EitherT[F, GitHubException, A] = EitherT( Sync[F].attempt(f).map { - case Right(Right(r)) => Right(r.result) - case Right(Left(e)) => + case Right(GHResponse(Right(r), _, _)) => Right(r) + case Right(GHResponse(Left(e), _, _)) => + Left(GitHubException(s"GitHub returned an error: ${e.getMessage}", Some(e))) + case Left(e) => Left(GitHubException("Error making request to GitHub", Some(e))) + } + ) + + def runOption[A](f: F[GHResponse[A]]): EitherT[F, GitHubException, Option[A]] = EitherT( + Sync[F].attempt(f).map { + case Right(GHResponse(Right(r), _, _)) => r.some.asRight[GitHubException] + case Right(GHResponse(Left(e), 404, _)) => none[A].asRight[GitHubException] + case Right(GHResponse(Left(e), _, _)) => Left(GitHubException(s"GitHub returned an error: ${e.getMessage}", Some(e))) case Left(e) => Left(GitHubException("Error making request to GitHub", Some(e))) } diff --git a/core/src/test/scala/sbtorgpolicies/arbitraries/GitHubArbitraries.scala b/core/src/test/scala/sbtorgpolicies/arbitraries/GitHubArbitraries.scala index 35fa90d..b7a61ff 100644 --- a/core/src/test/scala/sbtorgpolicies/arbitraries/GitHubArbitraries.scala +++ b/core/src/test/scala/sbtorgpolicies/arbitraries/GitHubArbitraries.scala @@ -51,14 +51,12 @@ trait GitHubArbitraries { def genGHResponse[T](gen: Gen[T]): Gen[GHResponse[T]] = Gen.oneOf( - genGHException.map(_.asLeft[GHResult[T]]), - gen.map(v => GHResult(v, 200, Map.empty).asRight[GHException]) + genGHException.map(e => GHResponse(e.asLeft[T], 500, Map.empty)), + gen.map(v => GHResponse(v.asRight[GHException], 200, Map.empty)) ) - val genGHException: Gen[GHException] = { - val message = "Generated Exception" - Gen.oneOf(JsonParsingException(message, """{"val": "value"}"""), UnexpectedException(message)) - } + val genGHException: Gen[GHException] = + Gen.const(JsonParsingException("Generated exception", """{"val": "value"}""")) val genEmail: Gen[String] = for { @@ -109,6 +107,12 @@ trait GitHubArbitraries { list2 <- Gen.listOfN(n, genGHResponse(genFullUser)) } yield (list1, list2) + val genRefInfo: Gen[RefInfo] = + for { + sha <- Gen.identifier + url <- genURL + } yield RefInfo(sha, url) + val genRefObject: Gen[RefObject] = for { refObjectType <- Gen.oneOf("commit", "tag") @@ -233,8 +237,8 @@ trait GitHubArbitraries { url <- genURL refAuthor <- genRefAuthor message <- Gen.alphaStr.filter(_ != nonExistingMessage) - tree <- genRefObject - parents <- Gen.listOf(genRefObject) + tree <- genRefInfo + parents <- Gen.listOf(genRefInfo) } yield RefCommit(sha, url, refAuthor, refAuthor, message, tree, parents) val genTreeDataResult: Gen[TreeDataResult] = @@ -298,7 +302,7 @@ trait GitHubArbitraries { } implicit val ghResponseRefObjectArbitrary: Arbitrary[GHResponse[RefInfo]] = Arbitrary { - genGHResponse(genRefObject) + genGHResponse(genRefInfo) } } diff --git a/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala b/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala index ebd9827..a62d269 100644 --- a/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala +++ b/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala @@ -21,7 +21,8 @@ import java.io.File import cats.data.{EitherT, NonEmptyList} import cats.effect.{ContextShift, IO, Timer} import cats.syntax.either._ -import github4s.GithubResponses.{GHException, GHResponse, GHResult, UnexpectedException} +import cats.syntax.option._ +import github4s.GithubResponses.{GHException, GHResponse, JsonParsingException} import github4s._ import github4s.algebras._ import github4s.domain._ @@ -68,20 +69,20 @@ class GitHubOpsTest extends TestOps { (gitHubOps, fileReaderMock, ghGitData, ghPullRequests, ghRepos, ghUsers) } - def toLeftResult[T](e: GHException): Either[OrgPolicyException, T] = - Left(GitHubException(s"GitHub returned an error: ${e.getMessage}", Some(e)): OrgPolicyException) + def toLeftResult[T](message: String, e: Option[GHException]): Either[OrgPolicyException, T] = + Left(GitHubException(s"GitHub returned an error: $message", e): OrgPolicyException) test("GithubOps.fetchContributors works as expected") { val property = forAll(genSimpleAndFullUserLists) { - case (list1: GHResponse[List[User]], list2: List[GHResponse[User]]) => + case (list: GHResponse[List[User]], list2: List[GHResponse[User]]) => val (gitHubOps, _, _, _, ghRepos, ghUsers) = newGitHubOps (ghRepos.listContributors _) .when(*, *, *, *) - .returns(IO.pure(list1)) + .returns(IO.pure(list)) - list1 match { + list.result match { case Right(r) => - r.result.zip(list2) foreach { + r.zip(list2) foreach { case (user1, response) => (ghUsers.get _) .when(user1.login, *) @@ -93,14 +94,14 @@ class GitHubOpsTest extends TestOps { val result: EitherT[IO, OrgPolicyException, List[User]] = gitHubOps.fetchContributors.leftMap[OrgPolicyException](identity) - (list1.left.toOption, list2.find(_.isLeft).flatMap(_.left.toOption)) match { + (list.result.left.toOption, list2.find(_.result.isLeft).flatMap(_.result.left.toOption)) match { case (Some(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case (_, Some(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case _ => - val resultList = list2.collect { - case Right(gHResult) => gHResult.result + val resultList = list2.map(_.result).collect { + case Right(gHResult) => gHResult } result.value.unsafeRunSync() shouldBeEq Right(resultList) } @@ -131,7 +132,7 @@ class GitHubOpsTest extends TestOps { .returns(IO.pure(refCommitResponse)) val maybeParentCommit: Option[String] = - nelRefResponse.toOption.map(_.result.head.`object`.sha) + nelRefResponse.result.toOption.map(_.head.`object`.sha) val contents = filesAndContents.map { case (s1, s2) => @@ -157,7 +158,7 @@ class GitHubOpsTest extends TestOps { contents foreach { case (s1, content) => val response: GHResponse[NonEmptyList[Content]] = - GHResult(NonEmptyList(content, Nil), 200, Map.empty).asRight + GHResponse(NonEmptyList(content, Nil).asRight[GHException], 200, Map.empty) (ghRepos.getContents _) .when(owner, repo, s1, maybeParentCommit, *) .returns(IO.pure(response)) @@ -171,14 +172,14 @@ class GitHubOpsTest extends TestOps { filesAndContents.map(t => new File(baseDir, t._1)) ) - (nelRefResponse, refCommitResponse) match { + (nelRefResponse.result, refCommitResponse.result) match { case (Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) - case (Right(gHResult), _) if !gHResult.result.exists(_.ref == s"refs/heads/$branch") => - val e = UnexpectedException(s"Branch $branch not found") - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) + case (Right(gHResult), _) if !gHResult.exists(_.ref == s"refs/heads/$branch") => + val e = JsonParsingException(s"Branch $branch not found", """{"val": "value"}""") + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case _ => result.value.unsafeRunSync() shouldBeEq Right(None) } @@ -214,14 +215,20 @@ class GitHubOpsTest extends TestOps { .when(*, *, *, *) .returns(IO.pure(refCommitR)) - val maybeParentCommit: Option[String] = nelRefR.toOption.map(_.result.head.`object`.sha) + val maybeParentCommit: Option[String] = nelRefR.result.toOption.map(_.head.`object`.sha) filesAndContents foreach { case (s1, _) => (ghRepos.getContents _) .when(owner, repo, s1, maybeParentCommit, *) .returns( - IO.pure(UnexpectedException("Not Found").asLeft) + IO.pure( + GHResponse( + JsonParsingException("Not Found", """{"val": "value"}""").asLeft, + 500, + Map.empty + ) + ) ) } @@ -245,21 +252,26 @@ class GitHubOpsTest extends TestOps { filesAndContents.map(t => new File(baseDir, t._1)) ) - (nelRefR, refCommitR, treeResultR, createCommitR, updateReferenceR) match { + ( + nelRefR.result, + refCommitR.result, + treeResultR.result, + createCommitR.result, + updateReferenceR.result + ) match { case (Left(e), _, _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) - case (Right(gHResult), _, _, _, _) - if !gHResult.result.exists(_.ref == s"refs/heads/$branch") => - val e = UnexpectedException(s"Branch $branch not found") - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) + case (Right(gHResult), _, _, _, _) if !gHResult.exists(_.ref == s"refs/heads/$branch") => + val e = JsonParsingException(s"Branch $branch not found", """{"val": "value"}""") + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, Left(e), _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, Left(e), _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, _, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case _ => result shouldBeEq EitherT.rightT(None) } @@ -302,7 +314,7 @@ class GitHubOpsTest extends TestOps { .returns(IO.pure(refCommitResponse)) val maybeParentCommit: Option[String] = - nelRefResponse.toOption.map(_.result.head.`object`.sha) + nelRefResponse.result.toOption.map(_.head.`object`.sha) val contents = filesAndContents.map { case (s1, s2) => @@ -328,7 +340,7 @@ class GitHubOpsTest extends TestOps { contents foreach { case (s1, content) => val response: GHResponse[NonEmptyList[Content]] = - GHResult(NonEmptyList(content, Nil), 200, Map.empty).asRight + GHResponse(NonEmptyList(content, Nil).asRight[GHException], 200, Map.empty) (ghRepos.getContents _) .when(owner, repo, s1, maybeParentCommit, *) .returns(IO.pure(response)) @@ -339,14 +351,14 @@ class GitHubOpsTest extends TestOps { .commitFilesAndContents(branch, sampleMessage, filesAndContents) .leftMap[OrgPolicyException](identity) - (nelRefResponse, refCommitResponse) match { + (nelRefResponse.result, refCommitResponse.result) match { case (Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) - case (Right(gHResult), _) if !gHResult.result.exists(_.ref == s"refs/heads/$branch") => - val e = UnexpectedException(s"Branch $branch not found") - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) + case (Right(gHResult), _) if !gHResult.exists(_.ref == s"refs/heads/$branch") => + val e = JsonParsingException(s"Branch $branch not found", """{"val": "value"}""") + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case _ => result shouldBeEq EitherT.rightT(None) } @@ -374,14 +386,20 @@ class GitHubOpsTest extends TestOps { .when(*, *, *, *) .returns(IO.pure(refCommitR)) - val maybeParentCommit: Option[String] = nelRefR.toOption.map(_.result.head.`object`.sha) + val maybeParentCommit: Option[String] = nelRefR.result.toOption.map(_.head.`object`.sha) filesAndContents foreach { case (s1, _) => (ghRepos.getContents _) .when(owner, repo, s1, maybeParentCommit, *) .returns( - IO.pure(UnexpectedException("Not Found").asLeft) + IO.pure( + GHResponse( + JsonParsingException("Not Found", """{"val": "value"}""").asLeft, + 500, + Map.empty + ) + ) ) } @@ -402,21 +420,26 @@ class GitHubOpsTest extends TestOps { .commitFilesAndContents(branch, sampleMessage, filesAndContents) .leftMap[OrgPolicyException](identity) - (nelRefR, refCommitR, treeResultR, createCommitR, updateReferenceR) match { + ( + nelRefR.result, + refCommitR.result, + treeResultR.result, + createCommitR.result, + updateReferenceR.result + ) match { case (Left(e), _, _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) - case (Right(gHResult), _, _, _, _) - if !gHResult.result.exists(_.ref == s"refs/heads/$branch") => - val e = UnexpectedException(s"Branch $branch not found") - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) + case (Right(gHResult), _, _, _, _) if !gHResult.exists(_.ref == s"refs/heads/$branch") => + val e = JsonParsingException(s"Branch $branch not found", """{"val": "value"}""") + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, Left(e), _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, Left(e), _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, _, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case _ => result shouldBeEq EitherT.rightT(None) } @@ -436,11 +459,11 @@ class GitHubOpsTest extends TestOps { val result: EitherT[IO, OrgPolicyException, NonEmptyList[Ref]] = gitHubOps.fetchReference(ref).leftMap[OrgPolicyException](identity) - refResponse match { + refResponse.result match { case Left(e) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case Right(gHResult) => - result.value.unsafeRunSync() shouldBeEq Right(gHResult.result) + result.value.unsafeRunSync() shouldBeEq Right(gHResult) } } @@ -498,25 +521,32 @@ class GitHubOpsTest extends TestOps { val result: EitherT[IO, OrgPolicyException, Ref] = gitHubOps.commitDir(branch, sampleMessage, baseDir) - (nelRefR, refCommitR, refInfoR, treeResultR, createCommitR, updateReferenceR) match { + ( + nelRefR.result, + refCommitR.result, + refInfoR.result, + treeResultR.result, + createCommitR.result, + updateReferenceR.result + ) match { case (Left(e), _, _, _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case (Right(gHResult), _, _, _, _, _) - if !gHResult.result.exists(_.ref == s"refs/heads/$branch") => - val e = UnexpectedException(s"Branch $branch not found") - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + if !gHResult.exists(_.ref == s"refs/heads/$branch") => + val e = JsonParsingException(s"Branch $branch not found", """{"val": "value"}""") + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, Left(e), _, _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, Left(e), _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, Left(e), _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, _, Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, _, _, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, _, _, Right(r)) => - result shouldBeEq EitherT.rightT(r.result) + result shouldBeEq EitherT.rightT(r) } } check(property) @@ -567,21 +597,20 @@ class GitHubOpsTest extends TestOps { .createTagRelease(branch, tag, sampleMessage, releaseDescription) .leftMap[OrgPolicyException](identity) - (nelRefResponse, tagResponse, refResponse, releaseResponse) match { + (nelRefResponse.result, tagResponse.result, refResponse.result, releaseResponse.result) match { case (Left(e), _, _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) - case (Right(gHResult), _, _, _) - if !gHResult.result.exists(_.ref == s"refs/heads/$branch") => - val e = UnexpectedException(s"Branch $branch not found") - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) + case (Right(gHResult), _, _, _) if !gHResult.exists(_.ref == s"refs/heads/$branch") => + val e = JsonParsingException(s"Branch $branch not found", """{"val": "value"}""") + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, Left(e), _, _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) case (_, _, _, Right(gHResult)) => - result shouldBeEq EitherT.rightT(gHResult.result) + result shouldBeEq EitherT.rightT(gHResult) } } @@ -597,7 +626,7 @@ class GitHubOpsTest extends TestOps { (ghRepos.listCommits _) .when(*, *, *, *, *, *, *, *, *) - .returns(IO.pure(Right(GHResult(Nil, 200, Map.empty)))) + .returns(IO.pure(GHResponse(Nil.asRight[GHException], 200, Map.empty))) (ghPullRequests.listPullRequests _) .when(*, *, *, *, *) @@ -608,13 +637,13 @@ class GitHubOpsTest extends TestOps { .latestPullRequests(branch, "", "") .leftMap[OrgPolicyException](identity) - prResponse match { + prResponse.result match { case Right(gHResult) => result.map(_.toSet).value.unsafeRunSync() shouldBeEq Right( - gHResult.result.filter(_.merged_at.nonEmpty).toSet + gHResult.filter(_.merged_at.nonEmpty).toSet ) case Left(e) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) } } check(property) @@ -641,14 +670,14 @@ class GitHubOpsTest extends TestOps { .latestPullRequests(branch, "", nonExistingMessage) .leftMap[OrgPolicyException](identity) - (commitsResponse, prResponse) match { + (commitsResponse.result, prResponse.result) match { case (Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case (_, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case (Right(_), Right(gHResult)) => result.map(_.toSet).value.unsafeRunSync() shouldBeEq Right( - gHResult.result.filter(_.merged_at.nonEmpty).toSet + gHResult.filter(_.merged_at.nonEmpty).toSet ) } } @@ -673,9 +702,8 @@ class GitHubOpsTest extends TestOps { author_url = None ) - val newCommitsResponse = commitsResponse map { ghResult => - ghResult.copy(result = commit :: ghResult.result) - } + val newCommitsResponse = + commitsResponse.copy(result = commitsResponse.result.map(list => commit :: list)) (ghRepos.listCommits _) .when(*, *, *, *, *, *, *, *, *) @@ -690,14 +718,14 @@ class GitHubOpsTest extends TestOps { .latestPullRequests(branch, "", nonExistingMessage) .leftMap[OrgPolicyException](identity) - (commitsResponse, prResponse) match { + (commitsResponse.result, prResponse.result) match { case (Left(e), _) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case (_, Left(e)) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) case (Right(_), Right(gHResult)) => val expected = - gHResult.result + gHResult .filter(_.merged_at.exists(s => dateTimeFormat.parseDateTime(s).isAfter(date2015))) .toSet result.map(_.toSet).value.unsafeRunSync() shouldBeEq Right(expected) @@ -717,14 +745,14 @@ class GitHubOpsTest extends TestOps { val result: EitherT[IO, OrgPolicyException, Ref] = gitHubOps.fetchHeadCommit(branch).leftMap[OrgPolicyException](identity) - refResponse match { + refResponse.result match { case Left(e) => - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) - case Right(gHResult) if gHResult.result.exists(_.ref == s"refs/heads/$branch") => - result.value.unsafeRunSync() shouldBeEq Right(gHResult.result.head) + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, e.some) + case Right(gHResult) if gHResult.exists(_.ref == s"refs/heads/$branch") => + result.value.unsafeRunSync() shouldBeEq Right(gHResult.head) case _ => - val e = UnexpectedException(s"Branch $branch not found") - result.value.unsafeRunSync() shouldBeEq toLeftResult(e) + val e = JsonParsingException(s"Branch $branch not found", """{"val": "value"}""") + result.value.unsafeRunSync() shouldBeEq toLeftResult(e.getMessage, None) } } diff --git a/project/ProjectPlugin.scala b/project/ProjectPlugin.scala index 723d9af..55854c2 100644 --- a/project/ProjectPlugin.scala +++ b/project/ProjectPlugin.scala @@ -22,7 +22,7 @@ object ProjectPlugin extends AutoPlugin { lazy val V = new { val base64: String = "0.2.9" val cats: String = "2.1.1" - val github4s: String = "0.22.0" + val github4s: String = "0.23.0" val moultingyaml: String = "0.4.1" val scala212: String = "2.12.10" val scala213: String = "2.13.1"