diff --git a/modules/github/modules.php b/modules/github/modules.php index 539cdc0c65..2b14fa5114 100644 --- a/modules/github/modules.php +++ b/modules/github/modules.php @@ -167,6 +167,7 @@ public function process() { $oauth2 = new Hm_Oauth2($details['client_id'], $details['client_secret'], $details['redirect_uri']); $result = $oauth2->request_token($details['token_url'], $this->request->get['code'], array('Accept: application/json')); if (count($result) > 0 && array_key_exists('access_token', $result)) { + $this->load_repositories($result['access_token']); Hm_Msgs::add('Github connection established'); $this->user_config->set('github_connect_details', $result); $user_data = $this->user_config->dump(); @@ -189,6 +190,19 @@ public function process() { Hm_Dispatch::page_redirect('?page=servers'); } } + + public function load_repositories($token) { + $repos = $this->user_config->get('github_repos', array()); + $url = sprintf('https://api.github.com/user/repos'); + $api = new Hm_API_Curl(); + $data = $api->command($url, array('Authorization: token ' . $token)); + foreach ($data as $value) { + if (!in_array($value['full_name'], $repos)) { + $repos[] = $value['full_name']; + } + } + $this->user_config->set('github_repos', $repos); + } } /** @@ -541,23 +555,31 @@ protected function output() { $res = ''; $details = $this->get('github_connect_details', array()); if (!empty($details)) { - $res = '
'. + ''. + ' | '. + ''.$this->html_safe($repo).' | '. + '