Skip to content

Commit b9733db

Browse files
committed
Merge pull request #1 from l3l0/add-to-travis
Add travis.yml file, fixed some code and tests
2 parents 73c0d8f + 3253653 commit b9733db

File tree

9 files changed

+313
-76
lines changed

9 files changed

+313
-76
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
7+
before_script:
8+
- curl -s http://getcomposer.org/installer | php
9+
- php composer.phar update
10+
11+
script: phpunit

README.markdown

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
1-
# PHP GitHub API
1+
# PHP GitHub API [WIP]
2+
3+
[![Build Status](https://secure.travis-ci.org/KnpLabs/php-github-api.png?branch=api_v3)](http://travis-ci.org/KnpLabs/php-github-api)
4+
5+
[WARNING] We are converting that lib into "github api v3" so some stuff is not working yet...
26

37
A simple Object Oriented wrapper for GitHub API, written with PHP5.
48

59
```php
6-
$github = new Github_Client();
10+
$github = new Github\Client();
711
$myRepos = $github->getRepoApi()->getUserRepos('ornicar');
812
```
913

10-
Uses [GitHub API v2](http://develop.github.com/). The object API is very similar to the RESTful API.
14+
Uses [GitHub API v3](http://developer.github.com/v3/). The object API is very similar to the RESTful API.
1115

1216
## Features
1317

14-
* Covers 100% of GitHub API with PHP methods
15-
* Supports 3 authentication methods
16-
* Follows PEAR conventions and coding standard: autoload friendly
18+
* Follows PSR-0 conventions and coding standard: autoload friendly
1719
* Light and fast thanks to lazy loading of API classes
1820
* Flexible and extensible thanks to dependency injection
1921
* Extensively tested and documented
2022

2123
## Requirements
2224

23-
* PHP 5.2 or 5.3.
24-
* [php curl](http://php.net/manual/en/book.curl.php), but it is possible to write another transport layer.
25+
* PHP >= 5.3
2526
* PHPUnit to run tests.
2627

2728
## Autoload
2829

29-
The first step to use php-github-api is to register its autoloader:
30+
The new version of php-github-api using [composer](http://getcomposer.org).
31+
The first step to use php-github-api is to download composer: `curl -s http://getcomposer.org/installer | php`
32+
Then we have to install our dependencies using `php composer.phar install`, now we can use autoloader from composer by:
3033

3134
```php
32-
require_once '/path/to/lib/Github/Autoloader.php';
33-
Github_Autoloader::register();
35+
require_once 'vendor/autoload.php';
3436
```
3537

36-
Replace the `/path/to/lib/` path with the path you used for php-github-api installation.
38+
TODO: More examples how to install with composer. Some example of composer.json files. Add to packagist
3739

38-
> php-github-api follows the PEAR convention names for its classes, which means you can easily integrate php-github-api classes loading in your own autoloader.
40+
> php-github-api follows the PSR-0 convention names for its classes, which means you can easily integrate php-github-api classes loading in your own autoloader.
3941
4042
## instantiate a new github client
4143

4244
```php
43-
$github = new Github_Client();
45+
$github = new Github\Client();
4446
```
4547

4648
From this object, you can access to all GitHub apis, listed below.
@@ -55,15 +57,9 @@ From this object, you can access to all GitHub apis, listed below.
5557
<a href='#nav' alt='Back to the navigation'>Go back to the Navigation</a>
5658

5759
Searching users, getting user information and managing authenticated user account information.
58-
Wrap [GitHub User API](http://develop.github.com/p/users.html).
59-
60-
### Search for users by username
61-
62-
```php
63-
$users = $github->getUserApi()->search('ornicar');
64-
```
60+
Wrap [GitHub User API](http://developer.github.com/v3/users).
6561

66-
Returns an array of users.
62+
### Search for users by username is depreciated cause of github api limitation.
6763

6864
### Get information about a user
6965

@@ -700,16 +696,16 @@ Wanna change, let's say, the http client User Agent?
700696
$github->getHttpClient()->setOption('user_agent', 'My new User Agent');
701697
```
702698

703-
See all available options in Github/HttpClient.php
699+
See all available options in Github/HttpClient/HttpClient.php
704700

705701
### Inject a new http client instance
706702

707703
php-github-api provides a curl-based implementation of a http client.
708-
If you want to use your own http client implementation, inject it to the Github_Client instance:
704+
If you want to use your own http client implementation, inject it to the Github\Client instance:
709705

710706
```php
711707
// create a custom http client
712-
class MyHttpClient extends Github_HttpClient
708+
class MyHttpClient extends Github\HttpClient\HttpClient
713709
{
714710
public function doRequest($url, array $parameters = array(), $httpMethod = 'GET', array $options = array())
715711
{
@@ -720,10 +716,10 @@ If you want to use your own http client implementation, inject it to the Github_
720716

721717
> Your http client implementation may not extend Github_HttpClient, but only implement Github_HttpClientInterface.
722718
723-
You can now inject your http client through Github_Client constructor:
719+
You can now inject your http client through Github\Client constructor:
724720

725721
```php
726-
$github = new Github_Client(new MyHttpClient());
722+
$github = new Github\Client(new MyHttpClient());
727723
```
728724

729725
Or to an existing Github_Client instance:
@@ -739,7 +735,7 @@ For example, to replace the user API:
739735

740736
```php
741737
// create a custom User API
742-
class MyGithubApiUser extends Github_Api_User
738+
class MyGithubApiUser extends Github\Api\User
743739
{
744740
// overwrite things
745741
}

lib/Github/Api/Issue.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ class Issue extends Api
1818
* @param string $username the username
1919
* @param string $repo the repo
2020
* @param string $state the issue state, can be open or closed
21+
* @param array $state the additional parameters like milestone, assignee, lables, sort, direction
2122
* @return array list of issues found
2223
*/
23-
public function getList($username, $repo, $state = 'open')
24+
public function getList($username, $repo, $state = null, $parameters = array())
2425
{
25-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues?state='.urlencode($state));
26+
$url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/issues';
27+
if ($state) {
28+
$parameters['state'] = $state;
29+
}
30+
if ($parameters) {
31+
$url .= '?'.http_build_query($parameters);
32+
}
33+
34+
return $this->get($url);
2635
}
2736

2837
/**
2938
* Search issues by username, repo, state and search term
30-
* http://develop.github.com/p/issues.html#list_a_projects_issues
3139
*
3240
* @param string $username the username
3341
* @param string $repo the repo
@@ -88,7 +96,7 @@ public function open($username, $repo, $title, $body)
8896

8997
/**
9098
* Close an existing issue by username, repo and issue number. Requires authentication.
91-
* http://develop.github.com/p/issues.html#open_and_close_issues
99+
* @link http://developer.github.com/v3/issues/
92100
*
93101
* @param string $username the username
94102
* @param string $repo the repo
@@ -102,7 +110,7 @@ public function close($username, $repo, $number)
102110

103111
/**
104112
* Update issue informations by username, repo and issue number. Requires authentication.
105-
* http://develop.github.com/p/issues.html#edit_existing_issues
113+
* @link http://developer.github.com/v3/issues/
106114
*
107115
* @param string $username the username
108116
* @param string $repo the repo
@@ -113,12 +121,12 @@ public function close($username, $repo, $number)
113121
*/
114122
public function update($username, $repo, $number, array $data)
115123
{
116-
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
124+
return $this->patch('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
117125
}
118126

119127
/**
120128
* Repoen an existing issue by username, repo and issue number. Requires authentication.
121-
* http://develop.github.com/p/issues.html#open_and_close_issues
129+
* @link http://developer.github.com/v3/issues/
122130
*
123131
* @param string $username the username
124132
* @param string $repo the repo
@@ -132,7 +140,7 @@ public function reOpen($username, $repo, $number)
132140

133141
/**
134142
* List an issue comments by username, repo and issue number
135-
* http://develop.github.com/p/issues.html#list_an_issues_comments
143+
* @link http://developer.github.com/v3/issues/comments/
136144
*
137145
* @param string $username the username
138146
* @param string $repo the repo
@@ -150,13 +158,12 @@ public function getComments($username, $repo, $number)
150158
*
151159
* @param string $username the username
152160
* @param string $repo the repo
153-
* @param string $number the issue number
154161
* @param string $id the comment id
155162
* @return array list of issue comments
156163
*/
157-
public function getComment($username, $repo, $number, $id)
164+
public function getComment($username, $repo, $id)
158165
{
159-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number).'/comments/'.urlencode($id));
166+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/comments/'.urlencode($id));
160167
}
161168

162169
/**

lib/Github/Api/PullRequest.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ class PullRequest extends Api
2121
* The API seems to automatically default to 'open'
2222
* @return array array of pull requests for the project
2323
*/
24-
public function listPullRequests($username, $repo, $state = 'open')
24+
public function listPullRequests($username, $repo, $state = null)
2525
{
26-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls?state='.urlencode($state));
26+
$url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/pulls';
27+
if ($state) {
28+
$url .= '?state='.urlencode($state);
29+
}
30+
31+
return $this->get($url);
2732
}
2833

2934
/**
@@ -43,7 +48,7 @@ public function show($username, $repo, $id)
4348
/**
4449
* Create a pull request
4550
*
46-
* @link http://develop.github.com/p/pulls.html
51+
* @link http://developer.github.com/v3/pulls/
4752
* @param string $username the username
4853
* @param string $repo the repo
4954
* @param string $base A String of the branch or commit SHA that you want your changes to be pulled to.
@@ -52,15 +57,23 @@ public function show($username, $repo, $id)
5257
* specify the username first: "my-user:some-branch".
5358
* @param string $title The String title of the Pull Request. Used in pair with $body.
5459
* @param string $body The String body of the Pull Request. Used in pair with $title.
60+
* @param string $issueNumber The issue number. Used when title and body is not set.
5561
* @return array array of pull requests for the project
5662
*/
57-
public function create($username, $repo, $base, $head, $title, $body = null)
63+
public function create($username, $repo, $base, $head, $title, $body = null, $issueNumber = null)
5864
{
59-
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', array(
65+
$input = array(
6066
'head' => $head,
6167
'base' => $base,
62-
'title' => $title,
63-
'body' => $body,
64-
));
68+
);
69+
70+
if ($title || $body) {
71+
$input['title'] = $title;
72+
$input['body'] = $body;
73+
} else {
74+
$input['issue'] = $issueNumber;
75+
}
76+
77+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', $input);
6578
}
6679
}

0 commit comments

Comments
 (0)