Merge branch 'devops18'
This commit is contained in:
+29
-13
@@ -97,11 +97,11 @@ class mr extends control
|
||||
$this->mr->apiCreate();
|
||||
|
||||
$response['result'] = 'success';
|
||||
$response['message'] = '';
|
||||
$response['message'] = $this->lang->saveSuccess;
|
||||
if(dao::isError())
|
||||
{
|
||||
$response['result'] = 'fail';
|
||||
$response['message'] = dao::getError();
|
||||
$response['message'] = join("\n", dao::getError());
|
||||
}
|
||||
|
||||
return $this->send($response);
|
||||
@@ -150,21 +150,19 @@ class mr extends control
|
||||
$this->loadModel('job');
|
||||
$this->loadModel('compile');
|
||||
|
||||
$repoList = array();
|
||||
$repoList = array();
|
||||
$rawRepoList = $this->repo->getGitLabRepoList($MR->gitlabID, $MR->sourceProject);
|
||||
foreach($rawRepoList as $rawRepo) $repoList[$rawRepo->id] = "[$rawRepo->id] $rawRepo->name";
|
||||
|
||||
$jobList = array();
|
||||
$rawJobList = $this->job->getListByRepoID($MR->repoID);
|
||||
foreach($rawJobList as $rawJob) $jobList[$rawJob->id] = "[$rawJob->id] $rawJob->name";
|
||||
if($MR->repoID)
|
||||
{
|
||||
$rawJobList = $this->job->getListByRepoID($MR->repoID);
|
||||
foreach($rawJobList as $rawJob) $jobList[$rawJob->id] = "[$rawJob->id] $rawJob->name";
|
||||
}
|
||||
|
||||
$compileList = array();
|
||||
$rawCompileList = $this->compile->getListByJobID($MR->jobID);
|
||||
foreach($rawCompileList as $rawCompile) $compileList[$rawCompile->id] = "[$rawCompile->id] [{$this->lang->compile->statusList[$rawCompile->status]}] $rawCompile->name";
|
||||
|
||||
$this->view->repoList = $repoList;
|
||||
$this->view->jobList = !empty($MR->repoID) ? $jobList : array();
|
||||
$this->view->compileList = !empty($MR->jobID) ? $compileList : array();
|
||||
$this->view->repoList = $repoList;
|
||||
$this->view->jobList = !empty($MR->repoID) ? $jobList : array();
|
||||
|
||||
$this->view->title = $this->lang->mr->edit;
|
||||
$this->view->MR = $MR;
|
||||
@@ -232,7 +230,7 @@ class mr extends control
|
||||
$this->view->compile = $this->loadModel('compile')->getById($MR->compileID);
|
||||
$this->view->compileJob = $MR->jobID ? $this->loadModel('job')->getById($MR->jobID) : false;
|
||||
|
||||
$this->view->title = $this->lang->mr->overview;
|
||||
$this->view->title = $this->lang->mr->view;
|
||||
$this->view->MR = $MR;
|
||||
$this->view->rawMR = isset($rawMR) ? $rawMR : false;
|
||||
$this->view->product = $product;
|
||||
@@ -937,4 +935,22 @@ class mr extends control
|
||||
foreach($compileList as $compile) $options .= "<option value='{$compile->id}' data-name='{$compile->name}'>[{$compile->id}] [{$this->lang->compile->statusList[$compile->status]}] {$compile->name}</option>";
|
||||
$this->send($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax check same opened mr for source branch.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxCheckSameOpened($gitlabID)
|
||||
{
|
||||
$sourceProject = $this->post->sourceProject;
|
||||
$sourceBranch = $this->post->sourceBranch;
|
||||
$targetProject = $this->post->targetProject;
|
||||
$targetBranch = $this->post->targetBranch;
|
||||
|
||||
$result = $this->mr->checkSameOpened($gitlabID, $sourceProject, $sourceBranch, $targetProject, $targetBranch);
|
||||
die(json_encode($result));
|
||||
}
|
||||
}
|
||||
|
||||
+53
-28
@@ -2,10 +2,10 @@ $(function()
|
||||
{
|
||||
$('#gitlabID').change(function()
|
||||
{
|
||||
gitlabID = $('#gitlabID').val();
|
||||
var gitlabID = $('#gitlabID').val();
|
||||
if(gitlabID == '') return false;
|
||||
|
||||
url = createLink('repo', 'ajaxgetgitlabprojects', "gitlabID=" + gitlabID);
|
||||
var url = createLink('repo', 'ajaxgetgitlabprojects', "gitlabID=" + gitlabID);
|
||||
$.get(url, function(response)
|
||||
{
|
||||
$('#sourceProject').html('').append(response);
|
||||
@@ -15,9 +15,10 @@ $(function()
|
||||
|
||||
$('#sourceProject,#targetProject').change(function()
|
||||
{
|
||||
sourceProject = $(this).val();
|
||||
var branchSelect = $(this).parents('td').find('select[name*=Branch]');
|
||||
branchUrl = createLink('gitlab', 'ajaxgetprojectbranches', "gitlabID=" + gitlabID + "&projectID=" + sourceProject);
|
||||
var gitlabID = $('#gitlabID').val();
|
||||
var sourceProject = $(this).val();
|
||||
var branchSelect = $(this).parents('td').find('select[name*=Branch]');
|
||||
var branchUrl = createLink('gitlab', 'ajaxgetprojectbranches', "gitlabID=" + gitlabID + "&projectID=" + sourceProject);
|
||||
$.get(branchUrl, function(response)
|
||||
{
|
||||
branchSelect.html('').append(response);
|
||||
@@ -28,15 +29,16 @@ $(function()
|
||||
|
||||
$('#sourceProject').change(function()
|
||||
{
|
||||
sourceProject = $(this).val();
|
||||
projectUrl = createLink('mr', 'ajaxGetMRTargetProjects', "gitlabID=" + gitlabID + "&projectID=" + sourceProject);
|
||||
var gitlabID = $('#gitlabID').val();
|
||||
var sourceProject = $(this).val();
|
||||
var projectUrl = createLink('mr', 'ajaxGetMRTargetProjects', "gitlabID=" + gitlabID + "&projectID=" + sourceProject);
|
||||
$.get(projectUrl, function(response)
|
||||
{
|
||||
$('#targetProject').html('').append(response);
|
||||
$('#targetProject').chosen().trigger("chosen:updated");;
|
||||
});
|
||||
|
||||
repoUrl = createLink('mr', 'ajaxGetRepoList', "gitlabID=" + gitlabID + "&projectID=" + sourceProject);
|
||||
var repoUrl = createLink('mr', 'ajaxGetRepoList', "gitlabID=" + gitlabID + "&projectID=" + sourceProject);
|
||||
$.get(repoUrl, function(response)
|
||||
{
|
||||
$('#repoID').html('').append(response);
|
||||
@@ -44,10 +46,34 @@ $(function()
|
||||
});
|
||||
});
|
||||
|
||||
$('#sourceBranch,#targetBranch').change(function()
|
||||
{
|
||||
var sourceProject = $('#sourceProject').val();
|
||||
var sourceBranch = $('#sourceBranch').val();
|
||||
var targetProject = $('#targetProject').val();
|
||||
var targetBranch = $('#targetBranch').val();
|
||||
if(!sourceProject || !sourceBranch || !targetProject || !targetBranch) return false;
|
||||
|
||||
var $this = $(this);
|
||||
var gitlabID = $('#gitlabID').val();
|
||||
var repoUrl = createLink('mr', 'ajaxCheckSameOpened', "gitlabID=" + gitlabID);
|
||||
$.post(repoUrl, {"sourceProject": sourceProject, "sourceBranch": sourceBranch, "targetProject": targetProject, "targetBranch": targetBranch}, function(response)
|
||||
{
|
||||
response = $.parseJSON(response);
|
||||
if(response.result == 'fail')
|
||||
{
|
||||
alert(response.message);
|
||||
$this.val('').trigger('chosen:updated');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
$('#targetProject').change(function()
|
||||
{
|
||||
targetProject = $(this).val();
|
||||
var gitlabID = $('#gitlabID').val();
|
||||
var assignee = $("#assignee").parents('td').find('select[name*=assignee]');
|
||||
var reviewer = $("#reviewer").parents('td').find('select[name*=reviewer]');
|
||||
usersUrl = createLink('gitlab', 'ajaxgetmruserpairs', "gitlabID=" + gitlabID + "&projectID=" + targetProject);
|
||||
@@ -63,8 +89,8 @@ $(function()
|
||||
|
||||
$('#repoID').change(function()
|
||||
{
|
||||
repoID = $(this).val();
|
||||
jobUrl = createLink('mr', 'ajaxGetJobList', "repoID=" + repoID);
|
||||
var repoID = $(this).val();
|
||||
var jobUrl = createLink('mr', 'ajaxGetJobList', "repoID=" + repoID);
|
||||
$.get(jobUrl, function(response)
|
||||
{
|
||||
$('#jobID').html('').append(response);
|
||||
@@ -74,8 +100,8 @@ $(function()
|
||||
|
||||
$('#jobID').change(function()
|
||||
{
|
||||
jobID = $(this).val();
|
||||
compileUrl = createLink('mr', 'ajaxGetCompileList', "job=" + jobID);
|
||||
var jobID = $(this).val();
|
||||
var compileUrl = createLink('mr', 'ajaxGetCompileList', "job=" + jobID);
|
||||
$.get(compileUrl, function(response)
|
||||
{
|
||||
$('#compile').html('').append(response);
|
||||
@@ -83,20 +109,19 @@ $(function()
|
||||
});
|
||||
});
|
||||
|
||||
$("#needCI").change(function()
|
||||
{
|
||||
if(this.checked == false)
|
||||
{
|
||||
$("#jobID").prop("disabled", true);
|
||||
$('#jobID').chosen().trigger("chosen:updated");;
|
||||
$("#jobID").parent().parent().addClass('hidden');
|
||||
}
|
||||
if(this.checked == true)
|
||||
{
|
||||
$("#jobID").prop("disabled", false);
|
||||
$('#jobID').chosen().trigger("chosen:updated");;
|
||||
$("#jobID").parent().parent().removeClass('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
$("#needCI").change(function()
|
||||
{
|
||||
if(this.checked == false)
|
||||
{
|
||||
$("#jobID").prop("disabled", true);
|
||||
$('#jobID').chosen().trigger("chosen:updated");;
|
||||
$("#jobID").parent().parent().addClass('hidden');
|
||||
}
|
||||
if(this.checked == true)
|
||||
{
|
||||
$("#jobID").prop("disabled", false);
|
||||
$('#jobID').chosen().trigger("chosen:updated");;
|
||||
$("#jobID").parent().parent().removeClass('hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+10
-10
@@ -1,26 +1,26 @@
|
||||
$(function ()
|
||||
{
|
||||
{
|
||||
$('#repoID').change(function ()
|
||||
{
|
||||
{
|
||||
repoID = $(this).val();
|
||||
jobUrl = createLink('mr', 'ajaxGetJobList', "repoID=" + repoID);
|
||||
$.get(jobUrl, function (response)
|
||||
{
|
||||
{
|
||||
$('#jobID').html('').append(response);
|
||||
$('#jobID').chosen().trigger("chosen:updated");;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#jobID').change(function ()
|
||||
{
|
||||
{
|
||||
jobID = $(this).val();
|
||||
compileUrl = createLink('mr', 'ajaxGetCompileList', "job=" + jobID);
|
||||
$.get(compileUrl, function (response)
|
||||
{
|
||||
{
|
||||
$('#compile').html('').append(response);
|
||||
$('#compile').chosen().trigger("chosen:updated");;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("#needCI").change(function()
|
||||
{
|
||||
@@ -28,4 +28,4 @@ $(function ()
|
||||
if(this.checked == true) $("#jobID").parent().parent().removeClass('hidden');
|
||||
});
|
||||
$("#needCI").trigger('change');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
$lang->mr = new stdclass;
|
||||
$lang->mr->common = "Merge Request";
|
||||
$lang->mr->overview = "Survey";
|
||||
$lang->mr->view = "Survey";
|
||||
$lang->mr->create = "Create";
|
||||
$lang->mr->apiCreate = "Interface: Create";
|
||||
$lang->mr->browse = "Browse";
|
||||
@@ -105,6 +105,7 @@ $lang->mr->apiError->createMR = "Failed to create a merge request through API. R
|
||||
$lang->mr->apiError->sudo = "Unable to operate with the GitLab account bound to the current user. Reason: %s";
|
||||
|
||||
$lang->mr->createFailedFromAPI = "Failed to create Merge Request.";
|
||||
$lang->mr->hasSameOpenedMR = "There are duplicate and unclosed merge requests.";
|
||||
$lang->mr->accessGitlabFailed = "Unable to connect to the GitLab server.";
|
||||
$lang->mr->reopenSuccess = "The merge request was reopened.";
|
||||
$lang->mr->closeSuccess = "Merge request closed.";
|
||||
@@ -113,17 +114,17 @@ $lang->mr->apiErrorMap[1] = "You can't use same project/branch for source and ta
|
||||
$lang->mr->apiErrorMap[2] = "/Another open merge request already exists for this source branch: !([0-9]+)/";
|
||||
|
||||
$lang->mr->errorLang[1] = 'The source project branch cannot be the same as the target project branch';
|
||||
$lang->mr->errorLang[2] = 'Another open merge request already exists for this source branch: !%u';
|
||||
$lang->mr->errorLang[2] = 'Another open merge request already exists for this source branch: ID%u';
|
||||
|
||||
$lang->mr->from = "from";
|
||||
$lang->mr->to = "to";
|
||||
$lang->mr->at = "at";
|
||||
|
||||
$lang->mr->pipeline = "Pipeline";
|
||||
$lang->mr->pipelineSuccess = "Success";
|
||||
$lang->mr->pipelineFailed = "Failed";
|
||||
$lang->mr->pipeline = "Pipeline";
|
||||
$lang->mr->pipelineSuccess = "Success";
|
||||
$lang->mr->pipelineFailed = "Failed";
|
||||
$lang->mr->pipelineCanceled = "Canceled";
|
||||
$lang->mr->pipelineUnknown = "Unknown";
|
||||
$lang->mr->pipelineUnknown = "Unknown";
|
||||
|
||||
$lang->mr->pipelineStatus = array();
|
||||
$lang->mr->pipelineStatus['success'] = "success";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
$lang->mr = new stdclass;
|
||||
$lang->mr->common = "合并请求";
|
||||
$lang->mr->overview = "概况";
|
||||
$lang->mr->view = "概况";
|
||||
$lang->mr->create = "创建{$lang->mr->common}";
|
||||
$lang->mr->apiCreate = "接口:创建{$lang->mr->common}";
|
||||
$lang->mr->browse = "浏览{$lang->mr->common}";
|
||||
@@ -105,6 +105,7 @@ $lang->mr->apiError->createMR = "通过API创建合并请求失败,失败原
|
||||
$lang->mr->apiError->sudo = "无法以当前用户绑定的GitLab账户进行操作,失败原因:%s";
|
||||
|
||||
$lang->mr->createFailedFromAPI = "创建合并请求失败。";
|
||||
$lang->mr->hasSameOpenedMR = "存在重复并且未关闭的合并请求。";
|
||||
$lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。";
|
||||
$lang->mr->reopenSuccess = "已重新打开合并请求。";
|
||||
$lang->mr->closeSuccess = "已关闭合并请求。";
|
||||
@@ -113,17 +114,17 @@ $lang->mr->apiErrorMap[1] = "You can't use same project/branch for source and ta
|
||||
$lang->mr->apiErrorMap[2] = "/Another open merge request already exists for this source branch: !([0-9]+)/";
|
||||
|
||||
$lang->mr->errorLang[1] = '源项目分支与目标项目分支不能相同';
|
||||
$lang->mr->errorLang[2] = '存在另外一个同样的合并请求在源项目分支中: !%u';
|
||||
$lang->mr->errorLang[2] = '存在另外一个同样的合并请求在源项目分支中: ID%u';
|
||||
|
||||
$lang->mr->from = "从";
|
||||
$lang->mr->to = "合并到";
|
||||
$lang->mr->at = "于";
|
||||
|
||||
$lang->mr->pipeline = "流水线";
|
||||
$lang->mr->pipelineSuccess = "已通过";
|
||||
$lang->mr->pipelineFailed = "未通过";
|
||||
$lang->mr->pipeline = "流水线";
|
||||
$lang->mr->pipelineSuccess = "已通过";
|
||||
$lang->mr->pipelineFailed = "未通过";
|
||||
$lang->mr->pipelineCanceled = "已取消";
|
||||
$lang->mr->pipelineUnknown = "未知";
|
||||
$lang->mr->pipelineUnknown = "未知";
|
||||
|
||||
$lang->mr->pipelineStatus = array();
|
||||
$lang->mr->pipelineStatus['success'] = "已通过";
|
||||
@@ -136,6 +137,7 @@ $lang->mr->hasNoConflict = "可以合并";
|
||||
$lang->mr->acceptMR = "合并";
|
||||
$lang->mr->mergeFailed = "无法合并,请核对合并请求状态";
|
||||
$lang->mr->mergeSuccess = "已成功合并";
|
||||
$lang->mr->mergeSuccess = "已成功合并";
|
||||
|
||||
$lang->mr->todomessage = "项目中指派给你了";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
$lang->mr = new stdclass;
|
||||
$lang->mr->common = "合併請求";
|
||||
$lang->mr->overview = "概況";
|
||||
$lang->mr->view = "概況";
|
||||
$lang->mr->create = "創建{$lang->mr->common}";
|
||||
$lang->mr->apiCreate = "介面:創建{$lang->mr->common}";
|
||||
$lang->mr->browse = "瀏覽{$lang->mr->common}";
|
||||
|
||||
+128
-24
@@ -93,6 +93,9 @@ class mrModel extends model
|
||||
->add('createdDate', helper::now())
|
||||
->get();
|
||||
|
||||
$result = $this->checkSameOpened($MR->gitlabID, $MR->sourceProject, $MR->sourceBranch, $MR->targetProject, $MR->targetBranch);
|
||||
if($result['result'] == 'fail') return $result;
|
||||
|
||||
/* Exec Job */
|
||||
if(isset($MR->jobID) && $MR->jobID)
|
||||
{
|
||||
@@ -138,21 +141,8 @@ class mrModel extends model
|
||||
{
|
||||
$this->dao->delete()->from(TABLE_MR)->where('id')->eq($MRID)->exec();
|
||||
|
||||
foreach($this->lang->mr->apiErrorMap as $key => $errorMsg)
|
||||
{
|
||||
if(strpos($errorMsg, '/') === 0)
|
||||
{
|
||||
$result = preg_match($errorMsg, $rawMR->message[0], $matches);
|
||||
if($result) $errorMessage = sprintf(zget($this->lang->mr->errorLang, $key), $matches[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($rawMR->message[0] == $errorMsg) $errorMessage = zget($this->lang->mr->errorLang, $key, $rawMR->message[0]);
|
||||
}
|
||||
|
||||
if(isset($errorMessage)) break;
|
||||
}
|
||||
return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->createMR, isset($errorMessage) ? $errorMessage : $rawMR->message[0]));
|
||||
$errorMessage = $this->convertApiError($rawMR->message);
|
||||
return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->createMR, $errorMessage));
|
||||
}
|
||||
|
||||
/* Create MR failed. */
|
||||
@@ -171,10 +161,7 @@ class mrModel extends model
|
||||
$newMR->mergeStatus = $rawMR->merge_status;
|
||||
|
||||
/* Update MR in Zentao database. */
|
||||
$this->dao->update(TABLE_MR)->data($newMR)
|
||||
->where('id')->eq($MRID)
|
||||
->autoCheck()
|
||||
->exec();
|
||||
$this->dao->update(TABLE_MR)->data($newMR)->where('id')->eq($MRID)->autoCheck()->exec();
|
||||
if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError());
|
||||
return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse'));
|
||||
}
|
||||
@@ -209,6 +196,7 @@ class mrModel extends model
|
||||
$MR->title = $this->lang->mr->common . ' ' . $postData->RepoSrcBranch . $this->lang->mr->to . $postData->RepoDistBranch ;
|
||||
$MR->repoID = $repo->id;
|
||||
$MR->jobID = isset($repo->job->id) ? $repo->job->id : 0;
|
||||
$MR->status = 'opened';
|
||||
$MR->synced = '0';
|
||||
$MR->needCI = '1';
|
||||
$MR->hasNoConflict = $postData->MergeStatus ? '0' : '1';
|
||||
@@ -216,6 +204,13 @@ class mrModel extends model
|
||||
$MR->createdBy = $this->app->user->account;
|
||||
$MR->createdDate = date('Y-m-d H:i:s');
|
||||
|
||||
$result = $this->checkSameOpened($MR->gitlabID, $MR->sourceProject, $MR->sourceBranch, $MR->targetProject, $MR->targetBranch);
|
||||
if($result['result'] == 'fail')
|
||||
{
|
||||
dao::$errors[] = $result['message'];
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->dao->insert(TABLE_MR)->data($MR, $this->config->mr->create->skippedFields)
|
||||
->batchCheck($this->config->mr->apicreate->requiredFields, 'notempty')
|
||||
->autoCheck()
|
||||
@@ -238,17 +233,16 @@ class mrModel extends model
|
||||
$compile = $this->loadModel('compile')->getByQueue($pipeline->queue);
|
||||
$newMR->compileID = $compile->id;
|
||||
$newMR->compileStatus = $compile->status;
|
||||
if($newMR->compileStatus == 'failure') $newMR->status = 'closed';
|
||||
}
|
||||
else
|
||||
{
|
||||
$newMR->compileStatus = $pipeline->status;
|
||||
if($newMR->compileStatus == 'create_fail') $newMR->status = 'closed';
|
||||
}
|
||||
|
||||
/* Update MR in Zentao database. */
|
||||
$this->dao->update(TABLE_MR)->data($newMR)
|
||||
->where('id')->eq($MRID)
|
||||
->autoCheck()
|
||||
->exec();
|
||||
$this->dao->update(TABLE_MR)->data($newMR)->where('id')->eq($MRID)->autoCheck()->exec();
|
||||
if(dao::isError()) return false;
|
||||
}
|
||||
return true;
|
||||
@@ -303,6 +297,11 @@ class mrModel extends model
|
||||
|
||||
/* Known issue: `reviewer_ids` takes no effect. */
|
||||
$rawMR = $this->apiUpdateMR($oldMR->gitlabID, $oldMR->targetProject, $oldMR->mriid, $newMR);
|
||||
if(!isset($rawMR->id) and isset($rawMR->message))
|
||||
{
|
||||
$errorMessage = $this->convertApiError($rawMR->message);
|
||||
return array('result' => 'fail', 'message' => $errorMessage);
|
||||
}
|
||||
|
||||
/* Update MR in Zentao database. */
|
||||
$this->dao->update(TABLE_MR)->data($MR, $this->config->mr->edit->skippedFields)
|
||||
@@ -533,6 +532,35 @@ class mrModel extends model
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get same opened mr by api.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $sourceProject
|
||||
* @param string $sourceBranch
|
||||
* @param int $targetProject
|
||||
* @param string $targetBranch
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiGetSameOpened($gitlabID, $sourceProject, $sourceBranch, $targetProject, $targetBranch)
|
||||
{
|
||||
if(empty($gitlabID) or empty($sourceProject) or empty($sourceBranch) or empty($targetProject) or empty($targetBranch)) return null;
|
||||
|
||||
$url = sprintf($this->loadModel('gitlab')->getApiRoot((int)$gitlabID), "/projects/{$sourceProject}/merge_requests") . "&state=opened&source_branch={$sourceBranch}&target_branch={$targetBranch}";
|
||||
$response = json_decode(commonModel::http($url));
|
||||
|
||||
if($response)
|
||||
{
|
||||
foreach($response as $mr)
|
||||
{
|
||||
if(empty($mr->source_project_id) or empty($mr->target_project_id)) return null;
|
||||
if($mr->source_project_id == $sourceProject and $mr->target_project_id == $targetProject) return $mr;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single MR by API.
|
||||
*
|
||||
@@ -1254,6 +1282,24 @@ class mrModel extends model
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get linked MR pairs.
|
||||
*
|
||||
* @param int $objectID
|
||||
* @param string $objectType
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getLinkedMRPairs($objectID, $objectType = 'story')
|
||||
{
|
||||
return $this->dao->select("t2.id,t2.title")->from(TABLE_RELATION)->alias('t1')
|
||||
->leftJoin(TABLE_MR)->alias('t2')->on('t1.AID = t2.id')
|
||||
->where('t1.AType')->eq('mr')
|
||||
->andWhere('t1.BType')->eq($objectType)
|
||||
->andWhere('t1.BID')->eq($objectID)
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an mr link.
|
||||
*
|
||||
@@ -1327,7 +1373,7 @@ class mrModel extends model
|
||||
$commits = array();
|
||||
foreach($DiffCommits as $DiffCommit)
|
||||
{
|
||||
$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');
|
||||
@@ -1400,4 +1446,62 @@ class mrModel extends model
|
||||
$this->action->create('task', $task->id, 'mergedmr', '', helper::createLink('mr', 'view', "mr={$MR->id}"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check same opened mr for source branch.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $sourceProject
|
||||
* @param string $sourceBranch
|
||||
* @param int $targetProject
|
||||
* @param string $targetBranch
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function checkSameOpened($gitlabID, $sourceProject, $sourceBranch, $targetProject, $targetBranch)
|
||||
{
|
||||
if(empty($sourceProject) or empty($sourceBranch) or empty($targetProject) or empty($targetBranch)) return array('result' => 'success');
|
||||
|
||||
$dbOpenedCount = $this->dao->select('count(*) as count')->from(TABLE_MR)
|
||||
->where('gitlabID')->eq($gitlabID)
|
||||
->andWhere('sourceProject')->eq($sourceProject)
|
||||
->andWhere('sourceBranch')->eq($sourceBranch)
|
||||
->andWhere('targetProject')->eq($targetProject)
|
||||
->andWhere('targetBranch')->eq($targetBranch)
|
||||
->andWhere('status')->eq('opened')
|
||||
->andWhere('deleted')->eq('0')
|
||||
->fetch('count');
|
||||
if($dbOpenedCount > 0) return array('result' => 'fail', 'message' => $this->lang->mr->hasSameOpenedMR);
|
||||
|
||||
if($this->apiGetSameOpened($gitlabID, $sourceProject, $sourceBranch, $targetProject, $targetBranch)) return array('result' => 'fail', 'message' => $this->lang->mr->hasSameOpenedMR);
|
||||
return array('result' => 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert API error.
|
||||
*
|
||||
* @param array $message
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function convertApiError($message)
|
||||
{
|
||||
if(is_array($message)) $message = $message[0];
|
||||
if(!is_string($message)) return $message;
|
||||
|
||||
foreach($this->lang->mr->apiErrorMap as $key => $errorMsg)
|
||||
{
|
||||
if(strpos($errorMsg, '/') === 0)
|
||||
{
|
||||
$result = preg_match($errorMsg, $message, $matches);
|
||||
if($result) $errorMessage = sprintf(zget($this->lang->mr->errorLang, $key), $matches[1]);
|
||||
}
|
||||
elseif($message == $errorMsg)
|
||||
{
|
||||
$errorMessage = zget($this->lang->mr->errorLang, $key, $message);
|
||||
}
|
||||
if(isset($errorMessage)) break;
|
||||
}
|
||||
return isset($errorMessage) ? $errorMessage : $message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
<?php endif;?>
|
||||
<td class='c-actions'>
|
||||
<?php
|
||||
common::printLink('mr', 'view', "mr={$MR->id}", '<i class="icon icon-eye"></i>', '', "title='{$lang->mr->overview}' class='btn btn-info'");
|
||||
common::printLink('mr', 'view', "mr={$MR->id}", '<i class="icon icon-eye"></i>', '', "title='{$lang->mr->view}' class='btn btn-info'");
|
||||
common::printLink('mr', 'edit', "mr={$MR->id}", '<i class="icon icon-edit"></i>', '', "title='{$lang->mr->edit}' class='btn btn-info'");
|
||||
common::printLink('mr', 'diff', "mr={$MR->id}", '<i class="icon icon-diff"></i>', '', "title='{$lang->mr->viewDiff}' class='btn btn-info'");
|
||||
common::printLink('mr', 'link', "mr={$MR->id}", '<i class="icon icon-link"></i>', '', "title='{$lang->mr->link}' class='btn btn-info'" . ($MR->linkButton == false ? 'disabled' : ''));
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<div id='mainContent' class='main-content'>
|
||||
<div class='tabs' id='tabsNav'>
|
||||
<ul class='nav nav-tabs'>
|
||||
<li><?php echo html::a(inlink('view', "mr={$MR->id}"), $lang->mr->overview);?></li>
|
||||
<li><?php echo html::a(inlink('view', "mr={$MR->id}"), $lang->mr->view);?></li>
|
||||
<li class='active'><?php echo html::a('#', $lang->mr->viewDiff);?></li>
|
||||
<li><?php echo html::a(inlink('link', "mr={$MR->id}&type=story"), html::icon($lang->icons['story'], 'text-primary') . ' ' . $lang->productplan->linkedStories);?></a></li>
|
||||
<li><?php echo html::a(inlink('link', "mr={$MR->id}&type=bug"), html::icon($lang->icons['bug'], 'text-red') . ' ' . $lang->productplan->linkedBugs);?></a></li>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<div id='mainContent' class='main-content'>
|
||||
<div class='tabs' id='tabsNav'>
|
||||
<ul class='nav nav-tabs'>
|
||||
<li><?php echo html::a(inlink('view', "mr={$MR->id}"), $lang->mr->overview);?></li>
|
||||
<li><?php echo html::a(inlink('view', "mr={$MR->id}"), $lang->mr->view);?></li>
|
||||
<li><?php echo html::a(inlink('diff', "mr={$MR->id}"), $lang->mr->viewDiff);?></li>
|
||||
<li class='<?php if($type == 'story') echo 'active'?>'><a href='#stories' data-toggle='tab'><?php echo html::icon($lang->icons['story'], 'text-primary') . ' ' . $lang->productplan->linkedStories;?></a></li>
|
||||
<li class='<?php if($type == 'bug') echo 'active'?>'><a href='#bugs' data-toggle='tab'><?php echo html::icon($lang->icons['bug'], 'text-red') . ' ' . $lang->productplan->linkedBugs;?></a></li>
|
||||
@@ -168,7 +168,7 @@
|
||||
<?php printf('%03d', $bug->id);?>
|
||||
</td>
|
||||
<td><span class='label-pri label-pri-<?php echo $bug->pri;?>' title='<?php echo zget($lang->bug->priList, $bug->pri, $bug->pri);?>'><?php echo zget($lang->bug->priList, $bug->pri, $bug->pri);?></span></td>
|
||||
<td class='text-left nobr' title='<?php echo $bug->title?>'><?php echo html::a($this->createLink('bug', 'view', "bugID=$bug->id"), $bug->title, '', 'data-app="product"');?></td>
|
||||
<td class='text-left nobr' title='<?php echo $bug->title?>'><?php echo html::a($this->createLink('bug', 'view', "bugID=$bug->id"), $bug->title);?></td>
|
||||
<td><?php echo zget($users, $bug->openedBy);?></td>
|
||||
<td><?php echo zget($users, $bug->assignedTo);?></td>
|
||||
<td>
|
||||
@@ -230,7 +230,7 @@
|
||||
<?php printf('%03d', $task->id);?>
|
||||
</td>
|
||||
<td><span class='label-pri label-pri-<?php echo $task->pri;?>' title='<?php echo zget($lang->task->priList, $task->pri, $task->pri);?>'><?php echo zget($lang->task->priList, $task->pri, $task->pri);?></span></td>
|
||||
<td class='text-left nobr' title='<?php echo $task->name?>'><?php echo html::a($this->createLink('task', 'view', "taskID=$task->id"), $task->name, '', 'data-app="product"');?></td>
|
||||
<td class='text-left nobr' title='<?php echo $task->name?>'><?php echo html::a($this->createLink('task', 'view', "taskID=$task->id"), $task->name);?></td>
|
||||
<td><?php echo zget($users, $task->finishedBy);?></td>
|
||||
<td><?php echo zget($users, $task->assignedTo);?></td>
|
||||
<td>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<div id="mainContent" class="main-content">
|
||||
<div class='tabs' id='tabsNav'>
|
||||
<ul class='nav nav-tabs'>
|
||||
<li class='active'><?php echo html::a('###', $lang->mr->overview);?></li>
|
||||
<li class='active'><?php echo html::a('###', $lang->mr->view);?></li>
|
||||
<li><?php echo html::a(inlink('diff', "mr={$MR->id}"), $lang->mr->viewDiff);?></li>
|
||||
<li><?php echo html::a(inlink('link', "mr={$MR->id}&type=story"), html::icon($lang->icons['story'], 'text-primary') . ' ' . $lang->productplan->linkedStories);?></a></li>
|
||||
<li><?php echo html::a(inlink('link', "mr={$MR->id}&type=bug"), html::icon($lang->icons['bug'], 'text-red') . ' ' . $lang->productplan->linkedBugs);?></a></li>
|
||||
|
||||
Reference in New Issue
Block a user