aboutsummaryrefslogtreecommitdiffstats
path: root/git-tools/setup_github_network.php
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-06-24 13:49:29 -0500
committerNathan Guse <nathaniel.guse@gmail.com>2013-06-24 13:49:29 -0500
commitff84aed0b2e5bb2def73a1861e601ad9fb8856df (patch)
tree22ffb4b331619cfb96002b526c6b45b3fc297332 /git-tools/setup_github_network.php
parent2dd58413e26434568bd768549e621e72b5ccb33c (diff)
parenta5c971176be81f854772919713da6db506fa7cd1 (diff)
downloadforums-ff84aed0b2e5bb2def73a1861e601ad9fb8856df.tar
forums-ff84aed0b2e5bb2def73a1861e601ad9fb8856df.tar.gz
forums-ff84aed0b2e5bb2def73a1861e601ad9fb8856df.tar.bz2
forums-ff84aed0b2e5bb2def73a1861e601ad9fb8856df.tar.xz
forums-ff84aed0b2e5bb2def73a1861e601ad9fb8856df.zip
Merge branch 'develop' of github.com:phpbb/phpbb3 into feature/twig
# By Dhruv (35) and others # Via Andreas Fischer (15) and others * 'develop' of github.com:phpbb/phpbb3: (75 commits) [ticket/10776] update min php version 5.3.3 in readme [ticket/11503] similar implementation for mssql_native and odbc [ticket/11603] Fix out dated comment [ticket/11603] Fix usage note [ticket/11604] Skip installer step where config.php is created. [ticket/11603] Throw RuntimeExceptions instead of using exit() [ticket/11603] Avoid using cURL [ticket/11604] Fix case where config.php is not generated by phpBB. [ticket/11604] Use variables for config.php filesnames. [ticket/11561] Specify used tables in notification fixture, so they are emptied [ticket/11094] Add textbox for jabber while memberlist search [ticket/10820] fix if condition to check for IE [ticket/11603] Split api_request into two functions (query only vs. full url) [ticket/11603] Fix spacing and add some comments [ticket/10820] Add additional check for IE in condition [ticket/11603] Fix github API calls [ticket/11603] Rename network to forks and fix handling [ticket/11603] Fix github api url and use curl with valid user agent [ticket/10820] Fix function docblock [ticket/10820] Inject IE version in function ...
Diffstat (limited to 'git-tools/setup_github_network.php')
-rwxr-xr-xgit-tools/setup_github_network.php92
1 files changed, 66 insertions, 26 deletions
diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php
index 5f2e1609a7..4e144edae6 100755
--- a/git-tools/setup_github_network.php
+++ b/git-tools/setup_github_network.php
@@ -15,14 +15,14 @@ function show_usage()
echo "$filename adds repositories of a github network as remotes to a local git repository.\n";
echo "\n";
- echo "Usage: [php] $filename -s collaborators|organisation|contributors|network [OPTIONS]\n";
+ echo "Usage: [php] $filename -s collaborators|organisation|contributors|forks [OPTIONS]\n";
echo "\n";
echo "Scopes:\n";
echo " collaborators Repositories of people who have push access to the specified repository\n";
echo " contributors Repositories of people who have contributed to the specified repository\n";
echo " organisation Repositories of members of the organisation at github\n";
- echo " network All repositories of the whole github network\n";
+ echo " forks All repositories of the whole github network\n";
echo "\n";
echo "Options:\n";
@@ -55,31 +55,31 @@ exit(work($scope, $username, $repository, $developer));
function work($scope, $username, $repository, $developer)
{
// Get some basic data
- $network = get_network($username, $repository);
+ $forks = get_forks($username, $repository);
$collaborators = get_collaborators($username, $repository);
- if ($network === false || $collaborators === false)
+ if ($forks === false || $collaborators === false)
{
- echo "Error: failed to retrieve network or collaborators\n";
+ echo "Error: failed to retrieve forks or collaborators\n";
return 1;
}
switch ($scope)
{
case 'collaborators':
- $remotes = array_intersect_key($network, $collaborators);
+ $remotes = array_intersect_key($forks, $collaborators);
break;
case 'organisation':
- $remotes = array_intersect_key($network, get_organisation_members($username));
+ $remotes = array_intersect_key($forks, get_organisation_members($username));
break;
case 'contributors':
- $remotes = array_intersect_key($network, get_contributors($username, $repository));
+ $remotes = array_intersect_key($forks, get_contributors($username, $repository));
break;
- case 'network':
- $remotes = $network;
+ case 'forks':
+ $remotes = $forks;
break;
default:
@@ -145,26 +145,66 @@ function get_repository_url($username, $repository, $ssh = false)
function api_request($query)
{
- $contents = file_get_contents("http://github.com/api/v2/json/$query");
+ return api_url_request("https://api.github.com/$query?per_page=100");
+}
+
+function api_url_request($url)
+{
+ $contents = file_get_contents($url, false, stream_context_create(array(
+ 'http' => array(
+ 'header' => "User-Agent: phpBB/1.0\r\n",
+ ),
+ )));
+
+ $sub_request_result = array();
+ // Check headers for pagination links
+ if (!empty($http_response_header))
+ {
+ foreach ($http_response_header as $header_element)
+ {
+ // Find Link Header which gives us a link to the next page
+ if (strpos($header_element, 'Link: ') === 0)
+ {
+ list($head, $header_content) = explode(': ', $header_element);
+ foreach (explode(', ', $header_content) as $links)
+ {
+ list($url, $rel) = explode('; ', $links);
+ if ($rel == 'rel="next"')
+ {
+ // Found a next link, follow it and merge the results
+ $sub_request_result = api_url_request(substr($url, 1, -1));
+ }
+ }
+ }
+ }
+ }
+
if ($contents === false)
{
return false;
}
- return json_decode($contents);
+ $contents = json_decode($contents);
+
+ if (isset($contents->message) && strpos($contents->message, 'API Rate Limit') === 0)
+ {
+ throw new RuntimeException('Reached github API Rate Limit. Please try again later' . "\n", 4);
+ }
+
+ return ($sub_request_result) ? array_merge($sub_request_result, $contents) : $contents;
}
function get_contributors($username, $repository)
{
- $request = api_request("repos/show/$username/$repository/contributors");
+ $request = api_request("repos/$username/$repository/stats/contributors");
if ($request === false)
{
return false;
}
$usernames = array();
- foreach ($request->contributors as $contributor)
+ foreach ($request as $contribution)
{
- $usernames[$contributor->login] = $contributor->login;
+ $usernames[$contribution->author->login] = $contribution->author->login;
}
return $usernames;
@@ -172,14 +212,14 @@ function get_contributors($username, $repository)
function get_organisation_members($username)
{
- $request = api_request("organizations/$username/public_members");
+ $request = api_request("orgs/$username/public_members");
if ($request === false)
{
return false;
}
$usernames = array();
- foreach ($request->users as $member)
+ foreach ($request as $member)
{
$usernames[$member->login] = $member->login;
}
@@ -189,35 +229,35 @@ function get_organisation_members($username)
function get_collaborators($username, $repository)
{
- $request = api_request("repos/show/$username/$repository/collaborators");
+ $request = api_request("repos/$username/$repository/collaborators");
if ($request === false)
{
return false;
}
$usernames = array();
- foreach ($request->collaborators as $collaborator)
+ foreach ($request as $collaborator)
{
- $usernames[$collaborator] = $collaborator;
+ $usernames[$collaborator->login] = $collaborator->login;
}
return $usernames;
}
-function get_network($username, $repository)
+function get_forks($username, $repository)
{
- $request = api_request("repos/show/$username/$repository/network");
+ $request = api_request("repos/$username/$repository/forks");
if ($request === false)
{
return false;
}
$usernames = array();
- foreach ($request->network as $network)
+ foreach ($request as $fork)
{
- $usernames[$network->owner] = array(
- 'username' => $network->owner,
- 'repository' => $network->name,
+ $usernames[$fork->owner->login] = array(
+ 'username' => $fork->owner->login,
+ 'repository' => $fork->name,
);
}