Esempio n. 1
0
 public function showIndex($login, $repo)
 {
     $repoInfo = GitHub::repos()->show($login, $repo);
     if ($repoInfo['fork']) {
         $pullFrom = $repoInfo['parent']['owner']['login'];
         $defaultBranch = $repoInfo['parent']['default_branch'];
     } else {
         $pullFrom = $login;
         $defaultBranch = $repoInfo['default_branch'];
     }
     if ($pullFrom != $login) {
         // Get pulls requests from issue list
         $pulls = [];
         $paginator = new ResultPager(GitHub::connection());
         $issues = $paginator->fetchAll(GitHub::issues(), 'all', [$pullFrom, $repo, ['creator' => $repoInfo['owner']['login']]]);
         foreach ($issues as $issue) {
             if (isset($issue['pull_request'])) {
                 $pull = GitHub::pullRequest()->show($pullFrom, $repo, $issue['number']);
                 $pulls[$pull['head']['ref']][] = $pull;
             }
         }
     }
     // Get branches for this repo
     $branches = GitHub::gitData()->references()->branches($login, $repo);
     foreach ($branches as &$branch) {
         $branch['name'] = str_replace('refs/heads/', '', $branch['ref']);
         if ($pullFrom == $login) {
             $branch['pulls'] = GitHub::pullRequests()->all($pullFrom, $repo, ['base' => $branch['name']]);
         } else {
             $branch['pulls'] = isset($pulls[$branch['name']]) ? $pulls[$branch['name']] : [];
         }
     }
     return view('branches.index', ['login' => $login, 'repo' => $repo, 'branches' => $branches, 'rateLimits' => $this->getRateLimit(), 'defaultBranch' => $defaultBranch]);
 }
 protected function getRelatedHtmlUrl($subject)
 {
     /** @var Response $response */
     $response = GitHub::connection()->getHttpClient()->get($subject['latest_comment_url']);
     $subjectData = ResponseMediator::getContent($response);
     return $subjectData['html_url'];
 }
Esempio n. 3
0
 /**
  * @param     $login
  * @param     $lastEventId
  * @param int $page
  *
  * @return array
  */
 private function findNewActivity($login, $lastEventId, $page = 1)
 {
     /** @var Response $response */
     $response = GitHub::connection()->getHttpClient()->get(sprintf('/users/%s/received_events?page=%s', $login, (int) $page));
     // Get the interval Github allows for polling
     $interval = $response->hasHeader('X-Poll-Interval') ? (string) $response->getHeader('X-Poll-Interval') : 60;
     $activity = ResponseMediator::getContent($response);
     $pagination = ResponseMediator::getPagination($response);
     $isLastPage = empty($pagination['next']);
     $caughtUp = false;
     $newActivity = [];
     foreach ($activity as $event) {
         if ($event['id'] == $lastEventId) {
             $caughtUp = true;
             break;
         }
         $newActivity[] = $event;
     }
     if (!$caughtUp && !$isLastPage) {
         // Try the next page
         list($interval, $activity) = $this->findNewActivity($login, $lastEventId, $page + 1);
         $newActivity += $activity;
     }
     return [$interval, $newActivity];
 }
Esempio n. 4
0
 /**
  * Get user's data through graham-campbell\github
  * @param string $name
  */
 public static function getUser($name)
 {
     $user = GitHub::users()->show($name);
     $user['title'] = 'User';
     $user['show_repo_user'] = false;
     //check liked
     self::addLikeAttributes($user, true);
     return $user;
 }
Esempio n. 5
0
 public function getRateLimit()
 {
     $rateLimits = GitHub::api('rate_limit')->getRateLimits();
     $limits = $rateLimits['resources']['core'];
     $dateTime = new \DateTime();
     $dateTime->setTimestamp($limits['reset']);
     $limits['reset_at'] = $dateTime;
     return $limits;
 }
Esempio n. 6
0
 /**
  * Search repositories through graham-campbell\github
  * @param string $query
  */
 public static function getSearched($query = '')
 {
     $q_fomated = str_replace(' ', '+', trim($query));
     //search result
     $list = GitHub::repo()->find($q_fomated);
     $repositories = $list['repositories'];
     //check likes
     self::addLikeAttributes($repositories);
     return $repositories;
 }
Esempio n. 7
0
 public function deleteBranch($login, $repo, $branch)
 {
     $data = ['success' => 0];
     try {
         GitHub::gitData()->references()->remove($login, $repo, 'heads/' . $branch);
         $data['success'] = 1;
     } catch (RuntimeException $exception) {
         $data['error'] = $exception->getMessage();
     }
     $response = Response::make(json_encode($data), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
Esempio n. 8
0
 /**
  * @param     $login
  * @param     $lastEventId
  * @param int $page
  *
  * @return array
  */
 private function findNewActivity($login, $lastEventId, $page = 1)
 {
     /** @var Response $response */
     $response = GitHub::connection()->getHttpClient()->get(sprintf('/notifications?page=%s', $login, (int) $page));
     // Get the interval Github allows for polling
     $interval = $response->hasHeader('X-Poll-Interval') ? (string) $response->getHeader('X-Poll-Interval') : 60;
     $activity = ResponseMediator::getContent($response);
     $newActivity = [];
     foreach ($activity as $event) {
         if ($event['id'] == $lastEventId) {
             break;
         }
         $newActivity[] = $event;
     }
     return [$interval, $newActivity];
 }
 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]);
 }
Esempio n. 10
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]);
 }
Esempio n. 11
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();
     }
 }
Esempio n. 12
0
 public function reply($login, $repo, $issue)
 {
     $data = ['success' => 0];
     if (Request::isMethod('post')) {
         $body = trim(Input::get('reply'));
         if ($body) {
             try {
                 GitHub::issue()->comments()->create($login, $repo, $issue, ['body' => $body]);
                 $data['success'] = 1;
             } catch (RuntimeException $exception) {
                 $data['error'] = $exception->getMessage();
             }
         }
     }
     $response = Response::make(json_encode($data), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
Esempio n. 13
0
 /**
  * @param $repositories
  * @param $org
  * @param $me
  */
 private function getIssuesAndPRs(&$repositories, $org, $me)
 {
     foreach ($repositories as &$repo) {
         // Get pulls requests from issue list
         $pulls = [];
         $issues = [];
         $paginator = new ResultPager(GitHub::connection());
         $allIssues = $paginator->fetchAll(GitHub::issues(), 'all', [$org['login'], $repo['name'], ['creator' => $me['login']]]);
         foreach ($allIssues as $issue) {
             if (isset($issue['pull_request'])) {
                 $pulls[] = $issue;
             } else {
                 $issues[] = $issue;
             }
         }
         $repo['issues'] = $issues;
         $repo['pulls'] = $pulls;
     }
 }
Esempio n. 14
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]);
 }
Esempio n. 15
0
});
/**
 * Get the code for their oAuth token
 */
Route::get('github/login', function () {
    SocialAuth::login('github', function ($user, $userDetails) {
        $user->email = $userDetails->email;
        $user->nickname = $userDetails->nickname;
        $user->full_name = $userDetails->full_name;
        $user->avatar = $userDetails->avatar;
        $user->save();
    });
    // Current user is now available via Auth facade
    $user = Auth::user();
    $data = array('fullname' => $user->full_name, 'nickname' => $user->nickname, 'avatar' => $user->avatar);
    // Get the repos for the authenticated user
    $repos = GitHub::user()->repositories($user->nickname);
    return view('dashboard')->with(['data' => $data, 'repos' => $repos]);
});
/**
 * For SSL
 */
Route::get('github/authorize', function () {
    return SocialAuth::authorize('github');
});
/**
 * Ember app stuff
 */
Route::get('{data?}', function () {
    return View::make('app');
})->where('data', '.*');
 public function generate($login, $repo, $milestone)
 {
     // Find the milestone number by fetching all milestones
     $paginator = new ResultPager(GitHub::connection());
     $milestones = $paginator->fetchAll(GitHub::issues()->milestones(), 'all', [$login, $repo]);
     // Fetch the issues for this milestone
     $milestoneIssues = [];
     foreach ($milestones as $result) {
         if ($milestone == $result['title']) {
             $milestoneIssues = $paginator->fetchAll(GitHub::issues(), 'all', [$login, $repo, ['milestone' => $result['number'], 'state' => 'all']]);
             $milestone = $result;
             break;
         }
     }
     $prs = [];
     $team = explode(',', $_SERVER['GITHUB_HIDE_AUTHORS']);
     foreach ($milestoneIssues as $k => $issue) {
         if (isset($issue['pull_request']) && $issue['state'] !== 'closed') {
             $needsDocumentation = false;
             $hasConflicts = false;
             $status = false;
             foreach ($issue['labels'] as $label) {
                 switch (true) {
                     case 'Pending Test Confirmation' == $label['name']:
                         $status = 'Pending Test Confirmation';
                         break;
                     case 'Code Review' == $label['name']:
                         $status = 'Code Review';
                         break;
                     case 'Pending Feedback' == $label['name']:
                         $status = 'Pending Feedback';
                         break;
                     case 'Ready To Commit' == $label['name']:
                         $status = "Ready To Commit";
                         break;
                 }
                 if ('Needs Documentation' == $label['name']) {
                     $needsDocumentation = true;
                 }
                 if ($status) {
                     break;
                 }
             }
             if (!$status) {
                 $status = 'Needs Testing';
             }
             $pull = GitHub::pullRequest()->show($login, $repo, $issue['number']);
             if (empty($pull['mergeable'])) {
                 $hasConflicts = true;
             }
             $plusOne = [];
             $feedBackBy = [];
             $comments = $event['comments'] = GitHub::issue()->comments()->all($login, $repo, $issue['number']);
             foreach ($comments as $comment) {
                 if (in_array($comment['user']['login'], $team)) {
                     if (strpos($comment['body'], '+1') !== false) {
                         $plusOne[] = $comment['user']['login'];
                     }
                     $feedBackBy[$comment['user']['login']] = $comment['user']['login'];
                 }
             }
             $prs[$issue['number']] = ['author' => $issue['user']['login'], 'name' => $issue['title'], 'link' => $issue['html_url'], 'status' => $status, 'hasConflicts' => $hasConflicts, 'needsDocs' => $needsDocumentation, 'plusOne' => $plusOne, 'feedbackBy' => $feedBackBy];
         }
     }
     uasort($prs, function ($a, $b) {
         return strnatcasecmp($a['author'], $b['author']);
     });
     return view('milestones.analyasis', ['login' => $login, 'repo' => $repo, 'milestone' => $milestone, 'pullRequests' => $prs, 'rateLimits' => $this->getRateLimit()]);
 }
Esempio n. 17
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'])]);
 }
Esempio n. 18
0
 public function parseActivity(array &$activity, $me, $pending = false)
 {
     foreach ($activity as &$event) {
         // Get the related PR
         list($login, $repo) = explode('/', $event['repo']['name']);
         $event['repo_owner'] = $login;
         $event['repo_name'] = $repo;
         $number = null;
         $isPr = false;
         switch (true) {
             case isset($event['payload']['issue']['pull_request']):
                 $number = $event['payload']['issue']['number'];
                 $isPr = true;
                 break;
             case isset($event['payload']['pull_request']['number']):
                 $number = $event['payload']['pull_request']['number'];
                 $isPr = true;
                 break;
             case isset($event['payload']['issue']['number']):
                 $number = $event['payload']['issue']['number'];
                 $event['state'] = $event['payload']['issue']['state'];
                 break;
         }
         if ($number) {
             if ($isPr) {
                 // Get the latest info on the PR and not what's cached with the activity
                 $event['pull_request'] = GitHub::pullRequest()->show($login, $repo, $number);
                 $event['state'] = $event['pull_request']['state'];
                 if (isset($event['payload']['issue']['pull_request'])) {
                     $event['payload']['issue']['pull_request'] =& $event['pull_request'];
                 } else {
                     $event['payload']['pull_request'] =& $event['pull_request'];
                 }
             } else {
                 // Get the latest info on the PR and not what's cached with the activity
                 $event['payload']['issue'] = GitHub::issue()->show($login, $repo, $number);
             }
             // Get list of comments
             $event['comments'] = GitHub::issue()->comments()->all($login, $repo, $number);
             if (count($event['comments'])) {
                 // Order by latest first
                 $event['comments'] = array_reverse($event['comments']);
                 // Did I comment last?
                 $event['user_last_replied'] = $event['comments'][0]['user']['login'];
                 // Get set the payload comment with updated version if applicable
                 if (isset($event['payload']['comment'])) {
                     foreach ($event['comments'] as $comment) {
                         if ($comment['id'] === $event['payload']['comment']['id']) {
                             $event['payload']['comment'] = $comment;
                             break;
                         }
                     }
                 }
             }
         }
         // Check for labels and set font color
         if (isset($event['payload']['issue']['labels'])) {
             foreach ($event['payload']['issue']['labels'] as &$label) {
                 $label['is_light'] = $this->isLightColor($label['color']);
             }
         } elseif (isset($event['payload']['pull_request']['labels'])) {
             foreach ($event['payload']['pull_request']['labels'] as &$label) {
                 $label['is_light'] = $this->isLightColor($label['color']);
             }
         }
     }
     if ($pending) {
         // Filter out those that have not been addressed by me yet
         foreach ($activity as $k => $event) {
             if (!isset($event['state']) || $event['state'] != 'open' || !isset($event['comments']) || !isset($event['user_last_replied']) || $event['user_last_replied'] == $me['login']) {
                 unset($activity[$k]);
             }
         }
     }
 }
Esempio n. 19
0
 public function test()
 {
     return GH::repo()->contents()->show('GrahamCampbell', 'Laravel-GitHub', '/', 'master');
 }
Esempio n. 20
0
 public function generate($login, $repo, $milestone)
 {
     // Find the milestone number by fetching all milestones
     $paginator = new ResultPager(GitHub::connection());
     $milestones = $paginator->fetchAll(GitHub::issues()->milestones(), 'all', [$login, $repo]);
     // Fetch the issues for this milestone
     $milestoneIssues = [];
     foreach ($milestones as $result) {
         if ($milestone == $result['title']) {
             $milestoneIssues = $paginator->fetchAll(GitHub::issues(), 'all', [$login, $repo, ['milestone' => $result['number'], 'state' => 'all']]);
             break;
         }
     }
     $pullRequests = [];
     $issues = [];
     $acknowledgements = [];
     $labels = [];
     $hideAuthors = explode(',', $_SERVER['GITHUB_HIDE_AUTHORS']);
     $labelGroups = explode(',', $_SERVER['GITHUB_LABELS']);
     foreach ($labelGroups as &$label) {
         list($labelName, $groupName) = explode('|', $label);
         $labels[$labelName] = $groupName;
     }
     $defaultGroup = $labels[$_SERVER['GITHUB_DEFAULT_GROUP']];
     foreach ($milestoneIssues as $k => $issue) {
         $issue['submitter'] = in_array($issue['user']['login'], $hideAuthors) ? '' : $issue['user']['login'];
         if (!empty($issue['submitter']) && !in_array('@' . $issue['submitter'], $acknowledgements)) {
             $acknowledgements[] = '@' . $issue['submitter'];
         }
         if (isset($issue['pull_request'])) {
             $labelFound = false;
             foreach ($issue['labels'] as $label) {
                 if (array_key_exists($label['name'], $labels)) {
                     $pullRequests[$labels[$label['name']]][] = $issue;
                     $labelFound = true;
                     break;
                 }
             }
             if (!$labelFound) {
                 $pullRequests[$defaultGroup][] = $issue;
             }
         } else {
             $labelFound = false;
             foreach ($issue['labels'] as $label) {
                 if (array_key_exists($label['name'], $labels)) {
                     $issues[$labels[$label['name']]][] = $issue;
                     $labelFound = true;
                     break;
                 }
             }
             if (!$labelFound) {
                 $issues[$defaultGroup][] = $issue;
             }
         }
     }
     // Sort by label order
     $pullRequests = array_merge(array_flip($labels), $pullRequests);
     $issues = array_merge(array_flip($labels), $issues);
     // Set acknowledgements
     natcasesort($acknowledgements);
     $acknowledgements = implode(', ', $acknowledgements);
     return view('milestones.changelog', ['login' => $login, 'repo' => $repo, 'milestone' => $milestone, 'pullRequests' => $pullRequests, 'issues' => $issues, 'acknowledgements' => $acknowledgements, 'rateLimits' => $this->getRateLimit()]);
 }