Project API

Note: The Projects API is currently available for developers to preview. During the preview period, the API may change without advance notice. Please see the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header: application/vnd.github.inertia-preview+json

Github4s supports the Project API. As a result, with Github4s, you can interact with:

The following examples assume the following code:


import cats.effect.IO
import github4s.Github
import org.http4s.client.{Client, JavaNetClientBuilder}


val httpClient: Client[IO] = JavaNetClientBuilder[IO].create // You can use any http4s backend

val accessToken = sys.env.get("GITHUB_TOKEN")
val gh = Github[IO](httpClient, accessToken)

Project

List repository projects

You can list the projects for a particular repository with listProjectsRepository; it takes as arguments:

  • owner: name of the owner for which we want to retrieve the projects.
  • repo: name of the repository for which we want to retrieve the projects.
  • state: filter projects returned by their state. Can be either open, closed, all. Default: open, optional
  • pagination: Limit and Offset for pagination, optional.
  • header: headers to include in the request, optional.

To list the projects for owner 47deg and repository github4s:

val listProjectsRepository = gh.projects.listProjectsRepository(
    owner = "47deg",
    repo = "github4s",
    headers = Map("Accept" -> "application/vnd.github.inertia-preview+json"))
listProjectsRepository.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding List[Project].

See the API doc for full reference.

List projects

You can list the project for a particular organization with listProjects; it takes as arguments:

  • org: name of the organization for which we want to retrieve the projects.
  • state: filter projects returned by their state. Can be either open, closed, all. Default: open, optional
  • pagination: Limit and Offset for pagination, optional.
  • header: headers to include in the request, optional.

To list the projects for organization 47deg:

val listProjects = gh.projects.listProjects(
    org = "47deg",
    headers = Map("Accept" -> "application/vnd.github.inertia-preview+json"))
listProjects.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding List[Project].

See the API doc for full reference.

Columns

List project columns

You can list the columns for a particular project with listColumns; it takes as arguments:

  • project_id: project id for which we want to retrieve the columns.
  • pagination: Limit and Offset for pagination, optional.
  • header: headers to include in the request, optional.

To list the columns for project_id 1910444:

val listColumns = gh.projects.listColumns(
    project_id = 1910444,
    headers = Map("Accept" -> "application/vnd.github.inertia-preview+json"))
listColumns.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding List[Column].

See the API doc for full reference.

Cards

List project cards by column

You can list the cards for a particular column with listCards; it takes as arguments:

  • column_id: column id for which we want to retrieve the cards.
  • archived_state: filters the project cards that are returned by the card’s state. Can be one of all,archived, or not_archived. Default: not_archived, optional.
  • pagination: Limit and Offset for pagination, optional.
  • header: headers to include in the request, optional.

To list the columns for project_id 8271018:

val listCards = gh.projects.listCards(
    column_id = 8271018,
    headers = Map("Accept" -> "application/vnd.github.inertia-preview+json"))
listCards.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding List[Card].

See the API doc for full reference.