L&D series: Get to know GitHub API v3

Ferawati Hartanti Pratiwi
Inside Bukalapak
Published in
4 min readJun 22, 2020
https://www.seekpng.com/png/detail/183-1838203_http-octodex-github-github-octocat.png

Learning and Development chapter 4.

Who doesn’t know about GitHub these days? I think GitHub is the most popular platform to save and integrate our code, isn’t it?

How many of you know that GitHub also has an API for a developer guide? Check it out here (https://developer.github.com/v3/). The new version already has v4 of it (https://developer.github.com/v4/), but since I don’t understand v4 yet so I’m just gonna discuss v3 in this article.

Authentication Token

Before we start to hit the endpoint, I’ll show you how to get the token because some endpoint URL requires authentication.

Click Setting Menu
Click Developer settings Menu
Click Personal access token menu
Click Generate new token
Create name and choose access for our token the click Generate token button
Do not forget to save our token in a safe place because we can’t see it anymore

Issues Assignees

https://developer.github.com/v3/issues/assignees/

Assign assignees to issue

List assignees

GET /repos/:owner/:repo/assignees . With this endpoint, we’ll know anyone who becomes an assignee in our repository.

Check if a user can be assigned

GET /repos/:owner/:repo/assignees/:assignee . We can check if the users above can become our assignees in the repository. If yes, then the expected response will 204.

Add assignees to an issue

POST /repos/:owner/:repo/issues/:issue_number/assignees . We can add an assignee up to 10 people. This endpoint needs the auth token.

Because I don’t use bot token so the user is using my username.

Remove assignees from an issue

DELETE /repos/:owner/:repo/issues/:issue_number/assignees . After adding an assignee, we can also delete the assignee we want to remove. This endpoint needs the auth token.

Result when removed the assignee

Issue Comments

https://developer.github.com/v3/issues/comments/

List issue comments

GET /repos/:owner/:repo/issues/:issue_number/comments .

List issue comments for a repository

GET /repos/:owner/:repo/issues/comments .

Create an issue comment

POST /repos/:owner/:repo/issues/:issue_number/comments .

Add comment result

Update an issue comment

PATCH /repos/:owner/:repo/issues/comments/:comment_id .

Update comment result

Delete an issue comment

DELETE /repos/:owner/:repo/issues/comments/:comment_id .

Issue Labels

https://developer.github.com/v3/issues/labels/

List labels for a repository

GET /repos/:owner/:repo/labels .

Create a label

POST /repos/:owner/:repo/labels .

The label has created successfully

Add labels to an issue

POST /repos/:owner/:repo/issues/:issue_number/labels .

Add the label to Pull Request

Pull Requests Reviews

https://developer.github.com/v3/pulls/reviews/

List reviews for a pull request

GET /repos/:owner/:repo/pulls/:pull_number/reviews .

Create a review for a pull request

POST /repos/:owner/:repo/pulls/:pull_number/reviews .

Because the PR is created by my account, as well as with the token.

Pull Request Review Requests

https://developer.github.com/v3/pulls/review_requests/

List requested reviewers for a pull request

GET /repos/:owner/:repo/pulls/:pull_number/requested_reviewers .

Request reviewers

Request reviewers for a pull request

POST /repos/:owner/:repo/pulls/:pull_number/requested_reviewers .

Remove requested reviewers from a pull request

DELETE /repos/:owner/:repo/pulls/:pull_number/requested_reviewers .

Request reviewers the remove the requested reviewers

Do you know that the API above can be used for https://danger.systems/reference.html with the help of https://octokit.github.io/octokit.rb/Octokit/Client.html? It will help us to manage our GitHub repository simple and better. Worth to try. — MperMperPisang

https://myk27x.github.io/octodex/images/megacat.png

References :

--

--

Ferawati Hartanti Pratiwi
Inside Bukalapak

QA (Quality Ambassador) | mpermperpisang official Medium account