php-github-api/doc/repo/contents.md at master · KnpLabs/php-github-api · GitHub
Skip to content

Latest commit

 

History

History
76 lines (48 loc) · 2.34 KB

contents.md

File metadata and controls

76 lines (48 loc) · 2.34 KB

Repo / Contents API

Back to the "Repos API" | Back to the navigation


Wraps GitHub Repository Contents API.

You can read about references here.

Get a repository's README

https://docs.github.com/rest/repos/contents#get-a-repository-readme

$readme = $client->api('repo')->contents()->readme('KnpLabs', 'php-github-api', $reference);

Get information about a repository file or directory

https://docs.github.com/rest/repos/contents#get-repository-content

$fileInfo = $client->api('repo')->contents()->show('KnpLabs', 'php-github-api', $path, $reference);

Check that a file or directory exists in the repository

$fileExists = $client->api('repo')->contents()->exists('KnpLabs', 'php-github-api', $path, $reference);

Create a file

https://docs.github.com/rest/repos/contents#create-or-update-file-contents

$committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com');

$fileInfo = $client->api('repo')->contents()->create('KnpLabs', 'php-github-api', $path, $content, $commitMessage, $branch, $committer);

Update a file

https://docs.github.com/rest/repos/contents#create-or-update-file-contents

$committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com');
$oldFile = $client->api('repo')->contents()->show('KnpLabs', 'php-github-api', $path, $branch);

$fileInfo = $client->api('repo')->contents()->update('KnpLabs', 'php-github-api', $path, $content, $commitMessage, $oldFile['sha'], $branch, $committer);

Remove a file

https://docs.github.com/rest/repos/contents#delete-a-file

$committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com');
$oldFile = $client->api('repo')->contents()->show('KnpLabs', 'php-github-api', $path, $branch);

$fileInfo = $client->api('repo')->contents()->rm('KnpLabs', 'php-github-api', $path, $commitMessage, $oldFile['sha'], $branch, $committer);

Get repository archive

https://docs.github.com/rest/repos/contents#download-a-repository-archive-tar

$archive = $client->api('repo')->contents()->archive('KnpLabs', 'php-github-api', $format, $reference);

Download a file

$fileContent = $client->api('repo')->contents()->download('KnpLabs', 'php-github-api', $path, $reference);