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]); }
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]); } } } }
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()]); }