diff --git a/module/gitlab/control.php b/module/gitlab/control.php index c87ba7772b..f06fbc76e0 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -820,7 +820,7 @@ class gitlab extends control $this->app->loadClass('pager', $static = true); $recTotal = count($branches); $pager = new pager($recTotal, $recPerPage, $pageID); - $branchList = array_chunk($branches, $pager->recPerPage); + $branchList = is_array($branches) ? array_chunk($branches, $pager->recPerPage) : array(); $this->view->keyword = $keyword; $this->view->pager = $pager; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 63bcf7207e..b279152f34 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -56,15 +56,23 @@ class gitlabModel extends model /** * Get gitlab api base url by gitlab id. * - * @param int $id + * @param int $gitlabID * @access public * @return string */ - public function getApiRoot($id) + public function getApiRoot($gitlabID) { - $gitlab = $this->getByID($id); + $gitlab = $this->getByID($gitlabID); if(!$gitlab) return ''; - return rtrim($gitlab->url, '/') . '/api/v4%s' . "?private_token={$gitlab->token}"; + + $sudoParam = ''; + if(!$this->app->user->admin) + { + $openID = $this->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); + if($openID) $sudoParam = "&sudo={$openID}"; + } + + return rtrim($gitlab->url, '/') . '/api/v4%s' . "?private_token={$gitlab->token}" . $sudoParam; } /** @@ -613,17 +621,15 @@ class gitlabModel extends model */ public function apiGetProjectsPager($gitlabID, $keyword = '', $orderBy = 'id_desc', $pager = null) { - $gitlab = $this->getByID($gitlabID); - if(!$gitlab) return array(); + $apiRoot = $this->getApiRoot($gitlabID); + if(!$apiRoot) return array(); - $host = rtrim($gitlab->url, '/'); - $host .= '/api/v4/projects'; + $url = sprintf($apiRoot, "/projects"); /* Parse order string. */ $order = explode('_', $orderBy); - $keyword = urlencode($keyword); - $result = commonModel::httpWithHeader($host . "?private_token={$gitlab->token}&simple=true&&per_page={$pager->recPerPage}&order_by={$order[0]}&sort={$order[1]}&page={$pager->pageID}&search={$keyword}&search_namespaces=true"); + $result = commonModel::httpWithHeader($url . "&simple=true&&per_page={$pager->recPerPage}&order_by={$order[0]}&sort={$order[1]}&page={$pager->pageID}&search={$keyword}&search_namespaces=true"); $header = $result['header']; $recTotal = $header['X-Total']; @@ -642,16 +648,15 @@ class gitlabModel extends model */ public function apiGetProjects($gitlabID) { - $gitlab = $this->getByID($gitlabID); - if(!$gitlab) return array(); + $apiRoot = $this->getApiRoot($gitlabID); + if(!$apiRoot) return array(); - $host = rtrim($gitlab->url, '/'); - $host .= '/api/v4/projects'; + $url = sprintf($apiRoot, "/projects"); $allResults = array(); for($page = 1; true; $page++) { - $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&page={$page}&per_page=100")); + $results = json_decode(commonModel::http($host . "&simple=true&page={$page}&per_page=100")); if(!is_array($results)) break; if(!empty($results)) $allResults = array_merge($allResults, $results); if(count($results)<100 or $page > 10) break; diff --git a/module/job/model.php b/module/job/model.php index d9b60f64b5..d679f7400e 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -21,6 +21,8 @@ class jobModel extends model public function getByID($id) { $job = $this->dao->select('*')->from(TABLE_JOB)->where('id')->eq($id)->fetch(); + if(empty($job)) return new stdClass(); + if(strtolower($job->engine) == 'gitlab') { $pipeline = json_decode($job->pipeline); diff --git a/module/mr/view/view.html.php b/module/mr/view/view.html.php index 019476a3d1..8bbe649941 100644 --- a/module/mr/view/view.html.php +++ b/module/mr/view/view.html.php @@ -139,9 +139,9 @@ compile->atTime;?> - lastExec : $lang->mr->compileUnexecuted;?> + mr->compileUnexecuted);?> - + id)):?> compile->result;?>