* Modify protect branch tips.
This commit is contained in:
@@ -566,4 +566,31 @@ class giteaModel extends model
|
||||
$url = sprintf($this->getApiRoot($giteaID), "/repos/$projectID/branches/$branch");
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get protect branches of one project.
|
||||
*
|
||||
* @param int $giteaID
|
||||
* @param string $project
|
||||
* @param string $keyword
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function apiGetBranchPrivs($giteaID, $project, $keyword = '')
|
||||
{
|
||||
$keyword = urlencode($keyword);
|
||||
$url = sprintf($this->getApiRoot($giteaID), "/repos/$project/branch_protections");
|
||||
$branches = json_decode(commonModel::http($url));
|
||||
|
||||
if(!is_array($branches)) return $branches;
|
||||
|
||||
$newBranches = array();
|
||||
foreach($branches as $branch)
|
||||
{
|
||||
$branch->name = $branch->branch_name;
|
||||
if(empty($keyword) || stristr($branch->name, $keyword)) $newBranches[] = $branch;
|
||||
}
|
||||
|
||||
return $newBranches;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +156,14 @@ class mr extends control
|
||||
$scm = $host->type;
|
||||
$branchList = $this->loadModel($scm)->getBranches($MR->hostID, $MR->targetProject);
|
||||
|
||||
$MR->canDeleteBranch = true;
|
||||
$branchPrivs = $this->loadModel($scm)->apiGetBranchPrivs($MR->hostID, $MR->sourceProject);
|
||||
foreach($branchPrivs as $priv)
|
||||
{
|
||||
if($MR->canDeleteBranch and $priv->name == $MR->sourceBranch) $MR->canDeleteBranch = false;
|
||||
}
|
||||
|
||||
|
||||
$targetBranchList = array();
|
||||
foreach($branchList as $branch) $targetBranchList[$branch] = $branch;
|
||||
|
||||
@@ -1017,4 +1025,24 @@ class mr extends control
|
||||
$result = $this->mr->checkSameOpened($hostID, $sourceProject, $sourceBranch, $targetProject, $targetBranch);
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax get branch pivs.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @param int|string $project
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function ajaxGetBranchPivs($hostID, $project)
|
||||
{
|
||||
$host = $this->loadModel('pipeline')->getByID($hostID);
|
||||
$scm = $host->type;
|
||||
if($scm == 'gitea') $project = urldecode(base64_decode($project));
|
||||
|
||||
$branches = $this->loadModel($scm)->apiGetBranchPrivs($hostID, $project);
|
||||
$branchPrivs = array();
|
||||
foreach($branches as $branch) $branchPrivs[$branch->name] = $branch->name;
|
||||
echo json_encode($branchPrivs);
|
||||
}
|
||||
}
|
||||
|
||||
+29
-4
@@ -13,6 +13,24 @@ function urlencode(param)
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get branch priv.
|
||||
*
|
||||
* @param int|string $project
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function getBranchPriv(project)
|
||||
{
|
||||
var hostID = $('#hostID').val();
|
||||
var branchUrl = createLink('mr', 'ajaxGetBranchPivs', "hostID=" + hostID + "&project=" + project);
|
||||
$.get(branchUrl, function(response)
|
||||
{
|
||||
branchPrivs = eval('(' + response + ')');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#hostID').change(function()
|
||||
@@ -66,14 +84,19 @@ $(function()
|
||||
$('#repoID').html('').append(response);
|
||||
$('#repoID').chosen().trigger("chosen:updated");;
|
||||
});
|
||||
|
||||
if(sourceProject) getBranchPriv(sourceProject);
|
||||
});
|
||||
|
||||
$('#sourceBranch,#targetBranch').change(function()
|
||||
{
|
||||
var sourceProject = urlencode($('#sourceProject').val());
|
||||
var sourceBranch = urlencode($('#sourceBranch').val());
|
||||
var targetProject = urlencode($('#targetProject').val());
|
||||
var targetBranch = urlencode($('#targetBranch').val());
|
||||
$('#removeSourceBranch').removeAttr('disabled');
|
||||
|
||||
var sourceProject = $('#sourceProject').val();
|
||||
var sourceBranch = $('#sourceBranch').val();
|
||||
var targetProject = $('#targetProject').val();
|
||||
var targetBranch = $('#targetBranch').val();
|
||||
if(branchPrivs[sourceBranch]) $('#removeSourceBranch').attr('disabled', 'true');
|
||||
if(!sourceProject || !sourceBranch || !targetProject || !targetBranch) return false;
|
||||
|
||||
var $this = $(this);
|
||||
@@ -86,9 +109,11 @@ $(function()
|
||||
{
|
||||
alert(response.message);
|
||||
$this.val('').trigger('chosen:updated');
|
||||
if($this.attr('id') == 'sourceBranch') $('#removeSourceBranch').removeAttr('disabled');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$('#repoID').change(function()
|
||||
|
||||
@@ -196,3 +196,4 @@ $lang->mr->linkedTasks = 'Task';
|
||||
$lang->mr->unlinkedTasks = 'Task not linked';
|
||||
$lang->mr->confirmUnlinkTask = "Are you sure to remove this task?";
|
||||
$lang->mr->taskSummary = "There are <strong>%s</strong> tasks on this page";
|
||||
$lang->mr->notDelbranch = "The source branch cannot be deleted when it is a protected branch";
|
||||
|
||||
@@ -196,3 +196,4 @@ $lang->mr->linkedTasks = 'Task';
|
||||
$lang->mr->unlinkedTasks = 'Task not linked';
|
||||
$lang->mr->confirmUnlinkTask = "Are you sure to remove this task?";
|
||||
$lang->mr->taskSummary = "There are <strong>%s</strong> tasks on this page";
|
||||
$lang->mr->notDelbranch = "The source branch cannot be deleted when it is a protected branch";
|
||||
|
||||
@@ -196,3 +196,4 @@ $lang->mr->linkedTasks = 'Task';
|
||||
$lang->mr->unlinkedTasks = 'Task not linked';
|
||||
$lang->mr->confirmUnlinkTask = "Are you sure to remove this task?";
|
||||
$lang->mr->taskSummary = "There are <strong>%s</strong> tasks on this page";
|
||||
$lang->mr->notDelbranch = "The source branch cannot be deleted when it is a protected branch";
|
||||
|
||||
@@ -196,3 +196,4 @@ $lang->mr->linkedTasks = 'Task';
|
||||
$lang->mr->unlinkedTasks = 'Task not linked';
|
||||
$lang->mr->confirmUnlinkTask = "Are you sure to remove this task?";
|
||||
$lang->mr->taskSummary = "There are <strong>%s</strong> tasks on this page";
|
||||
$lang->mr->notDelbranch = "The source branch cannot be deleted when it is a protected branch";
|
||||
|
||||
@@ -196,3 +196,4 @@ $lang->mr->linkedTasks = '任务';
|
||||
$lang->mr->unlinkedTasks = '未关联任务';
|
||||
$lang->mr->confirmUnlinkTask = "您确认移除该任务吗?";
|
||||
$lang->mr->taskSummary = "本页共 <strong>%s</strong> 个任务";
|
||||
$lang->mr->notDelbranch = "源分支为受保护分支时不可删除";
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<?php js::import($jsRoot . 'misc/base64.js');?>
|
||||
<?php js::set('hosts', $hosts);?>
|
||||
<?php js::set('branchPrivs', array());?>
|
||||
<div id='mainContent' class='main-row'>
|
||||
<div class='main-col main-content'>
|
||||
<div class='center-block'>
|
||||
@@ -59,7 +60,7 @@
|
||||
<tr>
|
||||
<th><?php echo $lang->mr->removeSourceBranch;?></th>
|
||||
<td colspan='1'>
|
||||
<div class="checkbox-primary">
|
||||
<div class="checkbox-primary" title="<?php echo $lang->mr->notDelbranch;?>">
|
||||
<input type="checkbox" name="removeSourceBranch" value="1" id="removeSourceBranch">
|
||||
<label for="removeSourceBranch"></label>
|
||||
</div>
|
||||
|
||||
@@ -79,9 +79,9 @@
|
||||
<tr>
|
||||
<th><?php echo $lang->mr->removeSourceBranch;?></th>
|
||||
<td colspan='1'>
|
||||
<div class="checkbox-primary">
|
||||
<?php $checked = $MR->removeSourceBranch== '1' ? 'checked' : '' ?>
|
||||
<input type="checkbox" <?php echo $checked;?> name="removeSourceBranch" value="1" id="removeSourceBranch">
|
||||
<div class="checkbox-primary" title="<?php echo $lang->mr->notDelbranch;?>">
|
||||
<?php $checked = $MR->canDeleteBranch and $MR->removeSourceBranch== '1' ? 'checked' : '' ?>
|
||||
<input type="checkbox" <?php echo $checked;?> <?php if(!$MR->canDeleteBranch) echo 'disabled';?> name="removeSourceBranch" value="1" id="removeSourceBranch">
|
||||
<label for="removeSourceBranch"></label>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user