/** * @param $organisation * @return array */ private function getStatistics($organisation) { $httpClient = new CachedHttpClient(); $githubClient = new GithubAPI($httpClient); $packagistClient = new PackagistApi(); $oregon = new Oregon($organisation, $githubClient, $packagistClient); $contributors = $oregon->getContributors(); $repositories = $githubClient->api('organization')->repositories($organisation); $downloads = $oregon->getDownloads(); $statistics = array('contributions' => Enumerable::from($contributors)->sum('$v["contributions"]'), 'contributors' => count($contributors), 'forks' => Enumerable::from($repositories)->sum('$v["forks_count"]'), 'watchers' => Enumerable::from($repositories)->sum('$v["watchers_count"]'), 'downloadstotal' => $downloads->getTotal(), 'downloadsmonthly' => $downloads->getMonthly()); return $statistics; }
public function run() { Makiavelo::puts("Starting update of approval ratings"); $projects = list_project(null, null, "published = 1"); foreach ($projects as $proj) { $proj_name = $proj->name; $usr_name = $proj->owner()->name; $dev = $proj->owner(); Makiavelo::puts("Querying Github for: {$usr_name} / {$proj_name}"); $data = GithubAPI::queryProjectData($usr_name, $proj_name); $total_pulls = 0; $total_merged_pulls = 0; foreach ($data->pulls as $pull) { $total_pulls++; if ($pull->merged_at) { $total_merged_pulls++; } } if ($total_pulls > 0) { $proj->pr_acceptance_rate = $total_merged_pulls / $total_pulls * 100; } else { $proj->pr_acceptance_ratec = -1; } Makiavelo::puts("Saving project..."); save_project($proj); } }
public function githubLoginAction() { $code = $this->request->getParam("code"); GithubAPI::requestWebAuth($code); $current_dev = GithubAPI::getCurrentUser(); $result = login_github_user($current_dev); GithubAPI::getUserRepos($current_dev['username']); if ($result['ok'] === true) { $this->redirect_to(home_root_path_path()); } else { $this->flash->error("Error authenticating against Github"); $this->redirect_to(home_root_path_path()); } }
public function run() { Makiavelo::puts("Starting update of urls"); $projects = list_project(null, null, "published =1"); foreach ($projects as $proj) { $proj_name = $proj->name; $dev = $proj->owner(); $usr_name = $dev->name; Makiavelo::puts("Querying Github for: {$usr_name} / {$proj_name}"); $data = GithubAPI::queryProjectData($usr_name, $proj_name); if (!isset($data->message)) { $proj->url = isset($data->html_url) ? $data->html_url : $data->url; } else { Makiavelo::puts("Project not found, unpublishing..."); $proj->published = 0; } Makiavelo::puts("Saving project..."); save_project($proj); } }
/** * Returns all the issues given an user, a repository and a status * * @param (usr) the GitHub username * @param (repo) the GitHub repository name * @param (status) could be open or closed * @return an array with issues. */ public static function getProjectIssues($usr, $repo, $status, $since = null) { if (self::$TOKEN == null) { self::$TOKEN = self::requestAuth(); } $repo = str_replace(".git", "", $repo); $issues_url = "https://api.github.com/repos/" . $usr . "/" . $repo . "/issues?state=" . $status . "&page=1&per_page=100"; if ($since != null) { $issues_url = $issues_url . "&since=" . $since . "T00:00:00Z"; } Makiavelo::info("Querying URL: " . $issues_url); $data = self::sendRequest($issues_url); return $data; }
private function queryGithub($usr, $repo) { return GithubAPI::queryProjectData($usr, $repo); }
/** Loads all projects and queries Githubs API for new data on stars and forks */ public function generateAction() { $projects = list_project(null, null, "published = 1"); Makiavelo::info("=== Starting stats process ==="); foreach ($projects as $proj) { $proj_name = $proj->name; $usr_name = $proj->owner()->name; $dev = $proj->owner(); Makiavelo::info("==== Querying for {$usr_name}/{$proj_name}"); Makiavelo::info("Last Update: " . $proj->updated_at); if (strstr($proj->updated_at, date("Y-m-d"))) { Makiavelo::info("Skiping project"); continue; //Avoid duplicated entries } $data = GithubAPI::queryProjectData($usr_name, $proj_name); //We update the dev's avatar if needed if ($data->owner->avatar_url != $dev->avatar_url) { $dev->avatar_url = $data->owner->avatar_url; save_developer($dev); } //Calculate the commits for today $commits_today = 0; $today = date("Y-m-d"); /* Makiavelo::info("========================"); Makiavelo::info(print_r($data->commits, true)); Makiavelo::info("========================"); exit(); */ foreach ($data->commits as $commit) { $commit_date = $commit->commit->committer->date; $commit_date = explode("T", $commit_date); $commit_date = $commit_date[0]; $pc = load_project_commit_where("sha = '" . $commit->sha . "'"); if ($pc == null) { //We make sure we haven't yet saved this commit $project_commit = new ProjectCommit(); $project_commit->project_id = $proj->id; $project_commit->committer = $commit->committer->login; $project_commit->commit_message = $commit->commit->message; $project_commit->sha = $commit->sha; $project_commit->commit_date = $commit_date; save_project_commit($project_commit); } if ($commit_date == $today) { $commits_today++; } } $new_pulls_today = $closed_pulls_today = $merged_pulls_today = 0; $total_pulls = 0; $total_merged_pulls = 0; foreach ($data->pulls as $pull) { $created_data = explode("T", $pull->created_at); $closed_data = explode("T", $pull->closed_at); $merged_data = explode("T", $pull->merged_at); $total_pulls++; if ($pull->merged_at) { $total_merged_pulls++; } if ($created_data[0] == $today) { $new_pulls_today++; } if ($closed_data[0] == $today) { $closed_pulls_today++; } if ($merged_data[0] == $today) { $merged_pulls_today++; } } if ($total_pulls > 0) { $proj->pr_acceptance_rate = $total_merged_pulls / $total_pulls * 100; } else { $proj->pr_acceptance_ratec = -1; } $delta_stars = $data->watchers - $proj->stars; $delta_forks = $data->forks - $proj->forks; //if($delta_stars != 0 || $delta_forks != 0) { Makiavelo::info("==== Delta found, saving..."); //We also update the project $proj->stars = $data->watchers; $proj->forks = $data->forks; $proj->readme = $data->readme; $proj->description = $data->description; $proj->open_issues = $data->open_issues; save_project($proj); $pd = new ProjectDelta(); $pd->forks = $data->forks; $pd->delta_forks = $delta_forks; $pd->open_issues = $data->open_issues; $pd->closed_issues = $data->closed_issues; $pd->stars = $data->watchers; $pd->delta_stars = $delta_stars; $pd->project_id = $proj->id; $pd->commits_count = $commits_today; $pd->new_pulls = $new_pulls_today; $pd->closed_pulls = $closed_pulls_today; $pd->merged_pulls = $merged_pulls_today; $pd->sample_date = date("Y-m-d H:i:s"); if (save_project_delta($pd)) { Makiavelo::info("===== Delta saved! "); Makiavelo::info(print_r($pd, true)); } else { Makiavelo::info("===== ERROR saving delta"); } //} delete_issues_by_project_id($proj->id); foreach ($data->open_issues_list as $issue) { $iss = new Issue(); $iss->title = $issue->title; $iss->body = MarkdownExtra::defaultTransform($issue->body); $iss->created_at = $issue->created_at; $iss->updated_at = $issue->updated_at; $iss->url = $issue->html_url; $iss->number = $issue->number; $iss->project_id = $proj->id; if (save_issue($iss)) { Makiavelo::info("===== Issue saved! "); } else { Makiavelo::info("===== ERROR saving issue::" . mysql_error()); } } } }
public function load() { $projects = list_project(); Makiavelo::info("=== Starting old stats process ==="); foreach ($projects as $proj) { $proj_name = $proj->name; $usr_name = $proj->owner()->name; Makiavelo::puts("==== Querying for {$usr_name}/{$proj_name}"); $g_data = GithubAPI::queryProjectData($usr_name, $proj_name); //Calculate the commits for today $data = array(); foreach ($g_data->commits as $commit) { $commit_date = $commit->commit->committer->date; $commit_date = explode("T", $commit_date); $commit_date = $commit_date[0]; $date_idx = intval(str_replace("-", "", $commit_date)); if (!isset($data[$date_idx]) || !isset($data[$date_idx]['commits'])) { $data[$date_idx] = array("commits" => 1); } else { $data[$date_idx]['commits']++; } } foreach ($g_data->pulls as $pull) { $created_data = explode("T", $pull->created_at); $closed_data = explode("T", $pull->closed_at); $merged_data = explode("T", $pull->merged_at); $created_idx = intval(str_replace("-", "", $created_data[0])); $merged_idx = intval(str_replace("-", "", $merged_data[0])); $closed_idx = intval(str_replace("-", "", $closed_data[0])); if (!isset($data[$created_idx]) || !isset($data[$created_idx]['new_pulls'])) { $data[$created_idx]['new_pulls'] = 1; } else { $data[$created_idx]['new_pulls']++; } if ($merged_idx != 0) { if (!isset($data[$merged_idx]) || !isset($data[$merged_idx]['merged_pulls'])) { $data[$merged_idx]['merged_pulls'] = 1; } else { $data[$merged_idx]['merged_pulls']++; } } if ($closed_idx != 0) { if (!isset($data[$closed_idx]) || !isset($data[$closed_idx]['closed_pulls'])) { $data[$closed_idx]['closed_pulls'] = 1; } else { $data[$closed_idx]['closed_pulls']++; } } } //Makiavelo::puts(print_r($data, true)); //exit; foreach ($data as $date => $stats) { $year = substr($date, 0, 4); $month = substr($date, 4, 2); $day = substr($date, 6, 2); $str_date = $year . "-" . $month . "-" . $day; Makiavelo::info("==== Delta found, saving..."); Makiavelo::puts("Saving delta for date: {$str_date}"); $pd = new ProjectDelta(); $pd->forks = -99; $pd->delta_forks = -99; $pd->stars = -99; $pd->delta_stars = -99; $pd->project_id = $proj->id; $pd->commits_count = isset($stats['commits']) ? $stats['commits'] : 0; $pd->new_pulls = isset($stats['new_pulls']) ? $stats['new_pulls'] : 0; $pd->closed_pulls = isset($stats['closed_pulls']) ? $stats['closed_pulls'] : 0; $pd->merged_pulls = isset($stats['merged_pulls']) ? $stats['merged_pulls'] : 0; $pd->sample_date = $str_date; if (save_project_delta($pd)) { Makiavelo::puts("===== Delta saved! "); } else { Makiavelo::puts("===== ERROR saving delta::" . mysql_error()); } } delete_issues_by_project_id($proj->id); foreach ($data->open_issues_list as $issue) { $iss = new Issue(); $iss->title = $issue->title; $iss->body = $issue->body; $iss->created_at = $issue->created_at; $iss->updated_at = $issue->updated_at; $iss->url = $issue->url; $iss->number = $issue->number; $iss->project_id = $proj->id; if (save_issue($iss)) { Makiavelo::info("===== Issue saved! "); } else { Makiavelo::info("===== ERROR saving issue::" . mysql_error()); } } } }
public function grabHistoricData() { $proj_name = $this->name; $usr_name = $this->owner()->name; Makiavelo::info("==== Querying for {$usr_name}/{$proj_name}"); $g_data = GithubAPI::queryProjectData($usr_name, $proj_name); $this->readme = $g_data->readme; //Makiavelo::puts("Updating project..."); save_project($this); $data = array(); foreach ($g_data->commits as $commit) { $commit_date = $commit->commit->committer->date; $commit_date = explode("T", $commit_date); $commit_date = $commit_date[0]; $date_idx = intval(str_replace("-", "", $commit_date)); if (!isset($data[$date_idx]) || !isset($data[$date_idx]['commits'])) { $data[$date_idx] = array("commits" => 1); } else { $data[$date_idx]['commits']++; } $pc = load_project_commit_where("sha = '" . $commit->sha . "'"); if ($pc == null) { //We make sure we haven't yet saved this commit $project_commit = new ProjectCommit(); $project_commit->project_id = $this->id; $project_commit->committer = $commit->committer->login; $project_commit->commit_message = $commit->commit->message; $project_commit->sha = $commit->sha; $project_commit->commit_date = $commit_date; save_project_commit($project_commit); } } foreach ($g_data->pulls as $pull) { $created_data = explode("T", $pull->created_at); $closed_data = explode("T", $pull->closed_at); $merged_data = explode("T", $pull->merged_at); $created_idx = intval(str_replace("-", "", $created_data[0])); $merged_idx = intval(str_replace("-", "", $merged_data[0])); $closed_idx = intval(str_replace("-", "", $closed_data[0])); if (!isset($data[$created_idx]) || !isset($data[$created_idx]['new_pulls'])) { $data[$created_idx]['new_pulls'] = 1; } else { $data[$created_idx]['new_pulls']++; } if ($merged_idx != 0) { if (!isset($data[$merged_idx]) || !isset($data[$merged_idx]['merged_pulls'])) { $data[$merged_idx]['merged_pulls'] = 1; } else { $data[$merged_idx]['merged_pulls']++; } } if ($closed_idx != 0) { if (!isset($data[$closed_idx]) || !isset($data[$closed_idx]['closed_pulls'])) { $data[$closed_idx]['closed_pulls'] = 1; } else { $data[$closed_idx]['closed_pulls']++; } } } foreach ($data as $date => $stats) { $year = substr($date, 0, 4); $month = substr($date, 4, 2); $day = substr($date, 6, 2); $str_date = $year . "-" . $month . "-" . $day; $pd = new ProjectDelta(); $pd->forks = -99; $pd->delta_forks = -99; $pd->stars = -99; $pd->delta_stars = -99; $pd->project_id = $this->id; $pd->commits_count = isset($stats['commits']) ? $stats['commits'] : 0; $pd->new_pulls = isset($stats['new_pulls']) ? $stats['new_pulls'] : 0; $pd->closed_pulls = isset($stats['closed_pulls']) ? $stats['closed_pulls'] : 0; $pd->merged_pulls = isset($stats['merged_pulls']) ? $stats['merged_pulls'] : 0; $pd->sample_date = $str_date; if (save_project_delta($pd)) { Makiavelo::info("===== Delta saved! "); } else { Makiavelo::info("===== ERROR saving delta::" . mysql_error()); } } foreach ($g_data->open_issues_list as $issue) { $iss = new Issue(); $iss->title = $issue->title; $iss->body = MarkdownExtra::defaultTransform($issue->body); $iss->created_at = $issue->created_at; $iss->updated_at = $issue->updated_at; $iss->url = $issue->html_url; $iss->number = $issue->number; $iss->project_id = $this->id; if (save_issue($iss)) { Makiavelo::info("===== Issue saved! "); } else { Makiavelo::info("===== ERROR saving issue::" . mysql_error()); } } }
public function run() { $projects = list_project(null, null, "published = 1"); Makiavelo::info("=== Starting stats process ==="); foreach ($projects as $proj) { $proj_name = $proj->name; $usr_name = $proj->owner()->name; $dev = $proj->owner(); Makiavelo::info("==== Querying for {$usr_name}/{$proj_name}"); Makiavelo::puts("==== Querying for {$usr_name}/{$proj_name}"); $data = GithubAPI::queryProjectData($usr_name, $proj_name); if (isset($data->message)) { Makiavelo::info("Project error: " . $data->message); continue; } //We update the dev's avatar if needed if ($data->owner->avatar_url != $dev->avatar_url) { $dev->avatar_url = $data->owner->avatar_url; save_developer($dev); } //Calculate the commits for today $commits_today = 0; $today = '2013-05-02'; foreach ($data->commits as $commit) { $commit_date = $commit->commit->committer->date; $commit_date = explode("T", $commit_date); $commit_date = $commit_date[0]; $pc = load_project_commit_where("sha = '" . $commit->sha . "'"); if ($pc == null) { //We make sure we haven't yet saved this commit $project_commit = new ProjectCommit(); } else { //if we have, then we'll update it $project_commit = $pc; } $project_commit->project_id = $proj->id; if (!$commit->committer) { Makiavelo::puts("**** No se encontró committer... ******"); Makiavelo::info(print_r($commit, true)); } $project_commit->committer = $commit->committer->login; $project_commit->commit_message = $commit->commit->message; $project_commit->sha = $commit->sha; $project_commit->commit_date = $commit_date; save_project_commit($project_commit); if ($commit_date == $today) { $commits_today++; } } $new_pulls_today = $closed_pulls_today = $merged_pulls_today = 0; foreach ($data->pulls as $pull) { $created_data = explode("T", $pull->created_at); $closed_data = explode("T", $pull->closed_at); $merged_data = explode("T", $pull->merged_at); if ($created_data[0] == $today) { $new_pulls_today++; } if ($closed_data[0] == $today) { $closed_pulls_today++; } if ($merged_data[0] == $today) { $merged_pulls_today++; } } $delta_stars = $data->watchers - $proj->stars; $delta_forks = $data->forks - $proj->forks; //if($delta_stars != 0 || $delta_forks != 0) { Makiavelo::info("==== Delta found, saving..."); //We also update the project $proj->stars = $data->watchers; $proj->forks = $data->forks; save_project($proj); $pd = new ProjectDelta(); $pd->forks = $data->forks; $pd->delta_forks = $delta_forks; $pd->stars = $data->watchers; $pd->delta_stars = $delta_stars; $pd->project_id = $proj->id; $pd->commits_count = $commits_today; $pd->new_pulls = $new_pulls_today; $pd->closed_pulls = $closed_pulls_today; $pd->merged_pulls = $merged_pulls_today; $pd->sample_date = $today; if (save_project_delta($pd)) { Makiavelo::info("===== Delta saved! "); Makiavelo::info(print_r($pd, true)); } else { Makiavelo::info("===== ERROR saving delta"); } //} } }
<?php echo link_to(project_show_path($proj), '<span class="fui-eye-24"></span> View Stats', array("class" => "btn btn-primary btn-large")); ?> <a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php echo $proj->url(); ?> " data-text="Checkout this cool project on @Github! " data-via="lookingfor_pr" data-count="none">Tweet about it!</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> </div> </div> <?php } ?> <div class="span3 text-center"> <div class="project-spotlight" id="your-project"> <h3>Your project</h3> <p> <img src="/img/illustrations/clipboard.png"> </p> <?php if (user_logged_in()) { echo link_to(developer_show_path(current_user()), '<i class="fui-plus-24"></i> Publish', array("class" => "btn btn-primary btn-large")); } else { echo link_to(GithubAPI::login_url(), '<i class="icon-github" style="font-size:30px;" ></i> Github', array("class" => "has-tooltip btn btn-large btn-success", "data-title" => "Sign-in using Github")); } ?> </div> </div> </div>