Repositories API

Back to the navigation

Searching repositories, getting repository information and managing repository information for authenticated users. Wrap GitHub Repo API. All methods are described on that page.

Search repos by keyword

Simple search

$repos = $client->api('repo')->find('symfony');

Returns a list of repositories.

Advanced search

You can filter the results by language. It takes the same values as the language drop down on http://github.com/search.

$repos = $client->api('repo')->find('chess', array('language' => 'php'));

You can specify the page number:

$repos = $client->api('repo')->find('chess', array('language' => 'php', 'start_page' => 2));

Get extended information about a repository

$repo = $client->api('repo')->show('KnpLabs', 'php-github-api')

Returns an array of information about the specified repository.

Get the repositories of a specific user

$repos = $client->api('user')->repositories('KnpLabs');

Returns a list of repositories.

Create a repository

Requires authentication.

$repo = $client->api('repo')->create('my-new-repo', 'This is the description of a repo', 'http://my-repo-homepage.org', true);

Creates and returns a public repository named my-new-repo.

Update a repository

Requires authentication.

$repo = $client->api('repo')->update('username', 'my-new-repo', array('description' => 'some new description'));

The value array also accepts the parameters

  • description
  • homepage
  • has_wiki
  • has_issues
  • has_downloads

Updates and returns the repository named 'my-new-repo' that is owned by 'username'.

Delete a repository

Requires authentication.

$client->api('repo')->remove('username', 'my-new-repo'); // Get the deletion token

Deletes the my-new-repo repository.

Making a repository public or private

Requires authentication.

// Make repo public
$client->api('repo')->update('username', 'reponame', array('private' => false));
// Make repo private
$client->api('repo')->update('username', 'reponame', array('private' => true));

Makes the 'reponame' repository public or private and returns the repository.

Get the deploy keys of a repository

$keys = $client->api('repo')->keys()->all('username', 'reponame');

Returns a list of the deploy keys for the 'reponame' repository.

Add a deploy key to a repository

Requires authentication.

$key = $client->api('repo')->keys()->create('username', 'reponame', array('title' => 'key title', 'key' => 12345));

Adds a key with title 'key title' to the 'reponame' repository and returns a list of the deploy keys for the repository.

Remove a deploy key from a repository

Requires authentication.

$client->api('repo')->keys()->remove('username', 'reponame', 12345);

Removes the key with id 12345 from the 'reponame' repository and returns a list of the deploy keys for the repository.

Get the collaborators for a repository

$collaborators = $client->api('repo')->collaborators()->all('username', 'reponame');

Returns a list of the collaborators for the 'reponame' repository.

Add a collaborator to a repository

$client->api('repo')->collaborators()->add('username', 'reponame', 'KnpLabs');

Adds the 'username' user as collaborator to the 'reponame' repository.

Remove a collaborator from a repository

Requires authentication.

$client->api('repo')->collaborators()->remove('username', 'reponame', 'KnpLabs');

Remove the 'username' collaborator from the 'reponame' repository.

Watch and unwatch a repository

Requires authentication.

$client->api('current_user')->watchers()->watch('ornicar', 'php-github-api');
$client->api('current_user')->watchers()->unwatch('ornicar', 'php-github-api');

Watches or unwatches the 'php-github-api' repository owned by 'ornicar' and returns the repository.

Fork a repository

Requires authentication.

$repository = $client->api('repo')->forks()->create('ornicar', 'php-github-api');

Creates a fork of the 'php-github-api' owned by 'ornicar' and returns the newly created repository.

Get the tags of a repository

$tags = $client->api('repo')->tags('ornicar', 'php-github-api');

Returns a list of tags.

Get the branches of a repository

$branches = $client->api('repo')->branches('ornicar', 'php-github-api');

Returns a list of branches.

Get single branch of a repository

$branch = $client->api('repo')->branches('ornicar', 'php-github-api', 'master');

Returns a branch data.

Get the watchers of a repository

$watchers = $client->api('repo')->watchers('ornicar', 'php-github-api');

Returns list of the users watching the 'php-github-api' owned by 'ornicar'.

Get the network (forks) of a repository

$network = $client->api('repo')->forks()->all('ornicar', 'php-github-api');

Returns list of the forks of the 'php-github-api' owned by 'ornicar', including the original repository.

Get the languages for a repository

$contributors = $client->api('repo')->languages('ornicar', 'php-github-api');

Returns a list of languages.

Get the contributors of a repository

$contributors = $client->api('repo')->contributors('ornicar', 'php-github-api');

Returns a list of contributors.

To include non GitHub users, add a third parameter to true:

$contributors = $client->api('repo')->contributors('ornicar', 'php-github-api', true);

Get the commit activity of a repository

$activity = $client->api('repo')->activity('ornicar', 'php-github-api');

Returns an array of commit activity group by week.