milo / github-api Goto Github PK
View Code? Open in Web Editor NEWGithub API easy access
Github API easy access
I had the need to specify the CURLOPT_SSL_VERIFYPEER option to the CurlClient instantiation because I am using a self-signed certificate and have not found a way to get CURL/GitHub to be happy with the certificate. My need is to get the file name for the latest release in the repository and I can condition my code to know that it is running in a test environment so I am not too concerned about the issues of the request not being verified.
I have modified Api::__construct and the Helpers::createDefaultClient functions to pass the $options array as an additional parameter and all works well. It would really be nice to have this change incorporated in your released code so I don't have to propagate the change whenever I upgrade to a new release.
A really nice augmentation to this change would be to have an equivalence mapping of these options so that the calling code does not need to be cognisant of whether the curl or stream client is being used.
Hello,
Thanks you for all this, it helps a lot to manage our softwares versions.
I just notice that you didn't implement PSR4 on your exceptions. That's not a big problem at all since you have a working autoloader.
If you have time, one day, for a futur update, it would be awesome.
Regards,
Vincent
Possible to use instead of Application Tokens? - I have an app that's inhouse to a private repo and we'd rather use the personal token ..
I had a look through the code and it doesn't appear to be the case - PS: excellent understanding of namespacing and OO ... you would not believe the messes I encountered trying other libs first :)
Hi ๐ ,
I an engineer on the API team at GitHub. A colleague and I are currently going through GitHub's REST API, tightening up validations.
We noticed that a fair number of requests from this library to the Add or update organization membership endpoint that are passing a Content-Length
key as part of the payload. Content-Length is an accepted header, but is not a valid value for the payload to this endpoint.
Currently the backend code is ignoring unknown parameters, but we're shortly going to change the validation to return a 422 Unprocessable Entity if an undocumented parameter is passed.
We're expecting to make this change in about a week, and wanted to give you a heads up so you're not caught by surprise.
Hi Miloslav,
First of all thanks for the API code! I use it in my Gizzle project: https://github.com/NamelessCoder/gizzle
I'll be very brief - I have a simple use case that I would like to have supported by the API. When performing calls via the API the returned data very often contains the URLs which can be used to manipulate the data, but these URLs are full URLs including the protocol and the API seems to require relative URLs instead. Currently I simply crop the domain and protocol off before passing it to your API but the code would be much cleaner and transparent if one could simply pass the raw URLs returned alongside the entity datas.
My question is: do you think such support would make sense? If you do, I'd be happy to make a pull request but I thought I'd ask before going ahead.
Cheers,
Claus
Fatal error: Uncaught exception 'Milo\Github\Http\BadResponseException' with message 'SSL certificate problem: unable to get local issuer certificate' in C:\xampp\htdocs\issues-classes\vendor\milo\github-api\src\Github\Http\CurlClient.php:108 Stack trace: #0 C:\xampp\htdocs\issues-classes\vendor\milo\github-api\src\Github\Http\AbstractClient.php(49): Milo\Github\Http\CurlClient->process(Object(Milo\Github\Http\Request)) #1 C:\xampp\htdocs\issues-classes\vendor\milo\github-api\src\Github\Api.php(202): Milo\Github\Http\AbstractClient->request(Object(Milo\Github\Http\Request)) #2 C:\xampp\htdocs\issues-classes\vendor\milo\github-api\src\Github\Api.php(106): Milo\Github\Api->request(Object(Milo\Github\Http\Request)) #3 C:\xampp\htdocs\baka\issues\index.php(186): Milo\Github\Api->get('/search/issues?...') #4 C:\xampp\htdocs\baka\issues\index.php(132): check_for_unique('pomftest') #5 {main} thrown in C:\xampp\htdocs\issues-classes\vendor\milo\github-api\src\Github\Http\CurlClient.php on line 108
Full error above. I've used this api for several years without problems and now i'm getting this error on submitting an api request. Any idea why or how to fix it?
Awesome framework!
But I have a issue:
When I try to use Login::getToken()
I get the error
Fatal error: Class 'Login' not found in /helper.php on line 42
But I included the class in the helper.php file:
<?php
require_once( 'framework/github-api.php' );
use Milo\Github;
When processing a request for Org members with 2fa using an account that is not part of the Owner team, the GH API returns a 422 response. The Api.php file tries to process the $content->errors property, but that doesn't exist in the response. So the response is missing the details of the error, and instead sees a stdClass::errors undefined property message.
Can I use PHP ">=5.3.29" instead?
php.net: What has changed in PHP 5.4.x says
Most improvements in PHP 5.4.x have no impact on existing code. There are a few incompatibilities and new features that should be considered, and code should be tested before switching PHP versions in production environments
But I'm not able to review the github-api
code and check if the few incompatibilities or new features are in use.
Any of Yes/No/Don't know
answers is good enough for me as I can upgrade to PHP 5.4 I just want to know if it is necessary to undergo the hassle
I'm looking for a simple to use, bug-free, read-only GitHub PHP client and I've found this library. My question is:
I'm also considering
Do you have an example of authenticating the user with OAuth and then using an application token to fetch the users repositories etc?
I get an error when trying to use the client: SSL: invalid CA certificate #1 (offset 0) in bundle
. If I comment out the CURLOPT_CAINFO
line then it works fine.
Undefined property: stdClass::$errors on src/Github/Api.php line 284
I was passing in a bad value for a date parameter, and Github was returning error 5422 "unprocessable entity."
Hello @milo
thank you for this great little helper :) I noticed a odd behavior I'm not sure where it comes from: When running a request to the information about a repo (e.g. /repos/milo/github-api) the number of Watchers is wrong. It seems to be actually the number of stars. Here is an var_dump from your repo as an example:
array(71) {
["id"]=>
int(19703364)
["name"]=>
string(10) "github-api"
["full_name"]=>
string(15) "milo/github-api"
["owner"]=>
array(17) {
["login"]=>
string(4) "milo"
["id"]=>
int(439140)
["avatar_url"]=>
string(50) "https://avatars.githubusercontent.com/u/439140?v=3"
["gravatar_id"]=>
string(0) ""
["url"]=>
string(33) "https://api.github.com/users/milo"
["html_url"]=>
string(23) "https://github.com/milo"
["followers_url"]=>
string(43) "https://api.github.com/users/milo/followers"
["following_url"]=>
string(56) "https://api.github.com/users/milo/following{/other_user}"
["gists_url"]=>
string(49) "https://api.github.com/users/milo/gists{/gist_id}"
["starred_url"]=>
string(56) "https://api.github.com/users/milo/starred{/owner}{/repo}"
["subscriptions_url"]=>
string(47) "https://api.github.com/users/milo/subscriptions"
["organizations_url"]=>
string(38) "https://api.github.com/users/milo/orgs"
["repos_url"]=>
string(39) "https://api.github.com/users/milo/repos"
["events_url"]=>
string(50) "https://api.github.com/users/milo/events{/privacy}"
["received_events_url"]=>
string(49) "https://api.github.com/users/milo/received_events"
["type"]=>
string(4) "User"
["site_admin"]=>
bool(false)
}
["private"]=>
bool(false)
["html_url"]=>
string(34) "https://github.com/milo/github-api"
["description"]=>
string(22) "Github API easy access"
["fork"]=>
bool(false)
["url"]=>
string(44) "https://api.github.com/repos/milo/github-api"
["forks_url"]=>
string(50) "https://api.github.com/repos/milo/github-api/forks"
["keys_url"]=>
string(58) "https://api.github.com/repos/milo/github-api/keys{/key_id}"
["collaborators_url"]=>
string(73) "https://api.github.com/repos/milo/github-api/collaborators{/collaborator}"
["teams_url"]=>
string(50) "https://api.github.com/repos/milo/github-api/teams"
["hooks_url"]=>
string(50) "https://api.github.com/repos/milo/github-api/hooks"
["issue_events_url"]=>
string(67) "https://api.github.com/repos/milo/github-api/issues/events{/number}"
["events_url"]=>
string(51) "https://api.github.com/repos/milo/github-api/events"
["assignees_url"]=>
string(61) "https://api.github.com/repos/milo/github-api/assignees{/user}"
["branches_url"]=>
string(62) "https://api.github.com/repos/milo/github-api/branches{/branch}"
["tags_url"]=>
string(49) "https://api.github.com/repos/milo/github-api/tags"
["blobs_url"]=>
string(60) "https://api.github.com/repos/milo/github-api/git/blobs{/sha}"
["git_tags_url"]=>
string(59) "https://api.github.com/repos/milo/github-api/git/tags{/sha}"
["git_refs_url"]=>
string(59) "https://api.github.com/repos/milo/github-api/git/refs{/sha}"
["trees_url"]=>
string(60) "https://api.github.com/repos/milo/github-api/git/trees{/sha}"
["statuses_url"]=>
string(59) "https://api.github.com/repos/milo/github-api/statuses/{sha}"
["languages_url"]=>
string(54) "https://api.github.com/repos/milo/github-api/languages"
["stargazers_url"]=>
string(55) "https://api.github.com/repos/milo/github-api/stargazers"
["contributors_url"]=>
string(57) "https://api.github.com/repos/milo/github-api/contributors"
["subscribers_url"]=>
string(56) "https://api.github.com/repos/milo/github-api/subscribers"
["subscription_url"]=>
string(57) "https://api.github.com/repos/milo/github-api/subscription"
["commits_url"]=>
string(58) "https://api.github.com/repos/milo/github-api/commits{/sha}"
["git_commits_url"]=>
string(62) "https://api.github.com/repos/milo/github-api/git/commits{/sha}"
["comments_url"]=>
string(62) "https://api.github.com/repos/milo/github-api/comments{/number}"
["issue_comment_url"]=>
string(69) "https://api.github.com/repos/milo/github-api/issues/comments{/number}"
["contents_url"]=>
string(61) "https://api.github.com/repos/milo/github-api/contents/{+path}"
["compare_url"]=>
string(68) "https://api.github.com/repos/milo/github-api/compare/{base}...{head}"
["merges_url"]=>
string(51) "https://api.github.com/repos/milo/github-api/merges"
["archive_url"]=>
string(67) "https://api.github.com/repos/milo/github-api/{archive_format}{/ref}"
["downloads_url"]=>
string(54) "https://api.github.com/repos/milo/github-api/downloads"
["issues_url"]=>
string(60) "https://api.github.com/repos/milo/github-api/issues{/number}"
["pulls_url"]=>
string(59) "https://api.github.com/repos/milo/github-api/pulls{/number}"
["milestones_url"]=>
string(64) "https://api.github.com/repos/milo/github-api/milestones{/number}"
["notifications_url"]=>
string(84) "https://api.github.com/repos/milo/github-api/notifications{?since,all,participating}"
["labels_url"]=>
string(58) "https://api.github.com/repos/milo/github-api/labels{/name}"
["releases_url"]=>
string(58) "https://api.github.com/repos/milo/github-api/releases{/id}"
["deployments_url"]=>
string(56) "https://api.github.com/repos/milo/github-api/deployments"
["created_at"]=>
string(20) "2014-05-12T15:08:21Z"
["updated_at"]=>
string(20) "2016-10-27T06:38:01Z"
["pushed_at"]=>
string(20) "2016-10-27T06:59:42Z"
["git_url"]=>
string(36) "git://github.com/milo/github-api.git"
["ssh_url"]=>
string(34) "[email protected]:milo/github-api.git"
["clone_url"]=>
string(38) "https://github.com/milo/github-api.git"
["svn_url"]=>
string(34) "https://github.com/milo/github-api"
["homepage"]=>
string(0) ""
["size"]=>
int(106)
["stargazers_count"]=>
int(50)
["watchers_count"]=>
int(50)
["language"]=>
string(3) "PHP"
["has_issues"]=>
bool(true)
["has_downloads"]=>
bool(true)
["has_wiki"]=>
bool(true)
["has_pages"]=>
bool(false)
["forks_count"]=>
int(28)
["mirror_url"]=>
NULL
["open_issues_count"]=>
int(0)
["forks"]=>
int(28)
["open_issues"]=>
int(0)
["watchers"]=>
int(50)
["default_branch"]=>
string(6) "master"
["permissions"]=>
array(3) {
["admin"]=>
bool(false)
["push"]=>
bool(false)
["pull"]=>
bool(true)
}
["network_count"]=>
int(28)
["subscribers_count"]=>
int(16)
}
I'm aware that the subscribers_count at the end is actually the number of watchers. My PHP is v7.0.8.
Peter
I keep getting headers mixed in with the body.
Seems like this doesn't work in line 92 in curlClient.php:
list($headersStr, $content) = explode("\r\n\r\n", $result, 2) + ['', ''];
For example:
$response = $api->get("/repos/name/repo/commits/master");
spits out headers etc.
Now if I do what I assume is what the original goal was of line 92 after the fact:
$result = $response->getContent();
list($headersStr, $content) = explode("\r\n\r\n", $result);
print_r($content);
then $content is just the content. not sure the point of the extra stuff in line 92, but it seems to break basic requests.
The function throws "Decoded JSON is not an array or object." at https://github.com/milo/github-api/blob/v1.4.0/src/Github/Api.php#L257 because the actual value of $contents
is ""
and it does not match is_array()
test neither the is_object()
test.
I want to issue a Request::HEAD
- style request and call some generic GitHub
error handler before running my code. How can I do it? Is behavior of decode()
designed or it is just a not-yet covered edge case?
Test case:
$api = new Github\Api();
$response = $api->head("/users");
$decoded = $api->decode($response);
Expected result: $decoded
contains some empty value
Actual result: exception is thrown
Hello! The Github API v3 returns a list of repositories at /users/:user/repos
. Each repository in that list contains the number of stars (both under stargazers_count
and watchers
), but not the actual watcher count, which can only be retrieved per repository with subscribers_count
at /repos/:user/:repo
. I think it would make sense that the watcher count be available in the repository list like the stars count is.
Example:
$response = $api->get('/repos/:owner/:repo/compare/:base...:head', [
'owner' => 'atoum',
'repo' => 'atoum',
'base' => '3.0.0',
'head' => '3.1.0',
]);
will provoke an error
PHP Fatal error: Uncaught Milo\Github\MissingParameterException: Missing parameter 'base...:head' for URL path '/repos/:owner/:repo/compare/:base...:head'. in /home/jvb/workspace/_perso/atoum-ref/atoum.github.io/scripts/release/vendor/milo/github-api/src/Github/Api.php:373
Stack trace:
#0 [internal function]: Milo\Github\Api->Milo\Github{closure}(Array)
...
Installing release 1.2.0 gives me an error in Helper.php
:
Parse error: syntax error, unexpected '[' in <redacted>/github-api-1.2.0/Github/Helpers.php on line 16
I do not have Composer. Does this require it?
https://api.github.com/search/repositories?q=vscode
stargazers_count: 70274,
forks_count: 9362,
forks: 9362
watchers_count: 70274, <--(LISTED)
watchers: 70274,
https://github.com/Microsoft/vscode
Stars 70,274
Forks 9,362
Watchers 2,667 <--- (REAL)
I have a issue with oauth.
When I first use it, it works fine. But when I revoke the key and try to get another one, I always get the same key again. And then github returns "401 - Bad credentials" error
When I switch browser, it works fine again, so maybe any kind of session issue.
Is there anyway to fix this?
oAuth function is here: https://github.com/TheZoker/GithubTemp/blob/master/github.php#L85-L118
Currently smart caching is implemented, but for development it often useful to never invalidate the cache. This can be currently achieved by manually modifying CachedClient
like this:
if ($cached = $this->cache->load($cacheKey)) {
return $cached; // always use cached result if available
...
}
Hey I'm getting an internal server error 500 after the lines
include '../inc/github-api/github-api.php';
use Milo\Github;
session_start();
$clientId = 'XXX';
$clientSecret = 'XXXX';
$config = new Github\OAuth\Config($clientId, $clientSecret, ['user']);
Any ideas?? Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.