Example #1
0
 public function getActivity(Request $request)
 {
     $me = GitHub::me()->show();
     $lastEventId = $request->session()->get('last_notification_id', false);
     $activity = [];
     $interval = 60;
     if ($lastEventId) {
         list($interval, $activity) = $this->findNewActivity($me['login'], $lastEventId);
         if ($activity) {
             $request->session()->set('last_notification_id', $activity[0]['id']);
             // Mark as read
             try {
                 GitHub::notification()->markRead();
             } catch (\Exception $e) {
                 // Github returns empty string for this endpoint but the API library tries to parse it as json
             }
             foreach ($activity as &$notice) {
                 $notice['html_url'] = $this->getRelatedHtmlUrl($notice['subject']);
             }
         }
     }
     $html = view('notifications.live', ['me' => $me, 'activity' => $activity]);
     $data = ['activity' => $html->render(), 'interval' => (int) $interval * 1000, 'count' => count($activity)];
     $response = \Illuminate\Support\Facades\Response::make(json_encode($data), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
Example #2
0
 public function showIndex()
 {
     $me = GitHub::me()->show();
     $paginator = new ResultPager(GitHub::connection());
     $repositories = $paginator->fetchAll(GitHub::me(), 'repositories');
     $organizations = $paginator->fetchAll(GitHub::me(), 'organizations');
     $this->getIssuesAndPRs($repositories, $me, $me);
     foreach ($organizations as &$org) {
         $paginator = new ResultPager(GitHub::connection());
         $org['repositories'] = $paginator->fetchAll(GitHub::organization(), 'repositories', [$org['login'], ['sort' => '']]);
         usort($org['repositories'], function ($a, $b) {
             return strnatcasecmp($a['name'], $b['name']);
         });
         $this->getIssuesAndPRs($org['repositories'], $org, $me);
     }
     return view('repositories.index', ['me' => $me, 'repos' => $repositories, 'orgs' => $organizations, 'rateLimits' => $this->getRateLimit()]);
 }
Example #3
0
 /**
  * Creating a record in db for current user, if it doesn't exist
  * @return bool
  */
 private function createGhUser()
 {
     $cur_user = GitHub::me()->show();
     /**
      * Define cur_user_id constant for the namespace vyze\ghpb
      */
     define('cur_gh_user_id', $cur_user['id']);
     if ($cur_user && !GhUserModel::find($cur_user['id'], array('id'))) {
         $ghpb_user = new GhUserModel();
         $ghpb_user->id = $cur_user['id'];
         $ghpb_user->username = $cur_user['login'];
         if (array_key_exists('name', $cur_user)) {
             $ghpb_user->name = $cur_user['name'];
         }
         return $ghpb_user->save();
     }
 }
Example #4
0
 public function showIndex(Request $request, $page = 1)
 {
     $me = GitHub::me()->show();
     /** @var Response $response */
     $response = GitHub::connection()->getHttpClient()->get(sprintf('/users/%s/received_events?page=%s', $me['login'], (int) $page));
     $activity = ResponseMediator::getContent($response);
     $pagination = $this->getPagination($response);
     $pending = Input::get('pending', 0);
     // Save the latest activity ID for live fetching
     if (count($activity)) {
         $request->session()->put('last_event_id', $activity[0]['id']);
         $this->parseActivity($activity, $me, $pending);
     }
     // Get the interval Github allows for polling
     $interval = $response->hasHeader('X-Poll-Interval') ? (string) $response->getHeader('X-Poll-Interval') : 60;
     return view('activity.index', ['me' => $me, 'activity' => $activity, 'pagination' => $pagination, 'page' => $page, 'interval' => (int) $interval * 1000, 'pending' => $pending]);
 }
 public function dashboard()
 {
     $noteCount = Note::count();
     $pullRequests = [];
     $issues = Cache::remember('github-issues', 20, function () {
         return GitHub::me()->issues();
     });
     for ($i = 0; $i < count($issues); $i++) {
         if (isset($issues[$i]['pull_request'])) {
             $pullRequests[] = $issues[$i];
             unset($issues[$i]);
         }
     }
     $issues = array_values($issues);
     // to normalize array keys
     return view('home.dashboard', ['pageTitle' => 'Dashboard'])->with(['noteCount' => $noteCount, 'issues' => $issues, 'pullRequests' => $pullRequests]);
 }
Example #6
0
 public function getActivity(Request $request)
 {
     $me = GitHub::me()->show();
     $lastEventId = $request->session()->get('last_event_id', false);
     $activity = [];
     $interval = 60;
     if ($lastEventId) {
         list($interval, $activity) = $this->findNewActivity($me['login'], $lastEventId);
         if ($activity) {
             $request->session()->set('last_event_id', $activity[0]['id']);
             $this->parseActivity($activity, $me, Input::get('pending', 0));
         }
     }
     $html = view('activity.live', ['me' => $me, 'activity' => $activity]);
     $data = ['activity' => $html->render(), 'interval' => (int) $interval * 1000, 'count' => count($activity)];
     $response = \Illuminate\Support\Facades\Response::make(json_encode($data), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
Example #7
0
 public function showIndex(Request $request, $page = 1)
 {
     $me = GitHub::me()->show();
     /** @var Response $response */
     $activity = GitHub::notification()->all();
     // Save the latest activity ID for live fetching
     if (count($activity)) {
         $request->session()->put('last_notification_id', $activity[0]['id']);
         // Mark as read
         try {
             GitHub::notification()->markRead();
         } catch (\Exception $e) {
             // Github returns empty string for this endpoint but the API library tries to parse it as json
         }
         foreach ($activity as &$notice) {
             $notice['html_url'] = $this->getRelatedHtmlUrl($notice['subject']);
         }
     }
     // Get the interval Github allows for polling
     $response = GitHub::connection()->getHttpClient()->getLastResponse();
     $interval = $response->hasHeader('X-Poll-Interval') ? (string) $response->getHeader('X-Poll-Interval') : 60;
     return view('notifications.index', ['me' => $me, 'activity' => $activity, 'page' => $page, 'interval' => (int) $interval * 1000]);
 }
Example #8
0
 /**
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function index()
 {
     $lastFm = new LastFm(env('LFM_KEY'), env('LFM_SECRET'));
     return view('index', ['repos' => collect(GitHub::me()->repositories()), 'lastfm' => $lastFm->user_getRecentTracks(['limit' => 10, 'user' => 'jaaaaaaaaaam'])]);
 }