From 43cefcb5904741c561e7000805fe6801b0b57f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Wed, 31 May 2023 11:04:38 +0200 Subject: [PATCH 1/7] Allow sending different auth headers to GitHub4s --- .jvmopts | 3 -- .../src/main/scala/github4s/Github.scala | 16 +++++-- .../scala/github4s/algebras/AccessToken.scala | 34 -------------- .../scala/github4s/algebras/AuthHeader.scala | 5 ++ .../main/scala/github4s/http/HttpClient.scala | 47 +++++++++---------- .../scala/github4s/http/RequestBuilder.scala | 7 +-- .../interpreters/StaticAccessToken.scala | 33 ------------- .../interpreters/StaticTokenAuthHeader.scala | 17 +++++++ .../scala/github4s/modules/GithubAPIs.scala | 6 +-- .../test/scala/github4s/utils/BaseSpec.scala | 14 +++--- 10 files changed, 66 insertions(+), 116 deletions(-) delete mode 100644 github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala create mode 100644 github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala delete mode 100644 github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala create mode 100644 github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala diff --git a/.jvmopts b/.jvmopts index e064f852..05d6d0c4 100644 --- a/.jvmopts +++ b/.jvmopts @@ -6,6 +6,3 @@ -XX:ReservedCodeCacheSize=250M -XX:+TieredCompilation -XX:-UseGCOverheadLimit -# effectively adds GC to Perm space --XX:+CMSClassUnloadingEnabled -# must be enabled for CMSClassUnloadingEnabled to work diff --git a/github4s/shared/src/main/scala/github4s/Github.scala b/github4s/shared/src/main/scala/github4s/Github.scala index 8fe15871..bd826517 100644 --- a/github4s/shared/src/main/scala/github4s/Github.scala +++ b/github4s/shared/src/main/scala/github4s/Github.scala @@ -16,19 +16,19 @@ package github4s -import cats.effect.kernel.Concurrent +import cats.effect.Concurrent import github4s.algebras._ -import github4s.interpreters.StaticAccessToken +import github4s.interpreters.StaticTokenAuthHeader import github4s.modules._ import org.http4s.client.Client class Github[F[_]: Concurrent]( client: Client[F], - accessToken: AccessToken[F] + authHeader: AuthHeader[F] )(implicit config: GithubConfig) extends GithubAPIs[F] { - private lazy val module: GithubAPIs[F] = new GithubAPIv3[F](client, config, accessToken) + private lazy val module: GithubAPIs[F] = new GithubAPIv3[F](client, config, authHeader) lazy val users: Users[F] = module.users lazy val repos: Repositories[F] = module.repos @@ -50,5 +50,11 @@ object Github { client: Client[F], accessToken: Option[String] = None )(implicit config: GithubConfig): Github[F] = - new Github[F](client, new StaticAccessToken(accessToken)) + new Github[F](client, StaticTokenAuthHeader(accessToken)) + + def withAuthHeader[F[_]: Concurrent]( + client: Client[F], + authHeader: AuthHeader[F] + )(implicit config: GithubConfig): Github[F] = + new Github[F](client, authHeader) } diff --git a/github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala b/github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala deleted file mode 100644 index 7d387f22..00000000 --- a/github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2016-2023 47 Degrees Open Source - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package github4s.algebras - -import github4s.GHResponse - -/** - * Source of static or expiring github tokens - * - * For github app authentication you'd want to create a token source which calls github's - * installation authentication api with a jwt token, generated from a private key These tokens have - * a 1h lifetime, so it's a good idea to handle expired tokens here as well - * - * @see - * https://docs.github.com/en/free-pro-team@latest/developers/apps/authenticating-with-github-apps - */ -trait AccessToken[F[_]] { - - def withAccessToken[T](f: Option[String] => F[GHResponse[T]]): F[GHResponse[T]] -} diff --git a/github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala b/github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala new file mode 100644 index 00000000..e56d8097 --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala @@ -0,0 +1,5 @@ +package github4s.algebras + +trait AuthHeader[F[_]] { + def header: F[Map[String, String]] +} diff --git a/github4s/shared/src/main/scala/github4s/http/HttpClient.scala b/github4s/shared/src/main/scala/github4s/http/HttpClient.scala index 5681c507..5104637c 100644 --- a/github4s/shared/src/main/scala/github4s/http/HttpClient.scala +++ b/github4s/shared/src/main/scala/github4s/http/HttpClient.scala @@ -22,7 +22,7 @@ import cats.effect.kernel.Concurrent import cats.syntax.all._ import github4s.GHError._ import github4s._ -import github4s.algebras.AccessToken +import github4s.algebras.AuthHeader import github4s.domain.Pagination import github4s.http.Http4sSyntax._ import io.circe.{Decoder, Encoder} @@ -34,10 +34,12 @@ import org.http4s._ class HttpClient[F[_]: Concurrent]( client: Client[F], val config: GithubConfig, - accessTokens: AccessToken[F] + authHeader: AuthHeader[F] ) { import HttpClient._ - import accessTokens._ + + def withAuthHeader[T](f: Map[String, String] => F[GHResponse[T]]): F[GHResponse[T]] = + authHeader.header.flatMap(f) def get[Res: Decoder]( method: String, @@ -45,10 +47,10 @@ class HttpClient[F[_]: Concurrent]( params: Map[String, String] = Map.empty, pagination: Option[Pagination] = None ): F[GHResponse[Res]] = - withAccessToken { accessToken => + withAuthHeader { authHeader => run[Unit, Res]( RequestBuilder(url = buildURL(method)) - .withAuth(accessToken) + .withAuthHeader(authHeader) .withHeaders(headers) .withParams( params ++ pagination.fold(Map.empty[String, String])(p => @@ -62,9 +64,9 @@ class HttpClient[F[_]: Concurrent]( url: String, headers: Map[String, String] = Map.empty ): F[GHResponse[Unit]] = - withAccessToken(accessToken => + withAuthHeader(authHeader => runWithoutResponse[Unit]( - RequestBuilder(buildURL(url)).withHeaders(headers).withAuth(accessToken) + RequestBuilder(buildURL(url)).withHeaders(headers).withAuthHeader(authHeader) ) ) @@ -73,10 +75,10 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map.empty, data: Req ): F[GHResponse[Res]] = - withAccessToken(accessToken => + withAuthHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(method)).patchMethod - .withAuth(accessToken) + .withAuthHeader(authHeader) .withHeaders(headers) .withData(data) ) @@ -87,10 +89,10 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map(), data: Req ): F[GHResponse[Res]] = - withAccessToken(accessToken => + withAuthHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(url)).putMethod - .withAuth(accessToken) + .withAuthHeader(authHeader) .withHeaders(headers) .withData(data) ) @@ -101,22 +103,15 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map.empty, data: Req ): F[GHResponse[Res]] = - withAccessToken(accessToken => + withAuthHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(url)).postMethod - .withAuth(accessToken) + .withAuthHeader(authHeader) .withHeaders(headers) .withData(data) ) ) - def postAuth[Req: Encoder, Res: Decoder]( - method: String, - headers: Map[String, String] = Map.empty, - data: Req - ): F[GHResponse[Res]] = - run[Req, Res](RequestBuilder(buildURL(method)).postMethod.withHeaders(headers).withData(data)) - def postOAuth[Res: Decoder]( url: String, headers: Map[String, String] = Map.empty, @@ -132,9 +127,9 @@ class HttpClient[F[_]: Concurrent]( url: String, headers: Map[String, String] = Map.empty ): F[GHResponse[Unit]] = - withAccessToken(accessToken => + withAuthHeader(authHeader => run[Unit, Unit]( - RequestBuilder(buildURL(url)).deleteMethod.withHeaders(headers).withAuth(accessToken) + RequestBuilder(buildURL(url)).deleteMethod.withHeaders(headers).withAuthHeader(authHeader) ) ) @@ -142,10 +137,10 @@ class HttpClient[F[_]: Concurrent]( url: String, headers: Map[String, String] = Map.empty ): F[GHResponse[Res]] = - withAccessToken(accessToken => + withAuthHeader(authHeader => run[Unit, Res]( RequestBuilder(buildURL(url)).deleteMethod - .withAuth(accessToken) + .withAuthHeader(authHeader) .withHeaders(headers) ) ) @@ -155,10 +150,10 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map.empty, data: Req ): F[GHResponse[Res]] = - withAccessToken(accessToken => + withAuthHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(url)).deleteMethod - .withAuth(accessToken) + .withAuthHeader(authHeader) .withHeaders(headers) .withData(data) ) diff --git a/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala b/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala index 6da83918..db6135e7 100644 --- a/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala +++ b/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala @@ -41,9 +41,6 @@ case class RequestBuilder[Res]( def withData(data: Res): RequestBuilder[Res] = this.copy(data = Some(data)) - def withAuth(accessToken: Option[String] = None): RequestBuilder[Res] = - this.copy(authHeader = accessToken match { - case Some(token) => Map("Authorization" -> s"token $token") - case _ => Map.empty[String, String] - }) + def withAuthHeader(authHeader: Map[String, String]): RequestBuilder[Res] = + this.copy(authHeader = authHeader) } diff --git a/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala b/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala deleted file mode 100644 index 8cb9be12..00000000 --- a/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016-2023 47 Degrees Open Source - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package github4s.interpreters - -import github4s.GHResponse -import github4s.algebras.AccessToken - -/** - * A simple static version - */ -class StaticAccessToken[F[_]](accessToken: Option[String]) extends AccessToken[F] { - - override def withAccessToken[T](f: Option[String] => F[GHResponse[T]]): F[GHResponse[T]] = - f(accessToken) -} - -object StaticAccessToken { - def noToken[F[_]] = new StaticAccessToken[F](None) -} diff --git a/github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala b/github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala new file mode 100644 index 00000000..17a4e067 --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala @@ -0,0 +1,17 @@ +package github4s.interpreters + +import cats.Applicative +import cats.syntax.all._ +import github4s.algebras.AuthHeader + +case class StaticTokenAuthHeader[F[_]: Applicative](accessToken: Option[String]) + extends AuthHeader[F] { + override def header: F[Map[String, String]] = + accessToken + .fold(Map.empty[String, String])(token => Map("Authorization" -> s"token $token")) + .pure[F] +} + +object StaticTokenAuthHeader { + def noToken[F[_]: Applicative] = StaticTokenAuthHeader[F](none[String]) +} diff --git a/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala b/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala index 46cc551a..f52ab3ec 100644 --- a/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala +++ b/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala @@ -26,10 +26,10 @@ import org.http4s.client.Client class GithubAPIv3[F[_]: Concurrent]( client: Client[F], config: GithubConfig, - accessToken: AccessToken[F] + authHeader: AuthHeader[F] ) extends GithubAPIs[F] { - implicit val httpClient: HttpClient[F] = new HttpClient[F](client, config, accessToken) + implicit val httpClient: HttpClient[F] = new HttpClient[F](client, config, authHeader) override val users: Users[F] = new UsersInterpreter[F] override val repos: Repositories[F] = new RepositoriesInterpreter[F] @@ -49,5 +49,5 @@ class GithubAPIv3[F[_]: Concurrent]( object GithubAPIv3 { def noAuth[F[_]: Concurrent](client: Client[F], config: GithubConfig): GithubAPIv3[F] = - new GithubAPIv3[F](client, config, StaticAccessToken.noToken) + new GithubAPIv3[F](client, config, StaticTokenAuthHeader.noToken) } diff --git a/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala b/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala index 167c87cb..768c43d8 100644 --- a/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala +++ b/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala @@ -18,7 +18,7 @@ package github4s.utils import cats.effect.{unsafe, IO} import github4s.http.HttpClient -import github4s.interpreters.StaticAccessToken +import github4s.interpreters.StaticTokenAuthHeader import github4s.{GithubConfig, IOAssertions} import io.circe.{Decoder, Encoder} import org.http4s.client.Client @@ -61,7 +61,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.params == params => response.map(body => Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, new StaticAccessToken(sampleToken)) + new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) } protected def httpClientMockGetWithoutResponse( @@ -76,7 +76,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.headers == Headers(userAgent) => response.map(_ => Response[IO](responseStatus).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, new StaticAccessToken(sampleToken)) + new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) } protected def httpClientMockPost[In: Decoder, Out: Encoder]( @@ -101,7 +101,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio response.map(body => Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, new StaticAccessToken(sampleToken)) + new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) } protected def httpClientMockPatch[In: Decoder, Out: Encoder]( @@ -135,7 +135,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.headers == Headers(userAgent) => response.as(Response[IO](responseStatus).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, new StaticAccessToken(sampleToken)) + new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) } protected def httpClientMockDeleteWithResponse[Out: Encoder]( @@ -150,7 +150,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.headers == Headers(userAgent) => response.map(body => Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, new StaticAccessToken(sampleToken)) + new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) } protected def httpClientMockDeleteWithBody[In: Decoder, Out: Encoder]( @@ -187,7 +187,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders) ) } - new HttpClient(httpClientMock, dummyConfig, new StaticAccessToken(sampleToken)) + new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) } private def httpMock(pf: PartialFunction[Request[IO], IO[Response[IO]]]) = From 31f01f98f9f9bc927fe6fd43cfc47242e9eb8b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Wed, 31 May 2023 15:30:42 +0200 Subject: [PATCH 2/7] Adds mima and keeps compatibility on public API --- build.sbt | 20 ++++++- .../src/main/scala/github4s/Github.scala | 33 ++-------- .../main/scala/github4s/GithubClient.scala | 60 +++++++++++++++++++ .../github4s/algebras/AccessHeader.scala | 16 +++++ .../scala/github4s/algebras/AccessToken.scala | 33 ++++++++++ .../scala/github4s/algebras/AuthHeader.scala | 5 -- .../main/scala/github4s/http/HttpClient.scala | 31 ++++++---- .../scala/github4s/http/RequestBuilder.scala | 6 ++ .../interpreters/StaticAccessHeader.scala | 13 ++++ .../interpreters/StaticAccessToken.scala | 33 ++++++++++ .../interpreters/StaticTokenAuthHeader.scala | 17 ------ .../scala/github4s/modules/GithubAPIs.scala | 27 ++------- .../scala/github4s/modules/GithubAPIsV3.scala | 53 ++++++++++++++++ project/plugins.sbt | 1 + 14 files changed, 262 insertions(+), 86 deletions(-) create mode 100644 github4s/shared/src/main/scala/github4s/GithubClient.scala create mode 100644 github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala create mode 100644 github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala delete mode 100644 github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala create mode 100644 github4s/shared/src/main/scala/github4s/interpreters/StaticAccessHeader.scala create mode 100644 github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala delete mode 100644 github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala create mode 100644 github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala diff --git a/build.sbt b/build.sbt index ab9d4cc9..c4623b39 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,8 @@ import ProjectPlugin.on +//import com.typesafe.tools.mima.MimaPlugin +import com.typesafe.tools.mima.core._ + +Global / onChangedBuildSource := ReloadOnSourceChanges ThisBuild / organization := "com.47deg" @@ -10,7 +14,12 @@ val allScalaVersions = scala2Versions :+ scala3Version ThisBuild / scalaVersion := scala213 ThisBuild / crossScalaVersions := allScalaVersions -addCommandAlias("ci-test", "scalafmtCheckAll; scalafmtSbtCheck; mdoc; ++test") +disablePlugins(MimaPlugin) + +addCommandAlias( + "ci-test", + "scalafmtCheckAll; scalafmtSbtCheck; mimaReportBinaryIssues; mdoc; ++test" +) addCommandAlias("ci-docs", "github; mdoc; headerCreateAll; publishMicrosite") addCommandAlias("ci-publish", "github; ci-release") @@ -19,6 +28,7 @@ publish / skip := true lazy val github4s = (crossProject(JSPlatform, JVMPlatform)) .crossType(CrossType.Full) .withoutSuffixFor(JVMPlatform) + .enablePlugins(MimaPlugin) .settings(coreDeps: _*) .settings( // Increase number of inlines, needed for circe semiauto derivation @@ -26,7 +36,11 @@ lazy val github4s = (crossProject(JSPlatform, JVMPlatform)) // See the README for why this is necessary // https://github.com/scala-js/scala-js-macrotask-executor/tree/v1.0.0 // tl;dr: without it, performance problems and concurrency bugs abound - libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0" % Test + libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0" % Test, + mimaPreviousArtifacts := Set("com.47deg" %% "github4s" % "0.32.0"), + mimaBinaryIssueFilters ++= Seq( + ProblemFilters.exclude[IncompatibleMethTypeProblem]("github4s.http.HttpClient.this") + ) ) ////////// @@ -37,11 +51,13 @@ lazy val microsite: Project = project .dependsOn(github4s.jvm) .enablePlugins(MicrositesPlugin) .enablePlugins(ScalaUnidocPlugin) + .disablePlugins(MimaPlugin) .settings(micrositeSettings: _*) .settings(publish / skip := true) .settings(ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(github4s.jvm, microsite)) lazy val documentation = project .enablePlugins(MdocPlugin) + .disablePlugins(MimaPlugin) .settings(mdocOut := file(".")) .settings(publish / skip := true) diff --git a/github4s/shared/src/main/scala/github4s/Github.scala b/github4s/shared/src/main/scala/github4s/Github.scala index bd826517..6f921516 100644 --- a/github4s/shared/src/main/scala/github4s/Github.scala +++ b/github4s/shared/src/main/scala/github4s/Github.scala @@ -18,43 +18,22 @@ package github4s import cats.effect.Concurrent import github4s.algebras._ -import github4s.interpreters.StaticTokenAuthHeader -import github4s.modules._ +import github4s.interpreters.StaticAccessToken import org.http4s.client.Client +@deprecated("Use github4s.GithubClient instead", "0.33.0") class Github[F[_]: Concurrent]( client: Client[F], - authHeader: AuthHeader[F] + accessToken: AccessToken[F] )(implicit config: GithubConfig) - extends GithubAPIs[F] { - - private lazy val module: GithubAPIs[F] = new GithubAPIv3[F](client, config, authHeader) - - lazy val users: Users[F] = module.users - lazy val repos: Repositories[F] = module.repos - lazy val auth: Auth[F] = module.auth - lazy val gists: Gists[F] = module.gists - lazy val issues: Issues[F] = module.issues - lazy val activities: Activities[F] = module.activities - lazy val gitData: GitData[F] = module.gitData - lazy val pullRequests: PullRequests[F] = module.pullRequests - lazy val organizations: Organizations[F] = module.organizations - lazy val teams: Teams[F] = module.teams - lazy val projects: Projects[F] = module.projects - lazy val search: Search[F] = module.search -} + extends GithubClient[F](client, AccessHeader.from(accessToken)) object Github { + @deprecated("Use github4s.GithubClient instead", "0.33.0") def apply[F[_]: Concurrent]( client: Client[F], accessToken: Option[String] = None )(implicit config: GithubConfig): Github[F] = - new Github[F](client, StaticTokenAuthHeader(accessToken)) - - def withAuthHeader[F[_]: Concurrent]( - client: Client[F], - authHeader: AuthHeader[F] - )(implicit config: GithubConfig): Github[F] = - new Github[F](client, authHeader) + new Github[F](client, new StaticAccessToken(accessToken)) } diff --git a/github4s/shared/src/main/scala/github4s/GithubClient.scala b/github4s/shared/src/main/scala/github4s/GithubClient.scala new file mode 100644 index 00000000..8a239c69 --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/GithubClient.scala @@ -0,0 +1,60 @@ +/* + * Copyright 2016-2023 47 Degrees Open Source + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package github4s + +import cats.effect.Concurrent +import github4s.algebras._ +import github4s.interpreters.StaticAccessToken +import github4s.modules._ +import org.http4s.client.Client + +private[github4s] class GithubClient[F[_]: Concurrent]( + client: Client[F], + authHeader: AccessHeader[F] +)(implicit config: GithubConfig) + extends GithubAPIs[F] { + + private lazy val module: GithubAPIs[F] = new GithubAPIsV3[F](client, config, authHeader) + + lazy val users: Users[F] = module.users + lazy val repos: Repositories[F] = module.repos + lazy val auth: Auth[F] = module.auth + lazy val gists: Gists[F] = module.gists + lazy val issues: Issues[F] = module.issues + lazy val activities: Activities[F] = module.activities + lazy val gitData: GitData[F] = module.gitData + lazy val pullRequests: PullRequests[F] = module.pullRequests + lazy val organizations: Organizations[F] = module.organizations + lazy val teams: Teams[F] = module.teams + lazy val projects: Projects[F] = module.projects + lazy val search: Search[F] = module.search +} + +object GithubClient { + + def apply[F[_]: Concurrent]( + client: Client[F], + accessToken: Option[String] = None + )(implicit config: GithubConfig): GithubAPIs[F] = + new GithubClient[F](client, AccessHeader.from(new StaticAccessToken(accessToken))) + + def withAuthHeader[F[_]: Concurrent]( + client: Client[F], + authHeader: AccessHeader[F] + )(implicit config: GithubConfig): GithubAPIs[F] = + new GithubClient[F](client, authHeader) +} diff --git a/github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala b/github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala new file mode 100644 index 00000000..797b3d8e --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala @@ -0,0 +1,16 @@ +package github4s.algebras + +import github4s.GHResponse + +trait AccessHeader[F[_]] { + def withAccessHeader[T](f: Map[String, String] => F[GHResponse[T]]): F[GHResponse[T]] +} + +object AccessHeader { + def from[F[_]](accessToken: AccessToken[F]): AccessHeader[F] = new AccessHeader[F] { + override def withAccessHeader[T](f: Map[String, String] => F[GHResponse[T]]): F[GHResponse[T]] = + accessToken.withAccessToken { token => + f(Map("Authorization" -> s"token $token")) + } + } +} diff --git a/github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala b/github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala new file mode 100644 index 00000000..e0fadd75 --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/algebras/AccessToken.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2016-2023 47 Degrees Open Source + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package github4s.algebras + +import github4s.GHResponse + +/** + * Source of static or expiring github tokens + * + * For github app authentication you'd want to create a token source which calls github's + * installation authentication api with a jwt token, generated from a private key These tokens have + * a 1h lifetime, so it's a good idea to handle expired tokens here as well + * + * @see + * https://docs.github.com/en/free-pro-team@latest/developers/apps/authenticating-with-github-apps + */ +trait AccessToken[F[_]] { + def withAccessToken[T](f: Option[String] => F[GHResponse[T]]): F[GHResponse[T]] +} diff --git a/github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala b/github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala deleted file mode 100644 index e56d8097..00000000 --- a/github4s/shared/src/main/scala/github4s/algebras/AuthHeader.scala +++ /dev/null @@ -1,5 +0,0 @@ -package github4s.algebras - -trait AuthHeader[F[_]] { - def header: F[Map[String, String]] -} diff --git a/github4s/shared/src/main/scala/github4s/http/HttpClient.scala b/github4s/shared/src/main/scala/github4s/http/HttpClient.scala index 5104637c..ce44b419 100644 --- a/github4s/shared/src/main/scala/github4s/http/HttpClient.scala +++ b/github4s/shared/src/main/scala/github4s/http/HttpClient.scala @@ -22,7 +22,7 @@ import cats.effect.kernel.Concurrent import cats.syntax.all._ import github4s.GHError._ import github4s._ -import github4s.algebras.AuthHeader +import github4s.algebras.AccessHeader import github4s.domain.Pagination import github4s.http.Http4sSyntax._ import io.circe.{Decoder, Encoder} @@ -34,12 +34,10 @@ import org.http4s._ class HttpClient[F[_]: Concurrent]( client: Client[F], val config: GithubConfig, - authHeader: AuthHeader[F] + accessHeader: AccessHeader[F] ) { import HttpClient._ - - def withAuthHeader[T](f: Map[String, String] => F[GHResponse[T]]): F[GHResponse[T]] = - authHeader.header.flatMap(f) + import accessHeader._ def get[Res: Decoder]( method: String, @@ -47,7 +45,7 @@ class HttpClient[F[_]: Concurrent]( params: Map[String, String] = Map.empty, pagination: Option[Pagination] = None ): F[GHResponse[Res]] = - withAuthHeader { authHeader => + withAccessHeader { authHeader => run[Unit, Res]( RequestBuilder(url = buildURL(method)) .withAuthHeader(authHeader) @@ -64,7 +62,7 @@ class HttpClient[F[_]: Concurrent]( url: String, headers: Map[String, String] = Map.empty ): F[GHResponse[Unit]] = - withAuthHeader(authHeader => + withAccessHeader(authHeader => runWithoutResponse[Unit]( RequestBuilder(buildURL(url)).withHeaders(headers).withAuthHeader(authHeader) ) @@ -75,7 +73,7 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map.empty, data: Req ): F[GHResponse[Res]] = - withAuthHeader(authHeader => + withAccessHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(method)).patchMethod .withAuthHeader(authHeader) @@ -89,7 +87,7 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map(), data: Req ): F[GHResponse[Res]] = - withAuthHeader(authHeader => + withAccessHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(url)).putMethod .withAuthHeader(authHeader) @@ -103,7 +101,7 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map.empty, data: Req ): F[GHResponse[Res]] = - withAuthHeader(authHeader => + withAccessHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(url)).postMethod .withAuthHeader(authHeader) @@ -112,6 +110,13 @@ class HttpClient[F[_]: Concurrent]( ) ) + def postAuth[Req: Encoder, Res: Decoder]( + method: String, + headers: Map[String, String] = Map.empty, + data: Req + ): F[GHResponse[Res]] = + run[Req, Res](RequestBuilder(buildURL(method)).postMethod.withHeaders(headers).withData(data)) + def postOAuth[Res: Decoder]( url: String, headers: Map[String, String] = Map.empty, @@ -127,7 +132,7 @@ class HttpClient[F[_]: Concurrent]( url: String, headers: Map[String, String] = Map.empty ): F[GHResponse[Unit]] = - withAuthHeader(authHeader => + withAccessHeader(authHeader => run[Unit, Unit]( RequestBuilder(buildURL(url)).deleteMethod.withHeaders(headers).withAuthHeader(authHeader) ) @@ -137,7 +142,7 @@ class HttpClient[F[_]: Concurrent]( url: String, headers: Map[String, String] = Map.empty ): F[GHResponse[Res]] = - withAuthHeader(authHeader => + withAccessHeader(authHeader => run[Unit, Res]( RequestBuilder(buildURL(url)).deleteMethod .withAuthHeader(authHeader) @@ -150,7 +155,7 @@ class HttpClient[F[_]: Concurrent]( headers: Map[String, String] = Map.empty, data: Req ): F[GHResponse[Res]] = - withAuthHeader(authHeader => + withAccessHeader(authHeader => run[Req, Res]( RequestBuilder(buildURL(url)).deleteMethod .withAuthHeader(authHeader) diff --git a/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala b/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala index db6135e7..1b8badc3 100644 --- a/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala +++ b/github4s/shared/src/main/scala/github4s/http/RequestBuilder.scala @@ -43,4 +43,10 @@ case class RequestBuilder[Res]( def withAuthHeader(authHeader: Map[String, String]): RequestBuilder[Res] = this.copy(authHeader = authHeader) + + def withAuth(accessToken: Option[String] = None): RequestBuilder[Res] = + this.copy(authHeader = accessToken match { + case Some(token) => Map("Authorization" -> s"token $token") + case _ => Map.empty[String, String] + }) } diff --git a/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessHeader.scala b/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessHeader.scala new file mode 100644 index 00000000..e4f11c72 --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessHeader.scala @@ -0,0 +1,13 @@ +package github4s.interpreters + +import github4s.GHResponse +import github4s.algebras.AccessHeader + +case class StaticAccessHeader[F[_]](accessHeader: Map[String, String]) extends AccessHeader[F] { + override def withAccessHeader[T](f: Map[String, String] => F[GHResponse[T]]): F[GHResponse[T]] = + f(accessHeader) +} + +object StaticAccessHeader { + def noHeader[F[_]] = new StaticAccessHeader[F](Map.empty) +} diff --git a/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala b/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala new file mode 100644 index 00000000..8cb9be12 --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/interpreters/StaticAccessToken.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2016-2023 47 Degrees Open Source + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package github4s.interpreters + +import github4s.GHResponse +import github4s.algebras.AccessToken + +/** + * A simple static version + */ +class StaticAccessToken[F[_]](accessToken: Option[String]) extends AccessToken[F] { + + override def withAccessToken[T](f: Option[String] => F[GHResponse[T]]): F[GHResponse[T]] = + f(accessToken) +} + +object StaticAccessToken { + def noToken[F[_]] = new StaticAccessToken[F](None) +} diff --git a/github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala b/github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala deleted file mode 100644 index 17a4e067..00000000 --- a/github4s/shared/src/main/scala/github4s/interpreters/StaticTokenAuthHeader.scala +++ /dev/null @@ -1,17 +0,0 @@ -package github4s.interpreters - -import cats.Applicative -import cats.syntax.all._ -import github4s.algebras.AuthHeader - -case class StaticTokenAuthHeader[F[_]: Applicative](accessToken: Option[String]) - extends AuthHeader[F] { - override def header: F[Map[String, String]] = - accessToken - .fold(Map.empty[String, String])(token => Map("Authorization" -> s"token $token")) - .pure[F] -} - -object StaticTokenAuthHeader { - def noToken[F[_]: Applicative] = StaticTokenAuthHeader[F](none[String]) -} diff --git a/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala b/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala index f52ab3ec..f453a280 100644 --- a/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala +++ b/github4s/shared/src/main/scala/github4s/modules/GithubAPIs.scala @@ -19,35 +19,18 @@ package github4s.modules import cats.effect.kernel.Concurrent import github4s.GithubConfig import github4s.algebras._ -import github4s.http.HttpClient import github4s.interpreters._ import org.http4s.client.Client +@deprecated("Use github4s.modules.GithubAPIsV3 instead", "0.33.0") class GithubAPIv3[F[_]: Concurrent]( client: Client[F], config: GithubConfig, - authHeader: AuthHeader[F] -) extends GithubAPIs[F] { - - implicit val httpClient: HttpClient[F] = new HttpClient[F](client, config, authHeader) - - override val users: Users[F] = new UsersInterpreter[F] - override val repos: Repositories[F] = new RepositoriesInterpreter[F] - override val auth: Auth[F] = new AuthInterpreter[F] - override val gists: Gists[F] = new GistsInterpreter[F] - override val issues: Issues[F] = new IssuesInterpreter[F] - override val activities: Activities[F] = new ActivitiesInterpreter[F] - override val gitData: GitData[F] = new GitDataInterpreter[F] - override val pullRequests: PullRequests[F] = new PullRequestsInterpreter[F] - override val organizations: Organizations[F] = new OrganizationsInterpreter[F] - override val teams: Teams[F] = new TeamsInterpreter[F] - override val projects: Projects[F] = new ProjectsInterpreter[F] - override val search: Search[F] = new SearchInterpreter[F] - -} + accessToken: AccessToken[F] +) extends GithubAPIsV3[F](client, config, AccessHeader.from(accessToken)) object GithubAPIv3 { - + @deprecated("Use github4s.modules.GithubAPIsV3.noAuth instead", "0.33.0") def noAuth[F[_]: Concurrent](client: Client[F], config: GithubConfig): GithubAPIv3[F] = - new GithubAPIv3[F](client, config, StaticTokenAuthHeader.noToken) + new GithubAPIv3[F](client, config, StaticAccessToken.noToken) } diff --git a/github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala b/github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala new file mode 100644 index 00000000..f348004b --- /dev/null +++ b/github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala @@ -0,0 +1,53 @@ +/* + * Copyright 2016-2023 47 Degrees Open Source + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package github4s.modules + +import cats.effect.Concurrent +import github4s.GithubConfig +import github4s.algebras._ +import github4s.http.HttpClient +import github4s.interpreters._ +import org.http4s.client.Client + +class GithubAPIsV3[F[_]: Concurrent]( + client: Client[F], + config: GithubConfig, + accessHeader: AccessHeader[F] +) extends GithubAPIs[F] { + + implicit val httpClient: HttpClient[F] = new HttpClient[F](client, config, accessHeader) + + override val users: Users[F] = new UsersInterpreter[F] + override val repos: Repositories[F] = new RepositoriesInterpreter[F] + override val auth: Auth[F] = new AuthInterpreter[F] + override val gists: Gists[F] = new GistsInterpreter[F] + override val issues: Issues[F] = new IssuesInterpreter[F] + override val activities: Activities[F] = new ActivitiesInterpreter[F] + override val gitData: GitData[F] = new GitDataInterpreter[F] + override val pullRequests: PullRequests[F] = new PullRequestsInterpreter[F] + override val organizations: Organizations[F] = new OrganizationsInterpreter[F] + override val teams: Teams[F] = new TeamsInterpreter[F] + override val projects: Projects[F] = new ProjectsInterpreter[F] + override val search: Search[F] = new SearchInterpreter[F] + +} + +object GithubAPIsV3 { + + def noAuth[F[_]: Concurrent](client: Client[F], config: GithubConfig): GithubAPIsV3[F] = + new GithubAPIsV3[F](client, config, StaticAccessHeader.noHeader) +} diff --git a/project/plugins.sbt b/project/plugins.sbt index e50494ed..c42921f4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -16,3 +16,4 @@ addSbtPlugin("com.alejandrohdezma" % "sbt-remove-test-from-pom" % "0.1.0") addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.1") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.12.0") +addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.2") From c9f47d7c7efe62003813e6000cfbdfde268345be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Wed, 31 May 2023 15:35:43 +0200 Subject: [PATCH 3/7] Reoves unused import [skip ci] --- build.sbt | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sbt b/build.sbt index c4623b39..8eb9cc4c 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,4 @@ import ProjectPlugin.on -//import com.typesafe.tools.mima.MimaPlugin import com.typesafe.tools.mima.core._ Global / onChangedBuildSource := ReloadOnSourceChanges From fecf2f4a9fe2ea550c20fe795fd10ed0bca96fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Wed, 31 May 2023 16:22:28 +0200 Subject: [PATCH 4/7] Changes for improving compatibilty --- .../main/scala/github4s/GithubClient.scala | 2 +- .../main/scala/github4s/http/HttpClient.scala | 18 ++++- .../scala/github4s/modules/GithubAPIsV3.scala | 2 +- .../github4s/integration/ActivitiesSpec.scala | 28 ++++---- .../scala/github4s/integration/AuthSpec.scala | 6 +- .../github4s/integration/GitDataSpec.scala | 18 ++--- .../github4s/integration/IssuesSpec.scala | 48 ++++++------- .../integration/OrganizationsSpec.scala | 10 +-- .../github4s/integration/ProjectsSpec.scala | 20 +++--- .../integration/PullRequestsSpec.scala | 42 +++++------ .../github4s/integration/ReposSpec.scala | 69 ++++++++++--------- .../github4s/integration/SearchSpec.scala | 8 +-- .../github4s/integration/TeamsSpec.scala | 6 +- .../github4s/integration/UsersSpec.scala | 16 ++--- .../github4s/utils/BaseIntegrationSpec.scala | 24 +++---- .../test/scala/github4s/utils/BaseSpec.scala | 14 ++-- 16 files changed, 172 insertions(+), 159 deletions(-) diff --git a/github4s/shared/src/main/scala/github4s/GithubClient.scala b/github4s/shared/src/main/scala/github4s/GithubClient.scala index 8a239c69..49b0c045 100644 --- a/github4s/shared/src/main/scala/github4s/GithubClient.scala +++ b/github4s/shared/src/main/scala/github4s/GithubClient.scala @@ -52,7 +52,7 @@ object GithubClient { )(implicit config: GithubConfig): GithubAPIs[F] = new GithubClient[F](client, AccessHeader.from(new StaticAccessToken(accessToken))) - def withAuthHeader[F[_]: Concurrent]( + def apply[F[_]: Concurrent]( client: Client[F], authHeader: AccessHeader[F] )(implicit config: GithubConfig): GithubAPIs[F] = diff --git a/github4s/shared/src/main/scala/github4s/http/HttpClient.scala b/github4s/shared/src/main/scala/github4s/http/HttpClient.scala index ce44b419..32c9e19f 100644 --- a/github4s/shared/src/main/scala/github4s/http/HttpClient.scala +++ b/github4s/shared/src/main/scala/github4s/http/HttpClient.scala @@ -22,7 +22,7 @@ import cats.effect.kernel.Concurrent import cats.syntax.all._ import github4s.GHError._ import github4s._ -import github4s.algebras.AccessHeader +import github4s.algebras.{AccessHeader, AccessToken} import github4s.domain.Pagination import github4s.http.Http4sSyntax._ import io.circe.{Decoder, Encoder} @@ -31,7 +31,7 @@ import org.http4s.circe.jsonOf import org.http4s.client.Client import org.http4s._ -class HttpClient[F[_]: Concurrent]( +class HttpClient[F[_]: Concurrent] private ( client: Client[F], val config: GithubConfig, accessHeader: AccessHeader[F] @@ -231,4 +231,18 @@ object HttpClient { private def responseBody[F[_]: Concurrent](response: Response[F]): F[String] = response.bodyText.compile.foldMonoid + + def apply[F[_]: Concurrent]( + client: Client[F], + config: GithubConfig, + accessToken: AccessToken[F] + ): HttpClient[F] = + new HttpClient[F](client, config, AccessHeader.from(accessToken)) + + def apply[F[_]: Concurrent]( + client: Client[F], + config: GithubConfig, + accessHeader: AccessHeader[F] + ): HttpClient[F] = + new HttpClient[F](client, config, accessHeader) } diff --git a/github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala b/github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala index f348004b..550eaf1e 100644 --- a/github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala +++ b/github4s/shared/src/main/scala/github4s/modules/GithubAPIsV3.scala @@ -29,7 +29,7 @@ class GithubAPIsV3[F[_]: Concurrent]( accessHeader: AccessHeader[F] ) extends GithubAPIs[F] { - implicit val httpClient: HttpClient[F] = new HttpClient[F](client, config, accessHeader) + implicit val httpClient: HttpClient[F] = HttpClient[F](client, config, accessHeader) override val users: Users[F] = new UsersInterpreter[F] override val repos: Repositories[F] = new RepositoriesInterpreter[F] diff --git a/github4s/shared/src/test/scala/github4s/integration/ActivitiesSpec.scala b/github4s/shared/src/test/scala/github4s/integration/ActivitiesSpec.scala index b4c8beac..3b8c9a67 100644 --- a/github4s/shared/src/test/scala/github4s/integration/ActivitiesSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/ActivitiesSpec.scala @@ -18,7 +18,7 @@ package github4s.integration import cats.effect.IO import github4s.GHError.NotFoundError -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -27,7 +27,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { "Activity >> Set a thread subscription" should "return expected response when a valid thread id is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .setThreadSub(validThreadId, true, false, headerUserAgent) } .unsafeRunSync() @@ -39,7 +39,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return error when an invalid thread id is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .setThreadSub(invalidThreadId, true, false, headerUserAgent) } .unsafeRunSync() @@ -51,7 +51,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { "Activity >> ListStargazers" should "return the expected list of starrers for valid data" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listStargazers(validRepoOwner, validRepoName, false, None, headerUserAgent) } .unsafeRunSync() @@ -69,7 +69,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return the expected list of starrers for valid data with dates if timeline" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listStargazers(validRepoOwner, validRepoName, true, None, headerUserAgent) } .unsafeRunSync() @@ -87,7 +87,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return error for invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listStargazers(invalidRepoName, validRepoName, false, None, headerUserAgent) } .unsafeRunSync() @@ -99,7 +99,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { "Activity >> ListStarredRepositories" should "return the expected list of starred repos" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listStarredRepositories(validUsername, false, headers = headerUserAgent) } .unsafeRunSync() @@ -117,7 +117,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return the expected list of starred repos with dates if timeline" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listStarredRepositories(validUsername, true, headers = headerUserAgent) } .unsafeRunSync() @@ -135,7 +135,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return error for invalid username" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listStarredRepositories(invalidUsername, false, headers = headerUserAgent) } .unsafeRunSync() @@ -147,7 +147,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { "Activity >> PublicOrganizationEvents" should "return the expected list of events" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listPublicOrganizationEvents(validOrganizationName, headers = headerUserAgent) } .unsafeRunSync() @@ -167,7 +167,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return error for invalid organization" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listPublicOrganizationEvents(invalidOrganizationName, headers = headerUserAgent) } .unsafeRunSync() @@ -179,7 +179,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { "Activity >> PublicRepositoryEvents" should "return the expected list of events" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listPublicRepositoryEvents(validRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -199,7 +199,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return error for invalid repository owner" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listPublicRepositoryEvents(invalidRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -211,7 +211,7 @@ trait ActivitiesSpec extends BaseIntegrationSpec { it should "return error for invalid repository name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).activities + GithubClient[IO](client, accessToken).activities .listPublicRepositoryEvents(validRepoOwner, invalidRepoName, headers = headerUserAgent) } .unsafeRunSync() diff --git a/github4s/shared/src/test/scala/github4s/integration/AuthSpec.scala b/github4s/shared/src/test/scala/github4s/integration/AuthSpec.scala index d33ad41b..8aceceb7 100644 --- a/github4s/shared/src/test/scala/github4s/integration/AuthSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/AuthSpec.scala @@ -17,7 +17,7 @@ package github4s.integration import cats.effect.IO -import github4s.{GHError, Github} +import github4s.{GHError, GithubClient} import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -26,7 +26,7 @@ trait AuthSpec extends BaseIntegrationSpec { "Auth >> AuthorizeUrl" should "return the expected URL for valid username" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client).auth + GithubClient[IO](client).auth .authorizeUrl(validClientId, validRedirectUri, validScopes) } .unsafeRunSync() @@ -38,7 +38,7 @@ trait AuthSpec extends BaseIntegrationSpec { "Auth >> GetAccessToken" should "return error on Left for invalid code value" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client).auth + GithubClient[IO](client).auth .getAccessToken( validClientId, invalidClientSecret, diff --git a/github4s/shared/src/test/scala/github4s/integration/GitDataSpec.scala b/github4s/shared/src/test/scala/github4s/integration/GitDataSpec.scala index 3f11f9c9..929bcb76 100644 --- a/github4s/shared/src/test/scala/github4s/integration/GitDataSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/GitDataSpec.scala @@ -19,7 +19,7 @@ package github4s.integration import cats.data.NonEmptyList import cats.effect.IO import github4s.GHError.NotFoundError -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -28,7 +28,7 @@ trait GitDataSpec extends BaseIntegrationSpec { "GitData >> GetReference" should "return a list of references" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getReference(validRepoOwner, validRepoName, "heads", None, headerUserAgent) } .unsafeRunSync() @@ -40,7 +40,7 @@ trait GitDataSpec extends BaseIntegrationSpec { it should "return at least one reference" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getReference(validRepoOwner, validRepoName, validRefSingle, None, headerUserAgent) } .unsafeRunSync() @@ -52,7 +52,7 @@ trait GitDataSpec extends BaseIntegrationSpec { it should "return an error when an invalid repository name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getReference(validRepoOwner, invalidRepoName, validRefSingle, None, headerUserAgent) } .unsafeRunSync() @@ -64,7 +64,7 @@ trait GitDataSpec extends BaseIntegrationSpec { "GitData >> GetCommit" should "return one commit" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getCommit(validRepoOwner, validRepoName, validCommitSha, headerUserAgent) } .unsafeRunSync() @@ -76,7 +76,7 @@ trait GitDataSpec extends BaseIntegrationSpec { it should "return an error when an invalid repository name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getCommit(validRepoOwner, invalidRepoName, validCommitSha, headerUserAgent) } .unsafeRunSync() @@ -88,7 +88,7 @@ trait GitDataSpec extends BaseIntegrationSpec { "GitData >> GetTree" should "return the file tree non-recursively" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getTree( validRepoOwner, validRepoName, @@ -112,7 +112,7 @@ trait GitDataSpec extends BaseIntegrationSpec { it should "return the file tree recursively" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getTree(validRepoOwner, validRepoName, validCommitSha, recursive = true, headerUserAgent) } .unsafeRunSync() @@ -135,7 +135,7 @@ trait GitDataSpec extends BaseIntegrationSpec { it should "return an error when an invalid repository name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).gitData + GithubClient[IO](client, accessToken).gitData .getTree( validRepoOwner, invalidRepoName, diff --git a/github4s/shared/src/test/scala/github4s/integration/IssuesSpec.scala b/github4s/shared/src/test/scala/github4s/integration/IssuesSpec.scala index e5d4d293..cba13ee0 100644 --- a/github4s/shared/src/test/scala/github4s/integration/IssuesSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/IssuesSpec.scala @@ -18,7 +18,7 @@ package github4s.integration import cats.effect.IO import github4s.GHError.NotFoundError -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -27,7 +27,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> List" should "return a list of issues" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listIssues(validRepoOwner, validRepoName, None, headerUserAgent) } .unsafeRunSync() @@ -39,7 +39,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> Get" should "return an issue which is a PR" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .getIssue(validRepoOwner, validRepoName, validPullRequestNumber, headerUserAgent) } .unsafeRunSync() @@ -51,7 +51,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> Search" should "return at least one issue for a valid query" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .searchIssues(validSearchQuery, validSearchParams, None, headerUserAgent) } .unsafeRunSync() @@ -69,7 +69,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "not regress github #569" taggedAs Integration in { clientResource .use { client => - Github[IO](client, accessToken).issues.searchIssues( + GithubClient[IO](client, accessToken).issues.searchIssues( "", List( OwnerParamInRepository("47degrees/github4s"), @@ -87,7 +87,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return an empty result for a non existent query string" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .searchIssues(nonExistentSearchQuery, validSearchParams, None, headerUserAgent) } .unsafeRunSync() @@ -105,7 +105,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> Edit" should "edit the specified issue" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .editIssue( validRepoOwner, validRepoName, @@ -134,7 +134,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> ListLabels" should "return a list of labels" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listLabels(validRepoOwner, validRepoName, validIssueNumber, None, headerUserAgent) } .unsafeRunSync() @@ -146,7 +146,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> listLabelsRepository" should "return a list of labels" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listLabelsRepository(validRepoOwner, validRepoName, None, headerUserAgent) } .unsafeRunSync() @@ -158,7 +158,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return error for an invalid repo owner" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listLabelsRepository(invalidRepoOwner, validRepoName, None, headerUserAgent) } .unsafeRunSync() @@ -170,7 +170,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return error for an invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listLabelsRepository(validRepoOwner, invalidRepoName, None, headerUserAgent) } .unsafeRunSync() @@ -182,7 +182,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> RemoveLabel" should "return a list of removed labels" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .removeLabel( validRepoOwner, validRepoName, @@ -200,7 +200,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> CreateLabel" should "return a created label" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .createLabel( validRepoOwner, validRepoName, @@ -217,7 +217,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> UpdateLabel" should "return a updated label" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .updateLabel( validRepoOwner, validRepoName, @@ -234,7 +234,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> DeleteLabel" should "return a valid status code" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .deleteLabel( validRepoOwner, validRepoName, @@ -250,7 +250,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "Issues >> AddLabels" should "return a list of labels" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .addLabels( validRepoOwner, validRepoName, @@ -268,7 +268,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "GHIssues >> ListAvailableAssignees" should "return a list of users" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listAvailableAssignees(validRepoOwner, validRepoName, None, headerUserAgent) } .unsafeRunSync() @@ -280,7 +280,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return error for an invalid repo owner" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listAvailableAssignees(invalidRepoOwner, validRepoName, None, headerUserAgent) } .unsafeRunSync() @@ -292,7 +292,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return error for an invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listAvailableAssignees(validRepoOwner, invalidRepoName, None, headerUserAgent) } .unsafeRunSync() @@ -304,7 +304,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "GHIssues >> ListMilestones" should "return a list of milestones" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listMilestones( validRepoOwner, validRepoName, @@ -324,7 +324,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return error for an invalid repo owner" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listMilestones( invalidRepoOwner, validRepoName, @@ -344,7 +344,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return error for an invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .listMilestones(validRepoOwner, invalidRepoName, None, None, None, None, headerUserAgent) } .unsafeRunSync() @@ -356,7 +356,7 @@ trait IssuesSpec extends BaseIntegrationSpec { "GHIssues >> GetMilestone" should "return a milestone for a valid number" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .getMilestone( validRepoOwner, validRepoName, @@ -373,7 +373,7 @@ trait IssuesSpec extends BaseIntegrationSpec { it should "return error for an invalid number" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).issues + GithubClient[IO](client, accessToken).issues .getMilestone( validRepoOwner, validRepoName, diff --git a/github4s/shared/src/test/scala/github4s/integration/OrganizationsSpec.scala b/github4s/shared/src/test/scala/github4s/integration/OrganizationsSpec.scala index 991b2e93..d850d1da 100644 --- a/github4s/shared/src/test/scala/github4s/integration/OrganizationsSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/OrganizationsSpec.scala @@ -18,7 +18,7 @@ package github4s.integration import cats.effect.IO import github4s.GHError.NotFoundError -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -27,7 +27,7 @@ trait OrganizationsSpec extends BaseIntegrationSpec { "Organization >> ListMembers" should "return the expected list of users" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).organizations + GithubClient[IO](client, accessToken).organizations .listMembers(validRepoOwner, headers = headerUserAgent) } .unsafeRunSync() @@ -39,7 +39,7 @@ trait OrganizationsSpec extends BaseIntegrationSpec { it should "return error for an invalid org" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).organizations + GithubClient[IO](client, accessToken).organizations .listMembers(invalidUsername, headers = headerUserAgent) } .unsafeRunSync() @@ -51,7 +51,7 @@ trait OrganizationsSpec extends BaseIntegrationSpec { "Organization >> ListOutsideCollaborators" should "return expected list of users" ignore { val response = clientResource .use { client => - Github[IO](client, accessToken).organizations + GithubClient[IO](client, accessToken).organizations .listOutsideCollaborators(validOrganizationName, headers = headerUserAgent) } .unsafeRunSync() @@ -63,7 +63,7 @@ trait OrganizationsSpec extends BaseIntegrationSpec { it should "return error for an invalid org" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).organizations + GithubClient[IO](client, accessToken).organizations .listOutsideCollaborators(invalidOrganizationName, headers = headerUserAgent) } .unsafeRunSync() diff --git a/github4s/shared/src/test/scala/github4s/integration/ProjectsSpec.scala b/github4s/shared/src/test/scala/github4s/integration/ProjectsSpec.scala index f8ca44e0..e371fd62 100644 --- a/github4s/shared/src/test/scala/github4s/integration/ProjectsSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/ProjectsSpec.scala @@ -18,7 +18,7 @@ package github4s.integration import cats.effect.IO import github4s.GHError.NotFoundError -import github4s.Github +import github4s.GithubClient import github4s.domain.{Card, Column, Project} import github4s.utils.{BaseIntegrationSpec, Integration} @@ -27,7 +27,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { "Project >> ListProjects" should "return the expected projects when a valid org is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listProjects(validRepoOwner, headers = headerUserAgent ++ headerAccept) } .unsafeRunSync() @@ -39,7 +39,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { it should "return error when an invalid org is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listProjects(invalidRepoName, headers = headerUserAgent ++ headerAccept) } .unsafeRunSync() @@ -51,7 +51,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { "Project >> ListProjectsRepository" should "return the expected projects when a valid owner and repo are provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listProjectsRepository( validRepoOwner, validRepoName, @@ -67,7 +67,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { it should "return error when an invalid repo is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listProjectsRepository( validRepoOwner, invalidRepoName, @@ -83,7 +83,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { it should "return error when an invalid owner is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listProjectsRepository( invalidRepoOwner, validRepoName, @@ -99,7 +99,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { "Project >> ListColumns" should "return the expected column when a valid project id is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listColumns(validProjectId, headers = headerUserAgent ++ headerAccept) } .unsafeRunSync() @@ -111,7 +111,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { it should "return error when an invalid project id is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listColumns(invalidProjectId, headers = headerUserAgent ++ headerAccept) } .unsafeRunSync() @@ -123,7 +123,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { "Project >> ListCards" should "return the expected cards when a valid column id is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listCards(validColumnId, headers = headerUserAgent ++ headerAccept) } .unsafeRunSync() @@ -135,7 +135,7 @@ trait ProjectsSpec extends BaseIntegrationSpec { it should "return error when an invalid column id is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).projects + GithubClient[IO](client, accessToken).projects .listCards(invalidColumnId, headers = headerUserAgent ++ headerAccept) } .unsafeRunSync() diff --git a/github4s/shared/src/test/scala/github4s/integration/PullRequestsSpec.scala b/github4s/shared/src/test/scala/github4s/integration/PullRequestsSpec.scala index 8f7033cf..bcbef5f9 100644 --- a/github4s/shared/src/test/scala/github4s/integration/PullRequestsSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/PullRequestsSpec.scala @@ -18,7 +18,7 @@ package github4s.integration import cats.effect.IO import github4s.GHError.{JsonParsingError, NotFoundError} -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -27,7 +27,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> Get" should "return a right response when a valid pr number is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .getPullRequest( validRepoOwner, validRepoName, @@ -44,7 +44,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return an error when a valid issue number is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .getPullRequest( validRepoOwner, validRepoName, @@ -61,7 +61,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return an error when an invalid repo name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .getPullRequest( validRepoOwner, invalidRepoName, @@ -78,7 +78,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> List" should "return a right response when valid repo is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listPullRequests( validRepoOwner, validRepoName, @@ -95,7 +95,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return a right response when a valid repo is provided but not all pull requests have body" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listPullRequests( "lloydmeta", "gh-test-repo", @@ -112,7 +112,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return a non empty list when valid repo and some filters are provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listPullRequests( validRepoOwner, validRepoName, @@ -129,7 +129,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return error when an invalid repo name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listPullRequests(validRepoOwner, invalidRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -141,7 +141,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> ListFiles" should "return a right response when a valid repo is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listFiles( validRepoOwner, validRepoName, @@ -158,7 +158,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return a right response when a valid repo is provided and not all files have 'patch'" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listFiles("scala", "scala", 4877, headers = headerUserAgent) } .unsafeRunSync() @@ -170,7 +170,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return error when an invalid repo name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listFiles( validRepoOwner, invalidRepoName, @@ -187,7 +187,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> ListReviews" should "return a right response when a valid pr is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listReviews( validRepoOwner, validRepoName, @@ -204,7 +204,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return error when an invalid repo name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listReviews( validRepoOwner, invalidRepoName, @@ -221,7 +221,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> GetReview" should "return a right response when a valid pr review is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .getReview( validRepoOwner, validRepoName, @@ -239,7 +239,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return error when an invalid repo name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .getReview( validRepoOwner, invalidRepoName, @@ -257,7 +257,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> CreateReview" should "return a created review" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .createReview( validRepoOwner, validRepoName, @@ -281,7 +281,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { it should "return an error when invalid review data was passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .createReview( validRepoOwner, validRepoName, @@ -299,7 +299,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> Add/List/Remove Reviewers" should "return the proper reviewers" taggedAs Integration ignore { val addReviewersResponse = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .addReviewers( validRepoOwner, validRepoName, @@ -318,7 +318,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { val getReviewersResponse = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .listReviewers( validRepoOwner, validRepoName, @@ -339,7 +339,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { val removeReviewersResponse = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .removeReviewers( validRepoOwner, validRepoName, @@ -360,7 +360,7 @@ trait PullRequestsSpec extends BaseIntegrationSpec { "PullRequests >> Update Branch" should "merge target branch's head into selected" taggedAs Integration ignore { val response = clientResource .use { client => - Github[IO](client, accessToken).pullRequests + GithubClient[IO](client, accessToken).pullRequests .updateBranch( validRepoOwner, validRepoName, diff --git a/github4s/shared/src/test/scala/github4s/integration/ReposSpec.scala b/github4s/shared/src/test/scala/github4s/integration/ReposSpec.scala index e01750c2..9790f67d 100644 --- a/github4s/shared/src/test/scala/github4s/integration/ReposSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/ReposSpec.scala @@ -19,18 +19,19 @@ package github4s.integration import cats.data.NonEmptyList import cats.effect.{IO, Resource} import cats.implicits._ +import github4s.{GHResponse, GithubClient} import github4s.GHError.{NotFoundError, UnauthorizedError} +import github4s.algebras.GithubAPIs import github4s.domain.RepoUrlKeys.CommitComparisonResponse import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} -import github4s.{GHResponse, Github} trait ReposSpec extends BaseIntegrationSpec { "Repos >> Get" should "return the expected name when a valid repo is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .get(validRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -42,7 +43,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error when an invalid repo name is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .get(validRepoOwner, invalidRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -54,7 +55,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListReleases" should "return the expected repos when a valid org is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listReleases(validRepoOwner, validRepoName, None, headers = headerUserAgent) } .unsafeRunSync() @@ -66,7 +67,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> getRelease" should "return the expected repos when a valid org is provided" taggedAs Integration in { val test = clientResource.use { client => - val gh: Github[IO] = Github[IO](client, accessToken) + val gh: GithubAPIs[IO] = GithubClient[IO](client, accessToken) for { @@ -97,7 +98,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> LatestRelease" should "return the expected repos when a valid org is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .latestRelease(validRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -109,7 +110,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListOrgRepos" should "return the expected repos when a valid org is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listOrgRepos(validRepoOwner, headers = headerUserAgent) } .unsafeRunSync() @@ -121,7 +122,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error when an invalid org is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listOrgRepos(invalidRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -133,7 +134,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListUserRepos" should "return the expected repos when a valid user is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listUserRepos(validUsername, headers = headerUserAgent) } .unsafeRunSync() @@ -145,7 +146,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error when an invalid user is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listUserRepos(invalidUsername, headers = headerUserAgent) } .unsafeRunSync() @@ -157,7 +158,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> GetContents" should "return the expected contents when valid path is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .getContents(validRepoOwner, validRepoName, validFilePath, headers = headerUserAgent) } .unsafeRunSync() @@ -170,7 +171,7 @@ trait ReposSpec extends BaseIntegrationSpec { val blobResponseFileContent = for { client <- clientResource - res = Github[IO](client, accessToken) + res = GithubClient[IO](client, accessToken) fileContentsIO = res.repos.getContents( owner = validRepoOwner, @@ -207,7 +208,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error when an invalid path is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .getContents(validRepoOwner, validRepoName, invalidFilePath, headers = headerUserAgent) } .unsafeRunSync() @@ -219,7 +220,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListCommits" should "return the expected list of commits for valid data" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listCommits(validRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -231,7 +232,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error for invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listCommits(invalidRepoName, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -243,7 +244,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListBranches" should "return the expected list of branches for valid data" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listBranches(validRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -255,7 +256,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error for invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listBranches(invalidRepoName, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -267,7 +268,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListContributors" should "return the expected list of contributors for valid data" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listContributors(validRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -279,7 +280,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error for invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listContributors(invalidRepoName, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -291,7 +292,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListCollaborators" should "return the expected list of collaborators for valid data" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listCollaborators(validRepoOwner, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -303,7 +304,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error for invalid repo name" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listCollaborators(invalidRepoName, validRepoName, headers = headerUserAgent) } .unsafeRunSync() @@ -315,7 +316,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> UserIsCollaborator" should "return true when the user is a collaborator" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .userIsCollaborator( validRepoOwner, validRepoName, @@ -332,7 +333,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return false when the user is not a collaborator" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .userIsCollaborator( validRepoOwner, validRepoName, @@ -349,7 +350,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error when other errors occur" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, "invalid-access-token".some).repos + GithubClient[IO](client, "invalid-access-token".some).repos .userIsCollaborator( validRepoOwner, validRepoName, @@ -366,7 +367,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> GetRepoPermissionForUser" should "return user repo permission" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .getRepoPermissionForUser( validRepoOwner, validRepoName, @@ -383,7 +384,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return error when invalid username is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .getRepoPermissionForUser( validRepoOwner, validRepoName, @@ -400,7 +401,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> GetStatus" should "return a combined status" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .getCombinedStatus( validRepoOwner, validRepoName, @@ -420,7 +421,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return an error when an invalid ref is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .getCombinedStatus(validRepoOwner, validRepoName, invalidRef, headers = headerUserAgent) } .unsafeRunSync() @@ -436,7 +437,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> ListStatus" should "return a non empty list when a valid ref is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listStatuses(validRepoOwner, validRepoName, validCommitSha, headers = headerUserAgent) } .unsafeRunSync() @@ -448,7 +449,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return an error when an invalid ref is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .listStatuses(validRepoOwner, validRepoName, invalidRef, headers = headerUserAgent) } .unsafeRunSync() @@ -461,7 +462,7 @@ trait ReposSpec extends BaseIntegrationSpec { val params = List(LanguageParam("scss"), TopicParam("jekyll")) val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .searchRepos("sbt-microsites", params, None, headerUserAgent) } .unsafeRunSync() @@ -479,7 +480,7 @@ trait ReposSpec extends BaseIntegrationSpec { "Repos >> Compare" should "compare against the base" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .compareCommits(validRepoOwner, validRepoName, validCommitSha, validBase) } .unsafeRunSync() @@ -497,7 +498,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "successfully return results when a valid repo is provided using / syntax" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .searchRepos(s"$validRepoOwner/$validRepoName", Nil) } .unsafeRunSync() @@ -514,7 +515,7 @@ trait ReposSpec extends BaseIntegrationSpec { it should "return an empty result for a non existent query string" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).repos + GithubClient[IO](client, accessToken).repos .searchRepos(nonExistentSearchQuery, validSearchParams, None, headerUserAgent) } .unsafeRunSync() diff --git a/github4s/shared/src/test/scala/github4s/integration/SearchSpec.scala b/github4s/shared/src/test/scala/github4s/integration/SearchSpec.scala index 07d33ca1..8ff07278 100644 --- a/github4s/shared/src/test/scala/github4s/integration/SearchSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/SearchSpec.scala @@ -17,7 +17,7 @@ package github4s.integration import cats.effect.IO -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -28,7 +28,7 @@ trait SearchSpec extends BaseIntegrationSpec { it should "return zero match for a non existent search query" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).search + GithubClient[IO](client, accessToken).search .searchCode( query = nonExistentSearchQuery, searchParams = List( @@ -53,7 +53,7 @@ trait SearchSpec extends BaseIntegrationSpec { it should "return at least one match for a valid query" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).search + GithubClient[IO](client, accessToken).search .searchCode( query = "github", searchParams = List( @@ -78,7 +78,7 @@ trait SearchSpec extends BaseIntegrationSpec { it should "return at least one match for a valid query with text matches enabled" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).search + GithubClient[IO](client, accessToken).search .searchCode( query = "github", searchParams = List( diff --git a/github4s/shared/src/test/scala/github4s/integration/TeamsSpec.scala b/github4s/shared/src/test/scala/github4s/integration/TeamsSpec.scala index ea6ad139..dff22d58 100644 --- a/github4s/shared/src/test/scala/github4s/integration/TeamsSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/TeamsSpec.scala @@ -18,7 +18,7 @@ package github4s.integration import cats.effect.IO import github4s.GHError.NotFoundError -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -26,7 +26,7 @@ trait TeamsSpec extends BaseIntegrationSpec { "Team >> ListTeams" should "return the expected teams when a valid org is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).teams + GithubClient[IO](client, accessToken).teams .listTeams(validRepoOwner, headers = headerUserAgent) } .unsafeRunSync() @@ -38,7 +38,7 @@ trait TeamsSpec extends BaseIntegrationSpec { it should "return error when an invalid org is passed" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).teams + GithubClient[IO](client, accessToken).teams .listTeams(invalidRepoName, headers = headerUserAgent) } .unsafeRunSync() diff --git a/github4s/shared/src/test/scala/github4s/integration/UsersSpec.scala b/github4s/shared/src/test/scala/github4s/integration/UsersSpec.scala index 397735df..b2f35a15 100644 --- a/github4s/shared/src/test/scala/github4s/integration/UsersSpec.scala +++ b/github4s/shared/src/test/scala/github4s/integration/UsersSpec.scala @@ -18,7 +18,7 @@ package github4s.integration import cats.effect.IO import github4s.GHError -import github4s.Github +import github4s.GithubClient import github4s.domain._ import github4s.utils.{BaseIntegrationSpec, Integration} @@ -27,7 +27,7 @@ trait UsersSpec extends BaseIntegrationSpec { "Users >> Get" should "return the expected login for a valid username" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).users + GithubClient[IO](client, accessToken).users .get(validUsername, headerUserAgent) } .unsafeRunSync() @@ -39,7 +39,7 @@ trait UsersSpec extends BaseIntegrationSpec { it should "return error on Left for invalid username" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).users + GithubClient[IO](client, accessToken).users .get(invalidUsername, headerUserAgent) } .unsafeRunSync() @@ -51,7 +51,7 @@ trait UsersSpec extends BaseIntegrationSpec { "Users >> GetAuth" should "return error on Left when no accessToken is provided" taggedAs Integration in { val response = clientResource - .use(client => Github[IO](client).users.getAuth(headerUserAgent)) + .use(client => GithubClient[IO](client).users.getAuth(headerUserAgent)) .unsafeRunSync() testIsLeft[GHError.UnauthorizedError, User](response) @@ -61,7 +61,7 @@ trait UsersSpec extends BaseIntegrationSpec { "Users >> GetUsers" should "return users for a valid since value" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).users + GithubClient[IO](client, accessToken).users .getUsers(validSinceInt, None, headerUserAgent) } .unsafeRunSync() @@ -73,7 +73,7 @@ trait UsersSpec extends BaseIntegrationSpec { it should "return an empty list when a invalid since value is provided" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).users + GithubClient[IO](client, accessToken).users .getUsers(invalidSinceInt, None, headerUserAgent) } .unsafeRunSync() @@ -85,7 +85,7 @@ trait UsersSpec extends BaseIntegrationSpec { "Users >> GetFollowing" should "return the expected following list for a valid username" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).users + GithubClient[IO](client, accessToken).users .getFollowing(validUsername, None, headerUserAgent) } .unsafeRunSync() @@ -97,7 +97,7 @@ trait UsersSpec extends BaseIntegrationSpec { it should "return error on Left for invalid username" taggedAs Integration in { val response = clientResource .use { client => - Github[IO](client, accessToken).users + GithubClient[IO](client, accessToken).users .getFollowing(invalidUsername, None, headerUserAgent) } .unsafeRunSync() diff --git a/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala b/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala index 626a1c04..24ebf0eb 100644 --- a/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala +++ b/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala @@ -28,19 +28,17 @@ import org.scalatest.{Assertion, Ignore, Inspectors, Tag} import scala.concurrent.ExecutionContext import scala.reflect.ClassTag -class IntegrationSpec - extends BaseIntegrationSpec - with ActivitiesSpec - with AuthSpec - with GitDataSpec - with IssuesSpec - with OrganizationsSpec - with PullRequestsSpec - with ReposSpec - with UsersSpec - with TeamsSpec - with ProjectsSpec - with SearchSpec +class IntegrationSpec extends BaseIntegrationSpec with ActivitiesSpec +// with AuthSpec +// with GitDataSpec +// with IssuesSpec +// with OrganizationsSpec +// with PullRequestsSpec +// with ReposSpec +// with UsersSpec +// with TeamsSpec +// with ProjectsSpec +// with SearchSpec object Integration extends Tag( diff --git a/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala b/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala index 768c43d8..dbd16f08 100644 --- a/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala +++ b/github4s/shared/src/test/scala/github4s/utils/BaseSpec.scala @@ -18,7 +18,7 @@ package github4s.utils import cats.effect.{unsafe, IO} import github4s.http.HttpClient -import github4s.interpreters.StaticTokenAuthHeader +import github4s.interpreters.StaticAccessToken import github4s.{GithubConfig, IOAssertions} import io.circe.{Decoder, Encoder} import org.http4s.client.Client @@ -61,7 +61,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.params == params => response.map(body => Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) + HttpClient(httpClientMock, dummyConfig, new StaticAccessToken[IO](sampleToken)) } protected def httpClientMockGetWithoutResponse( @@ -76,7 +76,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.headers == Headers(userAgent) => response.map(_ => Response[IO](responseStatus).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) + HttpClient(httpClientMock, dummyConfig, new StaticAccessToken[IO](sampleToken)) } protected def httpClientMockPost[In: Decoder, Out: Encoder]( @@ -101,7 +101,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio response.map(body => Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) + HttpClient(httpClientMock, dummyConfig, new StaticAccessToken[IO](sampleToken)) } protected def httpClientMockPatch[In: Decoder, Out: Encoder]( @@ -135,7 +135,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.headers == Headers(userAgent) => response.as(Response[IO](responseStatus).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) + HttpClient(httpClientMock, dummyConfig, new StaticAccessToken[IO](sampleToken)) } protected def httpClientMockDeleteWithResponse[Out: Encoder]( @@ -150,7 +150,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio req.headers == Headers(userAgent) => response.map(body => Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders)) } - new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) + HttpClient(httpClientMock, dummyConfig, new StaticAccessToken[IO](sampleToken)) } protected def httpClientMockDeleteWithBody[In: Decoder, Out: Encoder]( @@ -187,7 +187,7 @@ trait BaseSpec extends AsyncFlatSpec with Matchers with TestData with IOAssertio Response[IO](responseStatus).withEntity(body).putHeaders(respHeaders) ) } - new HttpClient(httpClientMock, dummyConfig, StaticTokenAuthHeader[IO](sampleToken)) + HttpClient(httpClientMock, dummyConfig, new StaticAccessToken[IO](sampleToken)) } private def httpMock(pf: PartialFunction[Request[IO], IO[Response[IO]]]) = From 5213457bcb58b1b4c69e031f2cde37c7c380f637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Thu, 1 Jun 2023 09:48:57 +0200 Subject: [PATCH 5/7] Fixes auth --- .../shared/src/main/scala/github4s/algebras/AccessHeader.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala b/github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala index 797b3d8e..7c648859 100644 --- a/github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala +++ b/github4s/shared/src/main/scala/github4s/algebras/AccessHeader.scala @@ -10,7 +10,7 @@ object AccessHeader { def from[F[_]](accessToken: AccessToken[F]): AccessHeader[F] = new AccessHeader[F] { override def withAccessHeader[T](f: Map[String, String] => F[GHResponse[T]]): F[GHResponse[T]] = accessToken.withAccessToken { token => - f(Map("Authorization" -> s"token $token")) + f(token.fold(Map.empty[String, String])(t => Map("Authorization" -> s"token $t"))) } } } From 647f693fa43b72f15981154778dca618a4ff6088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Thu, 1 Jun 2023 13:02:43 +0200 Subject: [PATCH 6/7] Removes comment block --- .../github4s/utils/BaseIntegrationSpec.scala | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala b/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala index 24ebf0eb..3d9a4527 100644 --- a/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala +++ b/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala @@ -29,16 +29,16 @@ import scala.concurrent.ExecutionContext import scala.reflect.ClassTag class IntegrationSpec extends BaseIntegrationSpec with ActivitiesSpec -// with AuthSpec -// with GitDataSpec -// with IssuesSpec -// with OrganizationsSpec -// with PullRequestsSpec -// with ReposSpec -// with UsersSpec -// with TeamsSpec -// with ProjectsSpec -// with SearchSpec + with AuthSpec + with GitDataSpec + with IssuesSpec + with OrganizationsSpec + with PullRequestsSpec + with ReposSpec + with UsersSpec + with TeamsSpec + with ProjectsSpec + with SearchSpec object Integration extends Tag( From 7ca6b9a678988a7cfc6e6eb4a74a22ba21fa2087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Thu, 1 Jun 2023 14:58:33 +0200 Subject: [PATCH 7/7] scalafmt --- .../src/test/scala/github4s/utils/BaseIntegrationSpec.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala b/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala index 3d9a4527..626a1c04 100644 --- a/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala +++ b/github4s/shared/src/test/scala/github4s/utils/BaseIntegrationSpec.scala @@ -28,7 +28,9 @@ import org.scalatest.{Assertion, Ignore, Inspectors, Tag} import scala.concurrent.ExecutionContext import scala.reflect.ClassTag -class IntegrationSpec extends BaseIntegrationSpec with ActivitiesSpec +class IntegrationSpec + extends BaseIntegrationSpec + with ActivitiesSpec with AuthSpec with GitDataSpec with IssuesSpec