diff --git a/module/git/model.php b/module/git/model.php index 30f10f3779..55da4451ac 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -82,6 +82,8 @@ class gitModel extends model { $this->updateCommit($repo, $commentGroup, true); + if($repo->SCM == 'Gitlab') $this->loadModel('gitlab')->updateCodePath($repo->serviceHost, $repo->serviceProject, $repo->id); + /* Create compile by tag. */ $jobs = zget($tagGroup, $repoID, array()); foreach($jobs as $job) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 11998aba2c..82e11c68a9 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2962,4 +2962,25 @@ class gitlabModel extends model $url = sprintf($apiRoot, "/projects/$projectID/pipelines") . "&ref=$branch"; return json_decode(commonModel::http($url)); } + + /** + * 更新版本库的代码地址。 + * Update repo code path. + * + * @param int $gitlabID + * @param int $projectID + * @param int $repoID + * @access public + * @return bool + */ + public function updateCodePath(int $gitlabID, int $projectID, int $repoID): bool + { + $project = $this->apiGetSingleProject($gitlabID, $projectID); + if(is_object($project) and !empty($project->web_url)) + { + return $this->dao->update(TABLE_REPO)->set('path')->eq($project->web_url)->where('id')->eq($repoID)->exec(); + } + + return false; + } } diff --git a/module/repo/control.php b/module/repo/control.php index a599e05110..c7ef16be24 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -79,7 +79,7 @@ class repo extends control $repoID = $this->repo->saveState(0, $objectID); if($this->viewType !== 'json') $this->commonAction($repoID, $objectID); - $repoList = $this->repo->getList(0, '', $orderBy, null, true, true); + $repoList = $this->repo->getList(0, '', $orderBy, null, false, true); $sonarRepoList = $this->loadModel('job')->getSonarqubeByRepo(array_keys($repoList)); /* Pager. */ @@ -138,8 +138,9 @@ class repo extends control if($this->post->SCM == 'Gitlab') { /* Add webhook. */ - $repo = $this->getRepoByID($repoID); + $repo = $this->repo->getRepoByID($repoID); $this->loadModel('gitlab')->addPushWebhook($repo); + $this->gitlab->updateCodePath($repo->serviceHost, $repo->serviceProject, $repo->id); } $this->loadModel('action')->create('repo', $repoID, 'created'); @@ -519,6 +520,8 @@ class repo extends control */ public function browse($repoID = 0, $branchID = '', $objectID = 0, $path = '', $revision = 'HEAD', $refresh = 0, $branchOrTag = 'branch', $type = 'dir', $recTotal = 0, $recPerPage = 10, $pageID = 1) { + unset($this->lang->devops->homeMenu); + $repoID = $this->repo->saveState($repoID, $objectID); $originBranchID = $branchID; if($branchID) $branchID = base64_decode(helper::safe64Decode($branchID)); diff --git a/module/repo/model.php b/module/repo/model.php index 4c64e62778..b3cc0bd1ef 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -2173,7 +2173,7 @@ class repoModel extends model { if($getCodePath) $project = $this->loadModel('gitlab')->apiGetSingleProject($repo->serviceHost, $repo->serviceProject); - $repo->path = $service ? sprintf($this->config->repo->{$service->type}->apiPath, $service->url, $repo->serviceProject) : ''; + $repo->path = (!$repo->path && $service) ? sprintf($this->config->repo->{$service->type}->apiPath, $service->url, $repo->serviceProject) : $repo->path; $repo->client = $service ? $service->url : ''; $repo->password = $service ? $service->token : ''; $repo->codePath = isset($project->web_url) ? $project->web_url : $repo->path;