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->trans('Add a Repository').'
'. + $res = '
+
'.$this->trans('Add a Repository').'
'. '
'. ''. ''. - ''. + ''. ''. - ''. - ''. + ''. + ''. '
'; - $res .= '
'.$this->trans('Repositories').'
'; + $res .= '
'.$this->trans('Repositories').'
'. + ''; foreach ($this->get('github_repos', array()) as $repo) { - $res .= '
'. - ''. - ''. - ''.$this->html_safe($repo).'
'; - } - $res .= '
'; + $res .= ''. + ''. + ''. + ''; + } + $res .= '
'. + '
'. + ''. + ''. + ''. + '
'. + '
'.$this->html_safe($repo).'
'; } return $res; } @@ -630,10 +652,10 @@ protected function output() { $res .= ''.$this->trans('Enable').'
'; } else { - $res .= $this->trans('Already connected'); - $res .= '
'; + $res .='
'. $this->trans('Already connected').'
'; + $res .= ''; $res .= ''; - $res .= ''; + $res .= ''; $res .= '
'; } return $res.'
'; diff --git a/modules/github/site.css b/modules/github/site.css index 374347f392..8fd257103c 100644 --- a/modules/github/site.css +++ b/modules/github/site.css @@ -1,8 +1,6 @@ .github_connect_section { padding: 20px; padding-bottom: 40px; display: none; padding-left: 40px; } .github_connect_section .add_server { width: 180px; } .github_connect_section .server_title { margin-bottom: 10px; } -.github_disconnect { margin-left: 20px; margin-top: 20px; } -.configured_repo { margin-bottom: 5px; } .github_link { margin-left: 10px; display: inline; } .github_all_setting { display: none; } .github_para { white-space: pre; border-bottom: solid 1px #ccc; padding-bottom: 20px; margin-bottom: 20px; }