Learn R Programming

R Bindings for the Github v3 API

This project is essentially abandoned

Hello there - unfortunately I don't have time to maintain this project anymore. If you're interested in taking over, send me an email and I'm happy to help with the transition.

If you're a user of this library, consider switching to gh or ghapi3, which are both newer and more actively maintained.

Intro

These are bindings for the Github web service API as of version 3. For full documentation, please refer to the Github developer API.

Quickie

> ctx = interactive.login(client.id, client.secret)
> me = get.myself(ctx)
> me$content$public_repos
[1] 17
> star.repository("cscheid", "guitar", ctx)
> unstar.repository("cscheid", "guitar", ctx)

Setting up

In order to use most of their API, Github requires you to register an application. You'll need to do this if you want to change information, repositories, post gists, etc.

Interactive use

If you will authenticate your Github account interactively (using the OAuth dance, for example), you should point the Callback URL to "http://localhost:1410". This is so that interactive.login works: the interactive OAuth login dancing involves redirection to a URL that is specified in advance. httr creates a web server on port 1410 to catch the redirection request and the token that comes with it.

To log in, you will need the Application Client ID and Secret, and you will call the following function in your R script:

> ctx = interactive.login(client.id, client.secret, scopes=c("gist"))

This will open a web browser where the caller of the R script (presumably, you) will be asked to type their Github username and password. Give more scopes to allow the bindings to do more things (more on oAuth scopes).

Noninteractive use

If you have obtained an OAuth access token by some other method, you can pass it directly to create.github.context. In fact, interactive.login does little else than securing access to a token interactively, and then calling create.github.context.

In other words, you should use create.github.context if some other part of your application is in charge of obtaining the OAuth access token.

You can also use create.github.context to create anonymous access contexts. You will be able to make some calls into the API, but not all of them, and you will be much more severely rate-limited. See the documentation for details.

About the Github client secret

DO NOT PUT THE CLIENT SECRET ON A PUBLICLY VISIBLE LOCATION. This is equivalent to an application-wide password. It is used by Github to track API usage, and could be used to impersonate your app. Store it in a safe location (like a locally-encrypted file in your local filesystem), ask the user to type it, or pass it via environment variables from the shell.

API naming and style

All API entry points are very shallow wrappers around Github's API. Once you logged in, all calls to the API take the result of web.login. Examples:

> repos = get.my.repositories(ctx)
> repos = get.my.repositories(ctx, type="owner")

The result of all calls to the API is the request from httr. Most of the time you will want the response contents, accessible through httr's content(). This is automatically parsed into JSON, the message format used throughout's the api:

> me = get.myself(ctx)
> me$content$public_repos
[1] 17

The naming of the function calls is always meant to evoke an order. It starts with a verb and follows with the appropriate objects:

> evts = get.public.events(ctx)
> result = is.repository.starred.by.me("cscheid", "facet")
> star.repository("cscheid", "guitar", ctx)
> unstar.repository("cscheid", "guitar", ctx)

When the Github API specifies "inputs", such as with blob creation, you will send the JSON content as the last parameter, named content:

> create.blob(ctx, "cscheid", "guitar", list(content="This is a new blob", encoding="utf-8"))

When the Github API specifies extra parameters, such as when listing repositories, you will pass parameters directly to the API call, like you've already seen above:

# Get all my repositories, sorted by when I last pushed to them
> repos = get.my.repositories(ctx, type="owner", sort="pushed")

TODO

  • Keep track of rate limits
  • Honor event API X-Poll-Interval query rate limits automatically

Copy Link

Version

Version

0.9.8

License

MIT + file LICENSE

Last Published

June 6th, 2018

Functions in github (0.9.8)

add.repository.collaborator

add a user to the list of collaborators of a repo
add.repository.to.team

add repository to team
create.commit

create a commit
create.blob

create a blob
am.following.user

Test whether current user is following given user
conceal.member.of.organization

conceal user membership in an organization
create.commit.comment

create a comment for a given commit in a repository
add.issue.labels

Add labels to an issue
add.emails

Add emails to the account
add.member.to.team

add member to team
create.fork

create a fork under the current user
create.gist.comment

Create gist comment
create.hook

create a new hook for repo
create.issue.comment

Create issue comment
create.gist

create a new gist
create.github.context

Create a github context object.
create.issue

Create issue
create.key

Add a public key with some id
create.organization.repository

create rpository under given organization
create.milestone

Create milestone
create.pull.request.comment

Create a comment on a pull request
create.repository.label

create a label for a repository
create.pull.request

create a pull request
create.repository.status

create status for a ref in a repo
create.repository.key

create a repository key
create.team

create a team in an organization
create.repository

create repository
create.tree

get a tree
create.tag

create a tag
create.reference

create a reference
delete.all.issue.labels

Delete all issue labels
delete.issue.label

Delete an issue from a label
delete.key

Delete a public key with some id
delete.hook

delete a hook.
delete.commit.comment

delete a single commit comment
delete.gist.comment

Delete gist comment
delete.member.from.organization

delete user from an organization
delete.emails

Delete emails from the account
delete.gist

delete a gist
delete.issue.comment

Delete issue comment
delete.member.from.team

remove member from team
delete.milestone

Delete milestone
get.assignees

Get list of assignees for a repo
delete.repository

delete repository
delete.repository.from.team

remove repository from team
get.blob

get a blob
get.gist.comment

Get specific comment
get.all.repositories

get list of all repositories
get.gist.comments

Get comments for a gist
get.all.repository.issues.comments

Get list of comments for an issue
get.issue.labels

List all labels for an issue
get.commit.comment

get a single commit comment
get.commit

get a commit
delete.repository.label

delete a label from a repository
delete.repository.key

delete a repository key
get.key

Get a public key with some id
get.gist.forks

list the forks of a gist
get.all.references

get all references (or subreferences)
get.all.my.issues

get all issues across all the authenticated user's visible repositories including owned repositories, member repositories, and organization repositories
get.gist

get a specific gist
get.my.followers

Get the list of followers for the current user
get.my.following

List who is following the current user
get.network.public.events

list events for a network of repositories
get.organization.public.members

list public members of organization
get.organization.repositories

get list of repositories of given organization
get.myself

Get information on the current user
get.repositories.watched.by.user

list repos watched by users
get.repositories.watched.by.me

list repos watched by current user
get.repository.commits

get commits from a repo
get.repository.commit

get a specific commit from a repo
get.repository.issue.events

list issue events for a given repo
get.repository.issues

List all issues for a repo
get.my.keys

Get public keys for the current user
get.pull.request

get a specific pull request
get.my.notifications

list the current user's notifications
get.pull.request.files

list files for a pull request
get.pull.requests

list all pull requests
get.repository.downloads

list downloads for a repository
get.reference

get a git reference
get.repository.events

list events for a given repo
get.tree

get a tree
get.user.received.events

list events that a user has received
get.user.followers

Get the list of followers for a given user
get.repository.keys

list all repository keys
get.user.repositories

Get list of repositories of given user
get.repository.label

get a specific label for a repository
is.assignee

Test if user is assignee in a repo
is.member.in.team

test if user is a member of team
modify.commit.comment

update a single commit comment
mark.thread.notifications

mark a single thread as read.
modify.pull.request

edit pull request
get.organization.teams

list teams from an organization
modify.reference

edit a reference
get.pull.requests.comments

List comments on all pull requests for a repo
get.pull.requests.comment

Get specific comment for a pull request
get.public.events

list public events
get.repository.branches

get list of repository branches
get.repository.collaborators

get list of collaborators of a repo
get.repository.status

get combined status for a ref in a repo
get.repository.statuses

get statuses for a ref in a repo
get.tag

get a tag
delete.pull.request.comment

Delete a comment on a pull request
get.team

get team information
delete.reference

delete a reference
fork.gist

fork a gist
follow.user

Start following a given user
get.issue.comments

Get list of comments for an issue
get.milestones

List milestones for a repository
get.issue.events

List events for an issue
get.my.emails

Get the list of emails of the current user
get.my.organization.events

list events from the authenticated user organization
get.repository.contributors

get list of repository contributors
get.my.organizations

List all organizations for the current user.
get.repository.key

get a specific repository key
get.repository

get repository
get.repository.contributors.stats

get stats on repository contributors
get.repository.teams

get list of teams participating in the repository
get.repository.languages

get list of languages used in the repository, as estimated by github
get.repository.labels

List all labels for a repository
get.stargazers

list people who starred a repo
get.my.gists

list the current user's gists
get.my.issues

List all issues across owned and member repositories for the authenticated user:
get.organization

Get an organization
get.organization.issues

List all issues across an organization of the authenticated user:
get.pull.request.comments

List comments on a pull request
get.pull.request.commits

list commits for a pull request
get.repositories.starred.by.user

list repos starred by user
get.repositories.starred.by.me

list repos starred by current user
get.repository.commit.comments

get all commit comments for a given commit in a repository
get.repository.comments

get all commit comments for a repository
delete.repository.collaborator

delete a user from the list of collaborators of a repo
delete.team

delete a team in an organization
delete.repository.path

Delete a file in a repository
delete.repository.download

delete specific download for a repository
get.github.context

returns the most recently created github context, or creates one if none has been so far created
get.issue.comment

Get specific comment
get.milestone.labels

Get labels for every issue in a milestone
get.milestone

Get specific milestone from a repository
get.my.repositories

Get list of repositories of current user
get.my.repository.notifications

list the current user's notifications for a given repo
get.organization.members

list all members from an organization. List all users who are members of an organization. A member is a user that belongs to at least 1 team in the organization. If the authenticated user is also an owner of this organization then both concealed and public members will be returned. If the requester is not an owner of the organization the query will be redirected to the public members list.
get.organization.public.events

list public events for an organization
get.repository.diff

return a diff between two commits
get.repository.archive

Get the archive of a repo
get.repository.branch

get specific repository branch
get.repository.download

get specific download for a repository
get.repository.forks

list forks
get.repository.hook

get specific hook of repository
get.repository.path

Get the contents of a file
get.repository.readme

Get the README for a repo
get.user.organizations

List all public organizations for an unauthenticated user. Lists private and public organizations for authenticated users.
is.public.member.of.organization

test if user is a public member of organization
is.member.of.organization

test if user is a member of an organization
get.user.performed.events

list events that a user has performed
modify.milestone

Edit milestone
modify.myself

Change information about the current user
search.issues

Search Github issues.
search.code

Search Github code.
star.repository

star a repository
star.gist

star a gist
get.user.public.performed.events

list public events that a user has performed
get.user.public.received.events

list public events that a user has received
test.hook

test a push hook. This will force github to trigger the given hook.
perform.repository.merge

perform a merge.
is.starred

test if gist is starred
perform.merge.pull.request

merge a pull request
is.repository.starred.by.me

check if repository is starred by current user
get.team.members

list team members
get.team.repositories

list repositories of a team
unfollow.user

Stop following a given user
get.user

Get information on some user
get.user.keys

Get public keys for a given user
is.pull.request.merged

test if pull request has been merged
modify.repository

modify repository
mark.my.repository.notifications

mark my notifications as read for a given repo
mark.my.notifications

mark my notifications as read
modify.repository.key

update a repository key
is.repository.collaborator

test if a given user is a collaborator of a repo
interactive.login

Obtain a github context interactively
github

github-package: use the Github API from R
modify.gist.comment

Edit gist comment
modify.gist

Edit a gist
modify.issue

Modify issue
unset.repository.subscription

clear repository subscription info
modify.key

Update a public key with some id
modify.team

edit a team in an organization
modify.repository.label

edit a specific label for a repository
unset.thread.notifications.subscription

deletes subscription info from thread.
publicize.member.of.organization

publicize user membership in an organization
replace.issue.labels

Replace all issue labels
unstar.gist

unstar a gist
unstar.repository

unstar a repository
get.repository.hooks

list hooks of repository
update.repository.path

Update the contents of a file
get.repository.issue.event

List a single event for a repository issue
get.repository.tags

get list of repository tags
get.thread.notifications

get single thread notifications
get.repository.subscription

get repository subscription info
get.thread.notifications.subscription

checks to see if the current user is subscribed to a thread.
get.user.following

List who a user is following
get.user.gists

list the gists of a given user
get.watchers

list repo watchers
get.users

Get all github users
modify.issue.comment

Modify issue comment
search.repositories

Search Github repositories.
modify.pull.request.comment

Modify a comment on a pull request
modify.organization

modify an organization
modify.hook

modify an exisitng hook for repo
search.users

Search Github users.
set.repository.subscription

set repository subscription info
set.thread.notifications.subscription

subscribes current user to a thread, or ignore thread. Subscribing to a thread is unnecessary if the user is already subscribed to the repository. Ignoring a thread will mute all future notifications (until you comment or get at-mentioned).