#!/usr/bin/env php 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; } $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/$username/$repository/stats/contributors"); if ($request === false) { return false; } $usernames = array(); foreach ($request as $contribution) { $usernames[$contribution->author->login] = $contribution->author->login; } return $usernames; } function get_organisation_members($username) { $request = api_request("orgs/$username/public_members"); if ($request === false) { return false; } $usernames = array(); foreach ($request as $member) { $usernames[$member->login] = $member->login; } return $usernames; } function get_collaborators($username, $repository) { $request = api_request("repos/$username/$repository/collaborators"); if ($request === false) { return false; } $usernames = array(); foreach ($request as $collaborator) { $usernames[$collaborator->login] = $collaborator->login; } return $usernames; } function get_forks($username, $repository) { $request = api_request("repos/$username/$repository/forks"); if ($request === false) { return false; } $usernames = array(); foreach ($request as $fork) { $usernames[$fork->owner->login] = array( 'username' => $fork->owner->login, 'repository' => $fork->name, ); } return $usernames; } function get_arg($array, $index, $default) { return isset($array[$index]) ? $array[$index] : $default; } function run($cmd, $dry = false) { static $dry_run; if (is_null($cmd)) { $dry_run = $dry; } else if (!empty($dry_run)) { echo "$cmd\n"; } else { passthru(escapeshellcmd($cmd)); } }