Searching repositories, getting repository information and managing repository information for authenticated users. Wrap GitHub Repo API. All methods are described on that page.
$repos = $client->api('repo')->all();
$repos = $client->api('repo')->all(1337);
$repos = $client->api('repo')->find('symfony');
Returns a list of repositories.
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));
Using the username of the repository owner and the repository name:
$repo = $client->api('repo')->show('KnpLabs', 'php-github-api')
Or by using the repository id (note that this is at time of writing an undocumented feature, see here and here):
$repo = $client->api('repo')->showById(123456)
Returns an array of information about the specified repository.
$repos = $client->api('user')->repositories('KnpLabs');
Returns a list of repositories.
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.
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'.
Requires authentication.
$client->api('repo')->remove('username', 'my-new-repo'); // Get the deletion token
Deletes the my-new-repo repository.
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.
$keys = $client->api('repo')->keys()->all('username', 'reponame');
Returns a list of the deploy keys for the 'reponame' 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.
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.
Requires authentication.
$client->api('repo')->hooks()->create('username', 'reponame', $params);
Requires authentication.
$client->api('repo')->hooks()->remove('username', 'reponame', $id);
Requires authentication.
$client->api('repo')->hooks()->all('username', 'reponame');
$collaborators = $client->api('repo')->collaborators()->all('username', 'reponame');
Returns a list of the collaborators for the 'reponame' repository.
$client->api('repo')->collaborators()->add('username', 'reponame', 'collaborator');
Adds the 'collaborator' user as collaborator to the 'reponame' repository.
Requires authentication.
$client->api('repo')->collaborators()->remove('username', 'reponame', 'collaborator');
Remove the 'collaborator' collaborator from the 'reponame' repository.
$permissions = $client->api('repo')->collaborators()->permission('username', 'reponame', 'collaborator');
Returns the permissions of 'collaborator' collaborator for the 'reponame' 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.
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.
$tags = $client->api('repo')->tags('ornicar', 'php-github-api');
Returns a list of tags.
$branches = $client->api('repo')->branches('ornicar', 'php-github-api');
Returns a list of branches.
$branch = $client->api('repo')->branches('ornicar', 'php-github-api', 'master');
Returns a branch data.
$watchers = $client->api('repo')->watchers('ornicar', 'php-github-api');
Returns list of the users watching the 'php-github-api' owned by 'ornicar'.
$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.
$languages = $client->api('repo')->languages('ornicar', 'php-github-api');
Returns a list of languages.
https://docs.github.com/en/rest/reference/repos#enable-automated-security-fixes
$client->api('repo')->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api');
https://docs.github.com/en/rest/reference/repos#disable-automated-security-fixes
$client->api('repo')->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api');
$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);
$activity = $client->api('repo')->activity('ornicar', 'php-github-api');
Returns an array of commit activity group by week.
Github repositories can be moved to another org/user, but it remains the id
.
In case if you can't no more find repo, you can retrieve it by id
:
use Github\HttpClient\Message\ResponseMediator;
$data = $client->getHttpClient()->get('/repositories/24560307');
$repo = ResponseMediator::getContent($data);
$milestones = $client->api('repo')->milestones('ornicar', 'php-github-api');
Returns a list of milestones.
$communityProfile = $client->api('repo')->communityProfile('ornicar', 'php-github-api');
$codeOfConduct = $client->api('repo')->codeOfConduct('ornicar', 'php-github-api');
$topics = $client->api('repo')->topics('ornicar', 'php-github-api');
$currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']);
$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github');
You can optionally assign some teams by passing an array with their ID's if you're transferring the repo to an organization:
$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1234]);
Example when you want to configure custom github action workflows.
$client->api('repo')->dispatch('KnpLabs', 'php-github-api', 'acme-event', ['foo'=>'bar']);
Create a new repository using a repository template.
$client->api('repo')->createFromTemplate('template-owner', 'template-repo', [
'name' => 'name-of-new-repo',
'owner' => 'name-of-new-repo-owner', // can be user or org
]);