* adjust for task #46002.
This commit is contained in:
+3
-2
@@ -147,7 +147,7 @@ $filter->user->edit = new stdclass();
|
||||
$filter->webhook->bind = new stdclass();
|
||||
$filter->user->ajaxgetmore = new stdclass();
|
||||
$filter->repo->ajaxsynccommit = new stdclass();
|
||||
$filter->repo->ajaxgetrepobyurl = new stdclass();
|
||||
$filter->repo->apigetrepobyurl = new stdclass();
|
||||
$filter->search->index = new stdclass();
|
||||
$filter->gitlab->webhook = new stdclass();
|
||||
$filter->gitlab->importissue = new stdclass();
|
||||
@@ -365,7 +365,8 @@ $filter->repo->view = new stdclass();
|
||||
$filter->repo->default->get['repoPath'] = 'reg::base64';
|
||||
$filter->repo->default->get['path'] = 'reg::base64';
|
||||
$filter->repo->default->get['entry'] = 'reg::base64';
|
||||
$filter->repo->ajaxgetrepobyurl->get['url'] = 'reg::any';
|
||||
|
||||
$filter->repo->apigetrepobyurl->get['url'] = 'reg::any';
|
||||
|
||||
$filter->repo->default->cookie['repoBranch'] = 'reg::any';
|
||||
$filter->repo->diff->cookie['arrange'] = 'reg::word';
|
||||
|
||||
+3
-45
@@ -1188,50 +1188,8 @@ class repo extends control
|
||||
{
|
||||
if($type != 'gitlab') return $this->send(array('result' => 'fail', 'message' => 'Now only search gitlab.'));
|
||||
|
||||
$url = urldecode($this->get->url);
|
||||
$parsedUrl = parse_url($url);
|
||||
|
||||
$isSSH = $parsedUrl['scheme'] == 'ssh';
|
||||
$gitlabBaseURL = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . (isset($parsedUrl['port']) ? ":{$parsedUrl['port']}" : '');
|
||||
|
||||
$gitlabs = $this->dao->select('*')->from(TABLE_PIPELINE)->where('type')->eq('gitlab')
|
||||
->beginIF($isSSH)->andWhere('url')->like("%{$parsedUrl['host']}%")->fi()
|
||||
->beginIF(!$isSSH)->andWhere('url')->eq($gitlabBaseURL)->fi()
|
||||
->orderBy('id_desc')
|
||||
->fetchAll('id');
|
||||
|
||||
$this->loadModel('gitlab');
|
||||
$matched = new stdclass();
|
||||
$matched->gitlab = 0;
|
||||
$matched->project = 0;
|
||||
foreach($gitlabs as $gitlabID => $gitlab)
|
||||
{
|
||||
$projects = $this->gitlab->apiGetProjects($gitlabID);
|
||||
foreach($projects as $project)
|
||||
{
|
||||
if((!$isSSH and $project->http_url_to_repo == $url) or ($isSSH and $project->ssh_url_to_repo == $url))
|
||||
{
|
||||
$matched->gitlab = $gitlabID;
|
||||
$matched->project = $project->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$matchedRepo = $this->dao->select('*')->from(TABLE_REPO)->where('SCM')->eq('Gitlab')
|
||||
->andWhere('client')->eq($matched->gitlab)
|
||||
->andWhere('path')->eq($matched->project)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('preMerge')->eq(1)
|
||||
->orderBy('id_desc')
|
||||
->fetch();
|
||||
if(empty($matchedRepo)) return $this->send(array('result' => 'fail', 'message' => 'No matched gitlab.'));
|
||||
if(empty($matchedRepo->linkJob)) return $this->send(array('result' => 'fail', 'message' => 'No linked job.'));
|
||||
|
||||
$job = $this->dao->select('*')->from(TABLE_JOB)->where('id')->eq($matchedRepo->linkJob)->andWhere('deleted')->eq(0)->fetch();
|
||||
if(empty($job)) return $this->send(array('result' => 'fail', 'message' => 'Linked job is not exists.'));
|
||||
|
||||
$matchedRepo->linkJob = $job;
|
||||
return $this->send(array('result' => 'success', 'data' => $matchedRepo));
|
||||
$url = urldecode($this->get->url);
|
||||
$result = $this->repo->getRepoByUrl($url);
|
||||
return $this->send($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,6 +396,74 @@ class repoModel extends model
|
||||
return $repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repo by url.
|
||||
*
|
||||
* @param string $url
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getRepoByUrl($url)
|
||||
{
|
||||
$parsedUrl = parse_url($url);
|
||||
|
||||
$isSSH = $parsedUrl['scheme'] == 'ssh';
|
||||
$baseURL = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . (isset($parsedUrl['port']) ? ":{$parsedUrl['port']}" : '');
|
||||
|
||||
/* Get gitlabs by URL. */
|
||||
$gitlabs = $this->dao->select('*')->from(TABLE_PIPELINE)->where('type')->eq('gitlab')
|
||||
->beginIF($isSSH)->andWhere('url')->like("%{$parsedUrl['host']}%")->fi()
|
||||
->beginIF(!$isSSH)->andWhere('url')->eq($baseURL)->fi()
|
||||
->orderBy('id_desc')
|
||||
->fetchAll('id');
|
||||
|
||||
/* Convert to id by url. */
|
||||
$this->loadModel('gitlab');
|
||||
$matched = new stdclass();
|
||||
$matched->gitlab = 0;
|
||||
$matched->project = 0;
|
||||
foreach($gitlabs as $gitlabID => $gitlab)
|
||||
{
|
||||
$projects = $this->gitlab->apiGetProjects($gitlabID);
|
||||
foreach($projects as $project)
|
||||
{
|
||||
if((!$isSSH and $project->http_url_to_repo == $url) or ($isSSH and $project->ssh_url_to_repo == $url))
|
||||
{
|
||||
$matched->gitlab = $gitlabID;
|
||||
$matched->project = $project->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(empty($matched->gitlab) or empty($matched->project)) return array('result' => 'fail', 'message' => 'No matched gitlab.');
|
||||
|
||||
$matchedRepos = $this->dao->select('*')->from(TABLE_REPO)->where('SCM')->eq('Gitlab')
|
||||
->andWhere('client')->eq($matched->gitlab)
|
||||
->andWhere('path')->eq($matched->project)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->orderBy('id_desc')
|
||||
->fetchAll();
|
||||
if(empty($matchedRepos)) return array('result' => 'fail', 'message' => 'No matched gitlab.');
|
||||
|
||||
$matchedRepo = '';
|
||||
foreach($matchedRepos as $repo)
|
||||
{
|
||||
if(!empty($matchedRepo->preMerge))
|
||||
{
|
||||
$matchedRepo = $repo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(empty($matchedRepo)) return array('result' => 'fail', 'message' => 'Matched gitlab is not open pre merge.');
|
||||
if(empty($matchedRepo->job)) return array('result' => 'fail', 'message' => 'No linked job.');
|
||||
|
||||
$job = $this->dao->select('*')->from(TABLE_JOB)->where('id')->eq($matchedRepo->job)->andWhere('deleted')->eq(0)->fetch();
|
||||
if(empty($job)) return array('result' => 'fail', 'message' => 'Linked job is not exists.');
|
||||
|
||||
$matchedRepo->job = $job;
|
||||
return array('result' => 'success', 'data' => $matchedRepo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get by id list.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user