|
| 1 | +--- |
| 2 | +layout: docs |
| 3 | +title: Project API |
| 4 | +permalink: project |
| 5 | +--- |
| 6 | + |
| 7 | +# Project API |
| 8 | + |
| 9 | +Note: The Projects API is currently available for developers to preview. During the preview period, |
| 10 | +the API may change without advance notice. Please see the blog post for full details. To access the |
| 11 | +API during the preview period, you must provide a custom media type in the `Accept` header: |
| 12 | + `application/vnd.github.inertia-preview+json` |
| 13 | + |
| 14 | +Github4s supports the [Project API](https://developer.github.com/v3/projects/). As a result, |
| 15 | +with Github4s, you can interact with: |
| 16 | + |
| 17 | +- [Project](#project) |
| 18 | + - [List projects](#list-project) |
| 19 | + - [Columns](#columns) |
| 20 | + - [List project columns](#list-projects-columns) |
| 21 | + |
| 22 | +The following examples assume the following imports and token: |
| 23 | + |
| 24 | +```scala mdoc:silent |
| 25 | +import github4s.Github |
| 26 | +import github4s.GithubIOSyntax._ |
| 27 | +import cats.effect.IO |
| 28 | +import scala.concurrent.ExecutionContext.Implicits.global |
| 29 | + |
| 30 | +implicit val IOContextShift = IO.contextShift(global) |
| 31 | +val accessToken = sys.env.get("GITHUB4S_ACCESS_TOKEN") |
| 32 | +``` |
| 33 | + |
| 34 | +They also make use of `cats.effect.IO`, but any type container `F` implementing `ConcurrentEffect` will do. |
| 35 | + |
| 36 | +LiftIO syntax for `cats.Id` and `Future` are provided in `GithubIOSyntax`. |
| 37 | + |
| 38 | +## Project |
| 39 | + |
| 40 | +### List projects |
| 41 | + |
| 42 | +You can list the project for a particular organization with `listProjects`; it takes as arguments: |
| 43 | + |
| 44 | +- `org`: name of the organization for which we want to retrieve the projects. |
| 45 | +- `state`: filter projects returned by their state. Can be either `open`, `closed`, `all`. Default: `open`, optional |
| 46 | +- `pagination`: Limit and Offset for pagination, optional. |
| 47 | +- `header`: headers to include in the request, optional. |
| 48 | + |
| 49 | +To list the projects for organization `47deg`: |
| 50 | + |
| 51 | +```scala mdoc:compile-only |
| 52 | +val listProjects = Github[IO](accessToken).projects.listProjects( |
| 53 | + org = "47deg", |
| 54 | + headers = Map("Accept" -> "application/vnd.github.inertia-preview+json")) |
| 55 | +listProjects.unsafeRunSync() match { |
| 56 | + case Left(e) => println(s"Something went wrong: ${e.getMessage}") |
| 57 | + case Right(r) => println(r.result) |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +The `result` on the right is the corresponding [List[Project]][project-scala]. |
| 62 | + |
| 63 | +See [the API doc](https://developer.github.com/v3/projects/#list-organization-projects) for full reference. |
| 64 | + |
| 65 | +[project-scala]: https://github.com/47deg/github4s/blob/master/github4s/src/main/scala/github4s/domain/Project.scala |
| 66 | + |
| 67 | +### Columns |
| 68 | + |
| 69 | +#### List project columns |
| 70 | + |
| 71 | +You can list the columns for a particular project with `listColumns`; it takes as arguments: |
| 72 | + |
| 73 | +- `project_id`: project id for which we want to retrieve the columns. |
| 74 | +- `pagination`: Limit and Offset for pagination, optional. |
| 75 | +- `header`: headers to include in the request, optional. |
| 76 | + |
| 77 | +To list the columns for project_id `1910444`: |
| 78 | + |
| 79 | +```scala mdoc:compile-only |
| 80 | +val listColumns = Github[IO](accessToken).projects.listColumns( |
| 81 | + project_id = 1910444, |
| 82 | + headers = Map("Accept" -> "application/vnd.github.inertia-preview+json")) |
| 83 | +listColumns.unsafeRunSync match { |
| 84 | + case Left(e) => println(s"Something went wrong: ${e.getMessage}") |
| 85 | + case Right(r) => println(r.result) |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +The `result` on the right is the corresponding [List[Column]][column-scala]. |
| 90 | + |
| 91 | +See [the API doc](https://developer.github.com/v3/projects/columns/#list-project-columns) for full reference. |
| 92 | + |
| 93 | +[column-scala]: https://github.com/47deg/github4s/blob/master/github4s/src/main/scala/github4s/domain/Column.scala |
0 commit comments