public function get_issues($options = array())
 {
     $options = empty($options) ? array() : $options;
     #if zero attributes passed, $options = ''
     $default_options = array('labels' => '', 'state' => 'open', 'page' => $this->page, 'per_page' => NULL, 'show_body' => FALSE);
     $params = array_merge($default_options, $options);
     $paginator = new Github\ResultPager($this->client);
     try {
         if (!empty($params['per_page'])) {
             $issues = $paginator->fetch($this->client->api('issue'), 'all', array($this->org, $this->repo, $params));
         } else {
             $issues = $paginator->fetchAll($this->client->api('issue'), 'all', array($this->org, $this->repo, $params));
             $issues = apply_filters('github_issues_list', $issues);
         }
     } catch (Exception $e) {
         echo "Error! " . $e->getMessage();
         return;
     }
     $this->has_next_page = $paginator->hasNext();
     $this->has_prev_page = $paginator->hasPrevious();
     return $issues;
 }
 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]);
 }
 /**
  * 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;
 }