function umc_github_link()
{
    global $GITHUB;
    $repo = $GITHUB['repo'];
    $owner = $GITHUB['owner'];
    $client = umc_github_client_connect($owner, $repo);
    $out = '';
    $paginator = new Github\ResultPager($client);
    $items = array('open_issues' => array('state' => array('state' => 'open'), 'fetch' => 'all'), 'closed_issues' => array('state' => array('state' => 'closed'), 'fetch' => 'all'), 'comments' => array('state' => 'comments', 'fetch' => 'show'));
    foreach ($items as $item => $I) {
        $api = $client->api('issue');
        $parameters = array($owner, $repo, $I['state']);
        ${$item} = $paginator->fetchAll($api, $I['fetch'], $parameters);
    }
    $parameters = array('sha' => 'master', 'per_page' => 100);
    $commits = $client->api('repo')->commits()->all($owner, $repo, $parameters);
    $out .= '<script type="text/javascript" src="/admin/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function() {jQuery("#shoptable_open").dataTable( {"autoWidth": false, "order": [[ 4 ]], "paging": false, "ordering": true, "info": false});;} );
        jQuery(document).ready(function() {jQuery("#shoptable_closed").dataTable( {"autoWidth": false, "order": [[ 4 ]], "paging": false, "ordering": true, "info": false});;} );
        jQuery(document).ready(function() {jQuery("#shoptable_commits").dataTable( {"autoWidth": false, "order": [[ 0 ]], "paging": false, "ordering": true, "info": false});;} );
    </script>
';
    $tab1 = "            <table class='unc_datatables' id='shoptable_open'>\r\n                <thead>\r\n                    <tr><th>#</th><th>Title</th><th style='display:none;'>hidden data</th><th>Labels</th><th>Updated</th></tr>\r\n                </thead>\r\n                <tbody>" . umc_github_issue_body($open_issues, $comments) . "</tbody>\r\n            </table>";
    $tab2 = "            <table class='unc_datatables' id='shoptable_closed'>\r\n                <thead>\r\n                    <tr><th>#</th><th>Title</th><th style='display:none;'>hidden data</th><th>Labels</th><th>Updated</th></tr>\r\n                </thead>\r\n                <tbody>" . umc_github_issue_body($closed_issues, $comments) . "</tbody>\r\n            </table>";
    $tab3 = "            <table class='unc_datatables' id='shoptable_commits'>\r\n                <thead>\r\n                    <tr><th>Date</th><th>User</th><th>Message</th></tr>\r\n                </thead>\r\n                <tbody>" . umc_github_commit_body($commits) . "</tbody>\r\n             </table>";
    $o_count = count($open_issues);
    $c_count = count($closed_issues);
    $out .= umc_jquery_tabs(array("Open Issues ({$o_count})" => $tab1, "Closed Issues ({$c_count})" => $tab2, 'Commits' => $tab3));
    return $out;
}
 protected function fetchExtensionsFromRepository()
 {
     $token = $_SESSION['github.token'];
     if (!$token) {
         throw new \Exception('no github token setup');
     }
     $client = new \Github\Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => $this->app->config('cache_dir') . 'githubapi-cache')));
     $this->client = $client;
     $client->authenticate($token, null, \GitHub\Client::AUTH_URL_TOKEN);
     $pager = new \Github\ResultPager($client);
     $api = $client->api('repo');
     $method = 'branches';
     $params = ['php', 'php-src'];
     $branches = $pager->fetchAll($api, $method, $params);
     $branchesToFetch = [];
     foreach ($branches as $branch) {
         $currentBranchName = $branch['name'];
         if (strlen($currentBranchName) == 7) {
             if (preg_match('$PHP-([0-9])\\.([0-9])$', $currentBranchName, $matches)) {
                 if ((int) $matches[1] < 5 || (int) $matches[2] < 4) {
                     continue;
                 }
                 $branchesToFetch[$matches[0]] = $branch;
             }
         }
     }
     $this->branches = $branchesToFetch;
     $extensions = $this->fetchExtensionPerBranch();
     return $extensions;
 }
 public function actionTeam()
 {
     $members = Yii::$app->params['members'];
     $activeMembers = [];
     $pastMembers = [];
     foreach ($members as $member) {
         if ($member['active']) {
             $activeMembers[] = $member;
         } else {
             $pastMembers[] = $member;
         }
     }
     $activeMembers = RowHelper::split($activeMembers, 3);
     $pastMembers = RowHelper::split($pastMembers, 3);
     $contributorLimit = 1000;
     // getting contributors from github
     try {
         $cacheKey = __CLASS__ . ":team:contributors:{$contributorLimit}";
         if (($contributors = Yii::$app->cache->get($cacheKey)) === false) {
             $client = new \Github\Client();
             $api = $client->api('repo');
             $paginator = new \Github\ResultPager($client);
             $parameters = ['yiisoft', 'yii2'];
             $contributors = $paginator->fetch($api, 'contributors', $parameters);
             while ($paginator->hasNext() && count($contributors) < $contributorLimit) {
                 $contributors = array_merge($contributors, $paginator->fetchNext());
             }
             // remove team members
             $teamGithubs = array_filter(array_map(function ($member) {
                 return isset($member['github']) ? $member['github'] : false;
             }, $members));
             foreach ($contributors as $key => $contributor) {
                 if (in_array($contributor['login'], $teamGithubs)) {
                     unset($contributors[$key]);
                 }
             }
             $contributors = array_slice($contributors, 0, $contributorLimit);
             Yii::$app->cache->set($cacheKey, $contributors, 3600 * 12);
             // cache for 12hours
         }
     } catch (\Exception $e) {
         $contributors = false;
     }
     return $this->render('team', ['activeMembers' => $activeMembers, 'pastMembers' => $pastMembers, 'contributors' => $contributors]);
 }
function milestoneSort($a, $b)
{
    return strnatcasecmp($a['title'], $b['title']);
}
function labelSort($a, $b)
{
    return strnatcasecmp($a['name'], $b['name']);
}
function skipBecauseOfVersionConstraint($versionAdded, $milestoneOrLabelName)
{
    $version = explode('-', $milestoneOrLabelName)[0];
    return version_compare($versionAdded, $version) === 1;
}
$authentication = json_decode(file_get_contents('credentials.json'));
$client->authenticate($authentication->apikey, Github\Client::AUTH_URL_TOKEN);
$paginator = new Github\ResultPager($client);
$config = json_decode(file_get_contents('config.json'));
$repositories = [];
$updateDueDate = [];
$SHOW_MILESTONE = true;
$SHOW_LABEL = true;
foreach ($config->repos as $repo) {
    $repositories[$repo] = ['milestones' => [], 'labels' => []];
    print 'Repo ' . $config->org . '/' . $repo . PHP_EOL;
    if ($SHOW_MILESTONE) {
        print "  Milestones" . PHP_EOL;
    }
    $milestones = $client->api('issue')->milestones()->all($config->org, $repo);
    uasort($milestones, 'milestoneSort');
    foreach ($milestones as $milestone) {
        $repositories[$repo]['milestones'][$milestone['title']] = $milestone;
 private function _get_milestone_info($number)
 {
     $paginator = new Github\ResultPager($this->client);
     $issues = $paginator->fetchAll($this->client->api('issue'), 'all', array($this->org, $this->repo, array('milestone' => $number, 'state' => 'all')));
     return $issues;
 }
Exemple #6
0
     }
     $repo->push("origin", "master");
     freepbx::out("Done");
     freepbx::outn("Checking you out into release/" . $options['updatemaster'] . "...");
     $repo->checkout("release/" . $options['updatemaster']);
     freepbx::out("Done");
 }
 $organizationApi = $client->api('organization');
 $paginator = new Github\ResultPager($client);
 $parameters = array('freepbx');
 $repos = $paginator->fetchAll($organizationApi, 'repositories', $parameters);
 $core = array();
 foreach ($repos as $repo) {
     $core[] = $repo['name'];
 }
 $paginator = new Github\ResultPager($client);
 $parameters = array('FreePBX-ContributedModules');
 $repos = $paginator->fetchAll($organizationApi, 'repositories', $parameters);
 $contrib = array();
 foreach ($repos as $repo) {
     $contrib[] = $repo['name'];
 }
 if (in_array($rawname, $core)) {
     $org = "freepbx";
 } elseif (in_array($rawname, $contrib)) {
     $org = "FreePBX-ContributedModules";
 } else {
     exit;
 }
 $repo = $client->api('repo')->update($org, $rawname, array('name' => $rawname, 'description' => "Module of FreePBX (" . trim($name) . ") :: " . trim(strip_tags(str_replace(array("\r", "\n"), '', $description))), 'default_branch' => 'release/13.0', 'homepage' => 'http://www.freepbx.org', "has_issues" => false, "has_wiki" => false, "had_downloads" => false));
 break;
 /**
  * Generates contributor data and avatars
  * @return success or fail
  */
 public function actionGenerate()
 {
     if (!$this->acquireMutex()) {
         $this->stderr("Execution terminated: command is already running.\n", Console::FG_RED);
         return self::EXIT_CODE_ERROR;
     }
     $members = Yii::$app->params['members'];
     $contributors = array();
     $raw_contributors = array();
     $contributorLimit = 1000;
     // getting contributors from github
     try {
         $client = new \Github\Client();
         $token_file = Yii::getAlias('@app/data') . '/github.token';
         if (file_exists($token_file)) {
             $this->stdout("Authenticating with Github token.\n");
             $token = file_get_contents($token_file);
             $client->authenticate($token, null, \Github\Client::AUTH_URL_TOKEN);
         }
         $api = $client->api('repo');
         $paginator = new \Github\ResultPager($client);
         $parameters = ['yiisoft', 'yii2'];
         $raw_contributors = $paginator->fetch($api, 'contributors', $parameters);
         while ($paginator->hasNext() && count($raw_contributors) < $contributorLimit) {
             $raw_contributors = array_merge($raw_contributors, $paginator->fetchNext());
         }
         // remove team members
         $teamGithubs = array_filter(array_map(function ($member) {
             return isset($member['github']) ? $member['github'] : false;
         }, $members));
         foreach ($raw_contributors as $key => $raw_contributor) {
             if (in_array($raw_contributor['login'], $teamGithubs)) {
                 unset($raw_contributors[$key]);
             }
         }
         $raw_contributors = array_slice($raw_contributors, 0, $contributorLimit);
     } catch (\Exception $e) {
         $raw_contributors = false;
     }
     if ($raw_contributors) {
         foreach ($raw_contributors as $raw_contributor) {
             $contributor = array();
             $contributor['login'] = $raw_contributor['login'];
             $contributor['avatar_url'] = $raw_contributor['avatar_url'];
             $contributor['html_url'] = $raw_contributor['html_url'];
             $contributor['contributions'] = $raw_contributor['contributions'];
             $contributors[] = $contributor;
         }
     }
     // save 'contributors.json' in the data directory
     $data_dir = Yii::getAlias('@app/data');
     file_put_contents($data_dir . DIRECTORY_SEPARATOR . 'contributors.json', json_encode($contributors, JSON_PRETTY_PRINT));
     // Generate avatar thumbnails and store them in data/avatars
     $thumbnail_dir = $data_dir . DIRECTORY_SEPARATOR . 'avatars';
     if (!is_dir($thumbnail_dir)) {
         FileHelper::createDirectory($thumbnail_dir);
     }
     $imagine = new Imagine();
     $mode = ImageInterface::THUMBNAIL_OUTBOUND;
     $size = new \Imagine\Image\Box(48, 48);
     foreach ($contributors as $contributor) {
         $login = $contributor['login'];
         // Check if the file exists and there are no errors
         $headers = get_headers($contributor['avatar_url'], 1);
         $code = isset($headers[1]) ? explode(' ', $headers[1]) : explode(' ', $headers[0]);
         $code = next($code);
         if ($code != 404 and $code != 403 and $code != 400 and $code != 500) {
             // the image url seems to be good, save the thumbnail
             $this->stdout("Saving {$login}.png\n");
             $imagine->open($contributor['avatar_url'])->thumbnail($size, $mode)->save($thumbnail_dir . DIRECTORY_SEPARATOR . $login . '.png');
         } else {
             //TODO: default avatar thumbnail?
             $this->stdout("Avatar {$login}.png was not found\n");
         }
     }
     if (YII_ENV_DEV) {
         exec('gulp sprites && gulp styles', $output, $ret);
     } else {
         exec('gulp sprites && gulp styles --production', $output, $ret);
     }
     $this->releaseMutex();
     return self::EXIT_CODE_NORMAL;
 }
Exemple #8
0
<?php

ini_set("memory_limit", "256M");
// doing this is annoying but heh I've not got a better method *yet*
require_once __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('UTC');
// compulsory thing to stop errors
$app = new Silex\Application();
$app["debug"] = true;
// you'll want to turn this to false in production
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    // declare php-github clients
    $client = new \Github\Client($client);
    $paginator = new Github\ResultPager($client);
    // get .env file and load the token from it
    Dotenv::load(__DIR__ . '/../');
    $token = getenv('GITHUB_TOKEN');
    // authenticate with github
    $client->authenticate($token, Github\Client::AUTH_HTTP_TOKEN);
    // get the user and the user repositories
    $user = $client->api('organization')->show('purplapp');
    $repositories = $client->api('repo')->show('purplapp', 'purplapp');
    $repo_contributors = $client->api('repo')->contributors('purplapp', 'purplapp', false);
    // get the languages used in the repository
    $repo_language = $client->api('repo')->languages('purplapp', 'purplapp');
    // $repo_language = new LanguageCollection($repo_language);
    // get the pull requests for the repository
    $repo_pull = $client->api('pull_request')->all('purplapp', 'purplapp', array('state' => 'all'));
    $repo_pull_comments_response = $client->getHttpClient()->get('/repos/purplapp/purplapp/comments');
    $repo_pull_comments = Github\HttpClient\Message\ResponseMediator::getContent($repo_pull_comments_response);
Exemple #9
0
 /**
  * コメントを取得する
  *
  * PR内のファイルに対するもの、PR自体に対するもの、両方を取得しマージする
  *
  * @param  int   $pr_number  PR番号
  * @return array $return_arr GithubAPI-Commentのレスポンスと、追加情報を含む配列
  */
 public function getComments($pr_number, $mode = self::COMMENT_GET_ALL)
 {
     // コメントは30個でページングされるため、それらを一気に取得するためのインスタンスを生成する
     $pager = new \Github\ResultPager($this->client);
     // コメントを取得する (PR内のファイルに対するもの)
     $pr_comments = [];
     if (self::COMMENT_GET_ALL === $mode or self::COMMENT_GET_FILE === $mode) {
         $pr_comments = $pager->fetchAll($this->client->api('pull_request')->comments(), 'all', array($this->repo_owner, $this->repo_name, $pr_number));
     }
     // コメントを取得する (PR自体に対するもの)
     $issue_comments = [];
     if (self::COMMENT_GET_ALL === $mode or self::COMMENT_GET_PR === $mode) {
         $issue_comments = $pager->fetchAll($this->client->api('issue')->comments(), 'all', array($this->repo_owner, $this->repo_name, $pr_number));
     }
     // コメントをマージして、日付昇順にする
     $comment_arr = array_merge($pr_comments, $issue_comments);
     usort($comment_arr, 'self::dateAscSort');
     // 情報を追加する
     $is_new = true;
     $review_status = 0;
     $return_arr = [];
     foreach ($comment_arr as $comment) {
         if (1 === preg_match(GITHUB_PATTERN_IGNORE_USER, $comment['user']['login'])) {
             // このユーザのコメントは無視する
             continue;
         }
         $is_agree = $is_reset = $is_deco = false;
         if (isset($comment['diff_hunk'])) {
             // PR内のファイルに対するものであるとき
             $type = 'file';
         } else {
             // PR自体に対するものであるとき
             $type = 'pr';
             if (1 === preg_match(GITHUB_PATTERN_AGREE, $comment['body'])) {
                 $is_agree = true;
                 $review_status += 1;
             }
             if (1 === preg_match(GITHUB_PATTERN_RESET_AGREE, $comment['body'])) {
                 $is_reset = true;
                 $review_status = 0;
             }
             if (1 === preg_match(GITHUB_PATTERN_SHOW_URL, $comment['body'])) {
                 $is_deco = true;
             }
         }
         $return_arr[] = ['is_new' => $is_new, 'is_decorate' => $is_deco, 'is_agree' => $is_agree, 'is_reset' => $is_reset, 'review_status' => $review_status, 'type' => $type, 'content' => $comment];
         $is_new = false;
     }
     return $return_arr;
 }
$handle = fopen('php://stdin', 'r');
$auth['password'] = trim(fgets($handle));
echo PHP_EOL;
echo 'Now tell us what repo you want to get issues for (e.g. kieranajp/github-issues): ';
$repo = fgets($handle);
$ex = explode('/', $repo);
if (count($ex) !== 2) {
    throw new Exception('Invalid repository name');
    exit;
}
// Convert the user's input to stdObjects so they're more fun
$repo = (object) ['owner' => trim($ex[0]), 'name' => trim($ex[1])];
$auth = (object) $auth;
// Authenticate (so that we can see private repos)
$client = new \Github\Client();
$paginator = new \Github\ResultPager($client);
try {
    $client->authenticate($auth->username, $auth->password, \Github\Client::AUTH_HTTP_PASSWORD);
    $issueApi = $client->api('issue');
    $issues = [];
    // Get the closed issues first - limited to 30
    $issues['closed'] = $issueApi->all($repo->owner, $repo->name, ['state' => 'closed']);
    // Get all the open issues
    $issues['open'] = $paginator->fetchAll($issueApi, 'all', [$repo->owner, $repo->name, ['state' => 'open']]);
} catch (Github\Exception\RuntimeException $e) {
    echo 'Error: ' . $e->getMessage();
    exit;
}
echo PHP_EOL;
echo sprintf('%s open and %s closed issues pulled…', (string) count($issues['open']), (string) count($issues['closed']));
// Set up the header rows for the CSV