From e75c7ecabefa5a2d3ea13ff9184614acb3445da0 Mon Sep 17 00:00:00 2001 From: David-Muhasa Date: Fri, 14 Jun 2024 18:50:16 +0200 Subject: [PATCH 1/2] added functionality : query the user's repositories and add them to the user settings on github connect --- modules/github/modules.php | 61 ++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/modules/github/modules.php b/modules/github/modules.php index 539cdc0c65..e1d66ad51b 100644 --- a/modules/github/modules.php +++ b/modules/github/modules.php @@ -166,7 +166,9 @@ public function process() { $details = github_connect_details($this->config); $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 +191,20 @@ 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 +557,42 @@ 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 .= '
'. + $res .= '
+ '. ''. - ''. - ''.$this->html_safe($repo).'
'; - } - $res .= '
'; + ' + + + + + + + '; + } + $res .= ' + +
+ + +

'.$this->html_safe($repo).'

+
+
'; } return $res; } @@ -630,10 +665,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.'
'; From 486518f982e9160a80d457159fb26a3d14bbadfb Mon Sep 17 00:00:00 2001 From: Josaphat Imani Date: Thu, 27 Jun 2024 22:46:04 +0200 Subject: [PATCH 2/2] Fixed malformed html tags --- modules/github/modules.php | 53 ++++++++++++++------------------------ modules/github/site.css | 2 -- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/modules/github/modules.php b/modules/github/modules.php index e1d66ad51b..2b14fa5114 100644 --- a/modules/github/modules.php +++ b/modules/github/modules.php @@ -166,7 +166,6 @@ public function process() { $details = github_connect_details($this->config); $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'); @@ -193,7 +192,6 @@ public function process() { } 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(); @@ -202,7 +200,7 @@ public function load_repositories($token) { if (!in_array($value['full_name'], $repos)) { $repos[] = $value['full_name']; } - } + } $this->user_config->set('github_repos', $repos); } } @@ -557,42 +555,31 @@ protected function output() { $res = ''; $details = $this->get('github_connect_details', array()); if (!empty($details)) { - $res = '
+ $res = '
'.$this->trans('Add a Repository').'
'. '
'. ''. ''. - ''. + ''. ''. - ''. - ''. + ''. + ''. '
'; - $res .= '
'.$this->trans('Repositories').'
- - - - '; + $res .= '
'.$this->trans('Repositories').'
'. + '
'; foreach ($this->get('github_repos', array()) as $repo) { - $res .= '
-
'. - ''. - ' -
- - - - - - '; - } - $res .= ' - -
- - -

'.$this->html_safe($repo).'

-
-
'; + $res .= ''. + ''. + '
'. + ''. + ''. + ''. + '
'. + ''. + ''.$this->html_safe($repo).''. + ''; + } + $res .= '
'; } return $res; } @@ -668,7 +655,7 @@ protected function output() { $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; }