Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest release #493

Merged
merged 7 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/docs/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,29 @@ response.result match {

The `result` on the right is the corresponding [List[Release]][repository-scala].

### The latest release
georgeorfanidi marked this conversation as resolved.
Show resolved Hide resolved

You can get the latest release using `latestRelease`, it takes as arguments:

- the repository coordinates (`owner` and `name` of the repository).

Get the latest release:

```scala mdoc:compile-only
val latestRelease =
gh.repos.latestRelease(
"47deg",
"github4s",
Map.empty)
georgeorfanidi marked this conversation as resolved.
Show resolved Hide resolved
val response = latestRelease.unsafeRunSync()
response.result match {
case Left(e) => println(s"Something went wrong: ${e.getMessage}")
case Right(r) => println(r)
}
```

The `result` on the right is the corresponding [Option[Release]][repository-scala].

### Create a release

Users with push access to the repository can create a release using `createRelease`; it takes as arguments:
Expand Down
14 changes: 14 additions & 0 deletions github4s/src/main/scala/github4s/algebras/Repositories.scala
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ trait Repositories[F[_]] {
headers: Map[String, String] = Map()
): F[GHResponse[List[User]]]

/**
* Latest release
*
* @param owner of the repo
* @param repo name of the repo
* @param headers optional user headers to include in the request
* @return a GHResponse with List[Release]
*/
def latestRelease(
owner: String,
repo: String,
headers: Map[String, String]
georgeorfanidi marked this conversation as resolved.
Show resolved Hide resolved
): F[GHResponse[Option[Release]]]

/**
* List of releases
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ class RepositoriesInterpreter[F[_]](implicit client: HttpClient[F], accessToken:
pagination
)

override def latestRelease(
owner: String,
repo: String,
headers: Map[String, String]
): F[GHResponse[Option[Release]]] =
client
.get[Option[Release]](accessToken, s"repos/$owner/$repo/releases/latest", headers, Map.empty)

override def listReleases(
owner: String,
repo: String,
Expand Down
12 changes: 12 additions & 0 deletions github4s/src/test/scala/github4s/integration/ReposSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ trait ReposSpec extends BaseIntegrationSpec {
response.statusCode shouldBe okStatusCode
}

"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
.latestRelease(validRepoOwner, validRepoName, headers = headerUserAgent)
}
.unsafeRunSync()

testIsRight[Option[Release]](response, r => r.nonEmpty shouldBe true)
response.statusCode shouldBe okStatusCode
}

"Repos >> ListOrgRepos" should "return the expected repos when a valid org is provided" taggedAs Integration in {
val response = clientResource
.use { client =>
Expand Down
14 changes: 14 additions & 0 deletions github4s/src/test/scala/github4s/unit/ReposSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class ReposSpec extends BaseSpec {
repos.listReleases(validRepoOwner, validRepoName, None, headers = headerUserAgent)
}

"Repos.latestRelease" should "call to httpClient.get with the right parameters" in {
val response: IO[GHResponse[Option[Release]]] =
IO(GHResponse(Option(release).asRight, okStatusCode, Map.empty))

implicit val httpClientMock = httpClientMockGet[Option[Release]](
url = s"repos/$validRepoOwner/$validRepoName/releases/latest",
response = response
)

val repos = new RepositoriesInterpreter[IO]

repos.latestRelease(validRepoOwner, validRepoName, headers = headerUserAgent)
}

"Repos.listOrgRepos" should "call to httpClient.get with the right parameters" in {
val response: IO[GHResponse[List[Repository]]] =
IO(GHResponse(List(repo).asRight, okStatusCode, Map.empty))
Expand Down