Merge branch 'liyuchun_64263' into 'zenops_41'
* Finish task #64263. See merge request easycorp/zentaopms!4958
This commit is contained in:
@@ -619,6 +619,27 @@ class Gogs
|
||||
return $logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get commits by MR branches.
|
||||
*
|
||||
* @param string $sourceBranch
|
||||
* @param string $targetBranch
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getMRCommits($sourceBranch, $targetBranch)
|
||||
{
|
||||
execCmd(escapeCmd("$this->client checkout $sourceBranch"));
|
||||
execCmd(escapeCmd("$this->client pull"));
|
||||
execCmd(escapeCmd("$this->client checkout $targetBranch"));
|
||||
execCmd(escapeCmd("$this->client pull"));
|
||||
|
||||
$commits = execCmd(escapeCmd("$this->client log origin/$sourceBranch ^origin/$targetBranch"), 'array');
|
||||
$commits = $this->parseLog($commits);
|
||||
foreach($commits as $commit) $commit->id = $commit->revision;
|
||||
return $commits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get clone url.
|
||||
*
|
||||
|
||||
@@ -220,6 +220,19 @@ class scm
|
||||
return $this->engine->getCommits($version, $count, $branch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get commits by MR branches.
|
||||
*
|
||||
* @param string $sourceBranch
|
||||
* @param string $targetBranch
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getMRCommits($sourceBranch, $targetBranch)
|
||||
{
|
||||
return $this->engine->getMRCommits($sourceBranch, $targetBranch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get clone url.
|
||||
*
|
||||
|
||||
@@ -630,7 +630,7 @@ class mr extends control
|
||||
$this->loadModel('search')->setSearchParams($this->config->product->search);
|
||||
|
||||
$MR = $this->mr->getByID($MRID);
|
||||
$relatedStories = $this->mr->getCommitedLink($MR->hostID, $MR->targetProject, $MR->mriid, 'story');
|
||||
$relatedStories = $this->mr->getCommitedLink($MR, 'story');
|
||||
|
||||
$linkedStories = $this->mr->getLinkList($MRID, $product->id, 'story');
|
||||
if($browseType == 'bySearch')
|
||||
@@ -715,7 +715,7 @@ class mr extends control
|
||||
$this->loadModel('search')->setSearchParams($this->config->bug->search);
|
||||
|
||||
$MR = $this->mr->getByID($MRID);
|
||||
$relatedBugs = $this->mr->getCommitedLink($MR->hostID, $MR->targetProject, $MR->mriid, 'bug');
|
||||
$relatedBugs = $this->mr->getCommitedLink($MR, 'bug');
|
||||
|
||||
$linkedBugs = $this->mr->getLinkList($MRID, $product->id, 'bug');
|
||||
if($browseType == 'bySearch')
|
||||
@@ -787,7 +787,7 @@ class mr extends control
|
||||
$this->loadModel('search')->setSearchParams($this->config->execution->search);
|
||||
|
||||
$MR = $this->mr->getByID($MRID);
|
||||
$relatedTasks = $this->mr->getCommitedLink($MR->hostID, $MR->targetProject, $MR->mriid, 'task');
|
||||
$relatedTasks = $this->mr->getCommitedLink($MR, 'task');
|
||||
$linkedTasks = $this->mr->getLinkList($MRID, $product->id, 'task');
|
||||
|
||||
/* Get executions by product. */
|
||||
|
||||
+33
-31
@@ -1226,29 +1226,6 @@ class mrModel extends model
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diff commits of MR from GitLab API.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @param int $projectID
|
||||
* @param int $MRID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiGetDiffCommits($hostID, $projectID, $MRID)
|
||||
{
|
||||
$host = $this->loadModel('pipeline')->getByID($hostID);
|
||||
if($host->type == 'gitlab')
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID/commits");
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = sprintf($this->loadModel($host->type)->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID/commits");
|
||||
}
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diff of MR from Gitea API.
|
||||
*
|
||||
@@ -1737,6 +1714,33 @@ class mrModel extends model
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diff commits of MR.
|
||||
*
|
||||
* @param object $MR
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getDiffCommits($MR)
|
||||
{
|
||||
$host = $this->loadModel('pipeline')->getByID($MR->hostID);
|
||||
if($host->type == 'gogs')
|
||||
{
|
||||
$repo = $this->loadModel('repo')->getRepoByID($MR->repoID);
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$scm->setEngine($repo);
|
||||
return $scm->getMRCommits($MR->sourceBranch, $MR->targetBranch);
|
||||
}
|
||||
else
|
||||
{
|
||||
$projectID = $MR->projectID;
|
||||
$MRID = $MR->mriid;
|
||||
if($host->type == 'gitlab') $url = sprintf($this->loadModel('gitlab')->getApiRoot($this->hostID), "/projects/$projectID/merge_requests/$MRID/commits");
|
||||
if($host->type == 'gitea') $url = sprintf($this->loadModel('gitea')->getApiRoot($this->hostID), "/repos/$projectID/pulls/$MRID/commits");
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an mr link.
|
||||
*
|
||||
@@ -1868,21 +1872,19 @@ class mrModel extends model
|
||||
/**
|
||||
* Get links by mr commites.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @param int $projectID
|
||||
* @param int $MRID
|
||||
* @param string $type
|
||||
* @param object $MR
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getCommitedLink($hostID, $projectID, $MRID, $type)
|
||||
public function getCommitedLink($MR, $type)
|
||||
{
|
||||
$DiffCommits = $this->apiGetDiffCommits($hostID, $projectID, $MRID);
|
||||
$diffCommits = $this->getDiffCommits($MR);
|
||||
|
||||
$commits = array();
|
||||
foreach($DiffCommits as $DiffCommit)
|
||||
foreach($diffCommits as $diffCommit)
|
||||
{
|
||||
if(isset($DiffCommit->id)) $commits[] = substr($DiffCommit->id, 0, 10);
|
||||
if(isset($diffCommit->id)) $commits[] = substr($diffCommit->id, 0, 10);
|
||||
}
|
||||
|
||||
return $this->dao->select('objectID')->from(TABLE_ACTION)->where('objectType')->eq($type)->andWhere('extra')->in($commits)->fetchPairs('objectID');
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ fields:
|
||||
range: 3,1
|
||||
- field: pipeline
|
||||
note: "流水线"
|
||||
range: dave,[{"project":"1569"}]
|
||||
range: dave,[{"project":"1569","reference":"master"}]
|
||||
- field: triggerType
|
||||
note: "触发方式"
|
||||
range: tag,commit,schedule
|
||||
|
||||
Reference in New Issue
Block a user