Skip to content

Allow getting repo info by id, not just user and repo name #579

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 5 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ $repos = $client->api('repo')->find('chess', array('language' => 'php', 'start_p
$repo = $client->api('repo')->show('KnpLabs', 'php-github-api')
```

or

```php
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the note about the undocumented feature also here in the docs. This makes it more visible for users using this api method. We can remove the note later when it's official mentioned in the docs!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done too

$repo = $client->api('repo')->showById(123456)
```

Returns an array of information about the specified repository.

### Get the repositories of a specific user
Expand Down
14 changes: 14 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ public function show($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository));
}

/**
* Get extended information about a repository by its id.
*
* @link http://developer.github.com/v3/repos/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a note saying it isn't documented...

*
* @param int $id the id of the repository
*
* @return array information about the repository
*/
public function showById($id)
{
return $this->get('/repositories/'.rawurlencode($id));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the ID always an integer? Why do we ned rawurlencode?

´return $this->get(sprintf('/repositories/%d', $id));`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should always be an integer (currently anyway). I thought about checking that they'd input an integer and if not throwing an exception, but then figured that it was better than us assuming IDs never become non-integers to just pass it over to GitHub and let them respond accordingly. Having the rawurlencode ensures that whatever is passed into the function (even if it shouldn't have been) is sent over to GitHub properly.

There probably isn't much in it as I think it's highly unlikely that GH will ever start to issue non-integer IDs, but personally I prefer this way - it's GitHub's ID, let's let them validate it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, okey. I see that @m1guelpf and @acrobat are fine with the way it is so let's not change it.

}

/**
* Create repository.
Expand Down