Repository

Note

See the official GitHub API v2 documentation for repositories.

class github2.repositories.Repository(type)[source]

Repository container.

homepage

Homepage for this project.

description

Repository description.

url

Canonical URL to this repository

open_issues

List of open issues for this repository.

has_issues

If True, this repository has an issue tracker.

has_downloads

If True, this repository has downloads.

integration_branch

Integration branch, if set.

name

Name of repository.

has_wiki

If True, this repository has a wiki.

fork

If True, this is a fork of another repository.

watchers

Number of people watching this repository.

private

If True, the repository is private.

language

Primary language for the repository.

created_at

Datetime the repository was created.

owner

Username of the user owning this repository.

parent

The parent project of this fork.

forks

Number of forks of this repository.

source

The root project of this fork

master_branch

Default branch, if set.

pushed_at

Datetime of the last push to this repository

class github2.repositories.Repositories(type)[source]

GitHub API repository functionality.

add_collaborator(project, username)[source]

Add an add_collaborator to a repo.

param str project:
 GitHub project
param str username:
 GitHub user to add as collaborator

Warning

Requires authentication

branches(project)[source]

Get branch names for project.

Parameters:project (str) – GitHub project
create(project, description=None, homepage=None, public=True)[source]

Create a repository.

param str project:
 new project name
param str description:
 optional project description
param str homepage:
 optional project homepage
param bool public:
 whether to make a public project

Warning

Requires authentication

delete(project)[source]

Delete a repository.

param str project:
 project name to delete

Warning

Requires authentication

fork(project)[source]

Fork a project.

param str project:
 GitHub project

Warning

Requires authentication

languages(project)[source]

Get programming language data for project.

Parameters:project (str) – GitHub project
list(user=None, page=1)[source]

Return a list of all repositories for a user.

Deprecated since version 0.4.0: Previous releases would attempt to display repositories for the logged-in user when user wasn’t supplied. This functionality is brittle and will be removed in a future release!

Parameters:
  • user (str) – GitHub user name to list repositories for
  • page (int) – optional page number
list_collaborators(project)[source]

List all the collaborators in a project.

Parameters:project (str) – GitHub project
list_contributors(project)[source]

List all the contributors in a project.

Parameters:project (str) – GitHub project
network(project)[source]

Get network data for project.

Parameters:project (str) – GitHub project
pushable()[source]

Return a list of repos you can push to that are not your own.

New in version 0.3.0.

Warning

Requires authentication

remove_collaborator(project, username)[source]

Remove a collaborator from a repo.

param str project:
 GitHub project
param str username:
 GitHub user to add as collaborator

Warning

Requires authentication

search(query)[source]

Get all repositories that match term.

Parameters:query (str) – term to search issues for
set_private(project)[source]

Mark repository as private.

param str project:
 project name to set as private

Warning

Requires authentication

set_public(project)[source]

Mark repository as public.

param str project:
 project name to set as public

Warning

Requires authentication

show(project)[source]

Get repository object for project.

Parameters:project (str) – GitHub project
tags(project)[source]

Get tags for project.

Parameters:project (str) – GitHub project
unwatch(project)[source]

Unwatch a project.

param str project:
 GitHub project

Warning

Requires authentication

watch(project)[source]

Watch a project.

param str project:
 GitHub project

Warning

Requires authentication

watchers(project)[source]

Get list of watchers for project.

Parameters:project (str) – GitHub project
watching(for_user=None, page=None)[source]

List all the repos a user is watching.

Parameters:
  • for_user (str) – optional GitHub user name to list repositories for
  • page (int) – optional page number

Examples

Searching Repositories

>>> repositories = github.repos.search("django")

Show Repo Info

>>> repo = github.repos.show("schacon/grit")
>>> repo.homepage
"http://grit.rubyforge.org/"

List All Repositories

>>> repos = github.repos.list("schacon")

By default the first page of results is returned, you can return further results with the page parameter:

>>> repos = github.repos.list("schacon", page=2)

Watching Repositories

>>> github.repos.watch("schacon/grit")
>>> github.repos.unwatch("schacon/grit")

Forking Repositories

>>> fork = github.repos.fork("schacon/grit")

Creating and Deleting Repositories

>>> new_repo = github.repos.create(name, description, homepage,
...                                 public=True)
>>> github.repos.delete(name)

Repository Visibility

>>> github.repos.set_private("ask/chishop")
>>> github.repos.set_public("ask/chishop")

Pushable repositories

>>> pushables = github.repos.pushable()

Collaborators

>>> collabs = github.repos.list_collaborators("ask/chishop")
>>> github.repos.add_collaborator("ask/chishop", "schacon")
>>> github.repos.remove_collaborator("ask/chishop", "schacon")

Watchers

>>> watchers = github.repos.watchers("ask/chishop")

Network

>>> github.repos.network("ask/chishop")

Repository Refs

Get a list of tags

>>> tags = github.repos.tags("ask/chishop")

Get a list of remote branches

>>> branches = github.repos.branches("ask/chishop")