Skip to content

Add docblocks for git data #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/Github/Api/GitData/Blobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
*/
class Blobs extends AbstractApi
{
/**
* Configure the Acccept header depending on the blob type.
*
* @param string|null $bodyType
*/
public function configure($bodyType = null)
{
if ('raw' == $bodyType) {
Expand All @@ -20,13 +25,33 @@ public function configure($bodyType = null)
}
}

/**
* Show a blob of a sha for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function show($username, $repository, $sha)
{
$response = $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha));

return $response;
}

/**
* Create a blob of a sha for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @return array
*
* @throws \Github\Exception\MissingArgumentException
*/
public function create($username, $repository, array $params)
{
if (!isset($params['content'], $params['encoding'])) {
Expand Down
20 changes: 20 additions & 0 deletions lib/Github/Api/GitData/Commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,31 @@
*/
class Commits extends AbstractApi
{
/**
* Show a commit for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function show($username, $repository, $sha)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits/'.rawurlencode($sha));
}

/**
* Create a commit for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @return array
*
* @throws \Github\Exception\MissingArgumentException
*/
public function create($username, $repository, array $params)
{
if (!isset($params['message'], $params['tree'], $params['parents'])) {
Expand Down
72 changes: 72 additions & 0 deletions lib/Github/Api/GitData/References.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,72 @@
*/
class References extends AbstractApi
{
/**
* Get all references of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function all($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs');
}

/**
* Get all branches of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function branches($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/heads');
}

/**
* Get all tags of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function tags($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags');
}

/**
* Show the reference of a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function show($username, $repository, $reference)
{
$reference = $this->encodeReference($reference);

return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
}

/**
* Create a reference for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @return array
*
* @throws \Github\Exception\MissingArgumentException
*/
public function create($username, $repository, array $params)
{
if (!isset($params['ref'], $params['sha'])) {
Expand All @@ -42,6 +86,18 @@ public function create($username, $repository, array $params)
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params);
}

/**
* Update a reference for a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
* @param array $params
*
* @return array
*
* @throws \Github\Exception\MissingArgumentException
*/
public function update($username, $repository, $reference, array $params)
{
if (!isset($params['sha'])) {
Expand All @@ -53,13 +109,29 @@ public function update($username, $repository, $reference, array $params)
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params);
}

/**
* Delete a reference of a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function remove($username, $repository, $reference)
{
$reference = $this->encodeReference($reference);

return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
}

/**
* Encode the raw reference.
*
* @param string $rawReference
*
* @return string
*/
private function encodeReference($rawReference)
{
return implode('/', array_map('rawurlencode', explode('/', $rawReference)));
Expand Down
28 changes: 28 additions & 0 deletions lib/Github/Api/GitData/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,44 @@
*/
class Tags extends AbstractApi
{
/**
* Get all tags for a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function all($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags');
}

/**
* Get a tag for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function show($username, $repository, $sha)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags/'.rawurlencode($sha));
}

/**
* Create a tag for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @return array
*
* @throws \Github\Exception\MissingArgumentException
*/
public function create($username, $repository, array $params)
{
if (!isset($params['tag'], $params['message'], $params['object'], $params['type'])) {
Expand Down
21 changes: 21 additions & 0 deletions lib/Github/Api/GitData/Trees.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,32 @@
*/
class Trees extends AbstractApi
{
/**
* Get the tree for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
* @param bool $recursive
*
* @return array
*/
public function show($username, $repository, $sha, $recursive = false)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), array('recursive' => $recursive ? 1 : null));
}

/**
* Create tree for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @return array
*
* @throws \Github\Exception\MissingArgumentException
*/
public function create($username, $repository, array $params)
{
if (!isset($params['tree']) || !is_array($params['tree'])) {
Expand Down