Skip to content

Commit

Permalink
Merge pull request KnpLabs#290 from lucasmichot/feature/gitdata
Browse files Browse the repository at this point in the history
Add docblocks for git data
  • Loading branch information
cursedcoder committed Jul 7, 2015
2 parents 934ad37 + b5d61c3 commit 99c6b87
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
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

0 comments on commit 99c6b87

Please sign in to comment.