Skip to content

Commit 5849584

Browse files
bond15Rafa Paradela
andauthored
Tagless final refactor (#344)
* initial refactoring from free monad to tagless final * Added Algebras * Refactored HttpClient, temporarily bypassing HttpRequestBuilderExtension, added runtime implicits, added User alg interpretation * moving /free/domain to /taglessFinal/domain * Adding interpreters for algebras. Interpreters target the /api classes * reformatted/linted, remove ADTs from algebras, added more implicit runtime instnaces * updated algebra signatures to match existing api, removed accessToken as default param, added headers as default param * Modified intepreters to fit new algebra definitions and take accessToken as a default parameter * removing free monad implementation * updating GHWorkflow and Github * for Rafa review * pre merge * Updated F type constraint F[_]: Applicative -> F[_]: ConcurrentEffect * For Rafa comment, progress on replacing scalaj-http with http4s * For Rafa review and refactor * applied some refactoring to have clean layers * Adding toFutue and toId syntax for IO[A] * removing unit tests associated with deleted classes * For Rafa Review, unit tests * updating unit tests for interpreters * unit test linting * refactoring integration test to match new api usage * updating unit and integration test base spec * linting and updating scala version 2.13 and blaze client * fixing TestData for integration test * Updateding FakeResponses for Decoder testing * fix integration test, pull GITHUB4S_ACCESS_TOKEN from sys env * upgrades some models * Revert "upgrades some models" This reverts commit 4771d05 * fixes the unit tests * removes commented import * fixes the decoders issue for the new http client * proves the organization's members with the proper token * enables commented suites * ignores temporally a test because we are getting permission issues * Updating documentation, initial draft * Update contributing.md * fixing github doc links * cleaning interpreter imports, retarget issue for testing (123 -> 17) * remove old api tests * remove mock-server dependency, change http4s version * switching to compile-only check in documentation. mdoc:silent -> mdoc:compile-only * Address Ben F. PR comments * Address Lawrence's PR comments * Address Anna M. PR Comments * Address Ana G. PR comments * Address Juan Pedro PR comments * test remove label Co-authored-by: Rafa Paradela <rafa.p@47deg.com>
1 parent a776769 commit 5849584

111 files changed

Lines changed: 3084 additions & 11164 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.sbt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ lazy val github4s =
2121
)
2222
.settings(coreDeps: _*)
2323

24-
lazy val catsEffect =
25-
(project in file("cats-effect"))
26-
.settings(moduleName := "github4s-cats-effect")
27-
.settings(catsEffectDependencies: _*)
28-
.dependsOn(github4s)
2924

3025
/////////////////////
3126
//// ALL MODULES ////
3227
/////////////////////
3328

34-
lazy val allModules: Seq[ProjectReference] = Seq(github4s, catsEffect)
29+
lazy val allModules: Seq[ProjectReference] = Seq(github4s)
3530

3631
lazy val allModulesDeps: Seq[ClasspathDependency] =
3732
allModules.map(ClasspathDependency(_, None))

cats-effect/src/main/scala/github4s/cats/effect/implicits.scala

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

cats-effect/src/test/scala/github4s/cats/effect/CatsEffectSpec.scala

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

docs/docs/activity.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@ with Github4s, you can interact with:
1515
- [List stargazers](#list-stargazers)
1616
- [List starred repositories](#list-starred-repositories)
1717

18-
The following examples assume the following imports and token:
18+
The following examples use `cats.effect.IO` and assume the following imports and token:
1919

2020
```scala mdoc:silent
2121
import github4s.Github
22-
import github4s.Github._
23-
import github4s.implicits._
22+
import github4s.GithubIOSyntax._
23+
import cats.effect.IO
24+
import scala.concurrent.ExecutionContext.Implicits.global
2425

26+
implicit val IOContextShift = IO.contextShift(global)
2527
val accessToken = sys.env.get("GITHUB4S_ACCESS_TOKEN")
2628
```
2729

28-
They also make use of `cats.Id`, but any type container implementing `MonadError[M, Throwable]` will do.
2930

30-
Support for `cats.Id`, `cats.Eval`, and `Future` are
31-
provided out of the box when importing `github4s.implicits._`.
31+
They also make use of `cats.Id`, but any type container `F` implementing `ConcurrentEffect` will do.
32+
33+
LiftIO syntax for `cats.Id` and `Future` are provided in `GithubIOSyntax`.
34+
3235

3336
## Notifications
3437

@@ -44,9 +47,9 @@ You can subscribe or unsubscribe using `setThreadSub`; it takes as arguments:
4447
- `subscribed`: Determines if notifications should be received from this thread.
4548
- `ignored`: Determines if all notifications should be blocked from this thread.
4649

47-
```scala
48-
val threadSub = Github(accessToken).activities.setThreadSub(5, true, false)
49-
threadSub.exec[cats.Id]() match {
50+
```scala mdoc:compile-only
51+
val threadSub = Github[IO](accessToken).activities.setThreadSub(5, true, false)
52+
threadSub.unsafeRunSync match {
5053
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
5154
case Right(r) => println(r.result)
5255
}
@@ -68,9 +71,9 @@ You can list the users starring a specific repository with `listStargazers`; it
6871

6972
To list the stargazers of 47deg/github4s:
7073

71-
```scala mdoc:silent
72-
val listStargazers = Github(accessToken).activities.listStargazers("47deg", "github4s", true)
73-
listStargazers.exec[cats.Id]() match {
74+
```scala mdoc:compile-only
75+
val listStargazers = Github[IO](accessToken).activities.listStargazers("47deg", "github4s", true)
76+
listStargazers.unsafeRunSync match {
7477
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
7578
case Right(r) => println(r.result)
7679
}
@@ -95,9 +98,9 @@ the repo was last pushed to), optional.
9598

9699
To list the starred repositories for user `rafaparadela`:
97100

98-
```scala mdoc:silent
99-
val listStarredRepositories = Github(accessToken).activities.listStarredRepositories("rafaparadela", true)
100-
listStarredRepositories.exec[cats.Id]() match {
101+
```scala mdoc:compile-only
102+
val listStarredRepositories = Github[IO](accessToken).activities.listStarredRepositories("rafaparadela", true)
103+
listStarredRepositories.unsafeRunSync match {
101104
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
102105
case Right(r) => println(r.result)
103106
}
@@ -112,4 +115,4 @@ As you can see, a few features of the activity endpoint are missing.
112115

113116
As a result, if you'd like to see a feature supported, feel free to create an issue and/or a pull request!
114117

115-
[activity-scala]: https://github.com/47deg/github4s/blob/master/github4s/shared/src/main/scala/github4s/free/domain/Activity.scala
118+
[activity-scala]: https://github.com/47deg/github4s/blob/master/github4s/src/main/scala/github4s/domain/Activity.scala

docs/docs/auth.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ The following examples assume the following imports:
1717

1818
```scala mdoc:silent
1919
import github4s.Github
20-
import github4s.Github._
21-
import github4s.implicits._
20+
import github4s.GithubIOSyntax._
21+
import cats.effect.IO
22+
import scala.concurrent.ExecutionContext.Implicits.global
23+
24+
implicit val IOContextShift = IO.contextShift(global)
2225
```
26+
They also make use of `cats.Id`, but any type container `F` implementing `ConcurrentEffect` will do.
27+
28+
LiftIO syntax for `cats.Id` and `Future` are provided in `GithubIOSyntax`.
2329

2430
**NOTE**: In the examples you will see `Github(None)`
2531
because if you are authenticating for the first time you don't have any access token yet.
@@ -36,15 +42,15 @@ You can create a new authorization token using `newAuth`; it takes as arguments:
3642
- `client_id`: the 20 character OAuth app client key for which to create the token.
3743
- `client_secret`: the 40 character OAuth app client secret for which to create the token.
3844

39-
```scala
40-
val newAuth = Github(None).auth.newAuth(
45+
```scala mdoc:compile-only
46+
val newAuth = Github[IO](None).auth.newAuth(
4147
"rafaparadela",
4248
"invalidPassword",
4349
List("public_repo"),
4450
"New access token",
4551
"e8e39175648c9db8c280",
4652
"1234567890")
47-
newAuth.exec[cats.Id]() match {
53+
newAuth.unsafeRunSync match {
4854
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
4955
case Right(r) => println(r.result)
5056
}
@@ -65,12 +71,12 @@ You can authorize a url using `authorizeUrl`; it takes as arguments:
6571
- `redirect_uri`: the URL in your app where users will be sent to after authorization.
6672
- `scopes`: attached to the token, for more information see [the scopes doc](https://developer.github.com/v3/oauth/#scopes).
6773

68-
```scala
69-
val authorizeUrl = Github(None).auth.authorizeUrl(
74+
```scala mdoc:compile-only
75+
val authorizeUrl = Github[IO](None).auth.authorizeUrl(
7076
"e8e39175648c9db8c280",
7177
"http://localhost:9000/_oauth-callback",
7278
List("public_repo"))
73-
authorizeUrl.exec[cats.Id]() match {
79+
authorizeUrl.unsafeRunSync match {
7480
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
7581
case Right(r) => println(r.result)
7682
}
@@ -93,14 +99,14 @@ You can get an access token using `getAccessToken`; it takes as arguments:
9399
- `redirect_uri`: the URL in your app where users will be sent after authorization.
94100
- `state`: the unguessable random string you optionally provided in [Create a new authorization token](#create-a-new-authorization-token).
95101

96-
```scala mdoc:silent
97-
val getAccessToken = Github(None).auth.getAccessToken(
102+
```scala mdoc:compile-only
103+
val getAccessToken = Github[IO](None).auth.getAccessToken(
98104
"e8e39175648c9db8c280",
99105
"1234567890",
100106
"code",
101107
"http://localhost:9000/_oauth-callback",
102108
"status")
103-
getAccessToken.exec[cats.Id]() match {
109+
getAccessToken.unsafeRunSync match {
104110
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
105111
case Right(r) => println(r.result)
106112
}
@@ -114,4 +120,4 @@ As you can see, a few features of the authorization endpoint are missing.
114120

115121
As a result, if you'd like to see a feature supported, feel free to create an issue and/or a pull request!
116122

117-
[auth-scala]: https://github.com/47deg/github4s/blob/master/github4s/shared/src/main/scala/github4s/free/domain/Authorization.scala
123+
[auth-scala]: https://github.com/47deg/github4s/blob/master/github4s/src/main/scala/github4s/domain/Authorization.scala

0 commit comments

Comments
 (0)