* Finish task #46544,46556.

This commit is contained in:
liyuchun
2021-12-30 14:05:57 +08:00
parent 07756750db
commit 1f4ee55810
11 changed files with 285 additions and 48 deletions
+74 -3
View File
@@ -2403,10 +2403,18 @@ class gitlabModel extends model
{
foreach($response->message as $field => $fieldErrors)
{
foreach($fieldErrors as $error)
if(is_string($fieldErrors))
{
$errorKey = array_search($error, $this->lang->gitlab->apiError);
if($error) dao::$errors[$field][] = $errorKey === false ? $error : zget($this->lang->gitlab->errorLang, $errorKey);
$errorKey = array_search($fieldErrors, $this->lang->gitlab->apiError);
if($fieldErrors) dao::$errors[$field][] = $errorKey === false ? $fieldErrors : zget($this->lang->gitlab->errorLang, $errorKey);
}
else
{
foreach($fieldErrors as $error)
{
$errorKey = array_search($error, $this->lang->gitlab->apiError);
if($error) dao::$errors[$field][] = $errorKey === false ? $error : zget($this->lang->gitlab->errorLang, $errorKey);
}
}
}
}
@@ -2542,6 +2550,69 @@ class gitlabModel extends model
return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE')));
}
/**
* Create gitlab protect tag.
*
* @param int $gitlabID
* @param int $projectID
* @param string $tag
* @access public
* @return bool
*/
public function createTagPriv($gitlabID, $projectID, $tag = '')
{
$priv = fixer::input('post')->get();
if(empty($priv->name)) dao::$errors['name'][] = $this->lang->gitlab->branch->emptyPrivNameError;
$singleTag = $this->apiGetSingleTagPriv($gitlabID, $projectID, $priv->name);
if(empty($tag) && !empty($singleTag->id)) dao::$errors['name'][] = $this->lang->gitlab->tag->issetPrivNameError;
if(dao::isError()) return false;
if(!empty($tag) && !empty($singleTag->name)) $this->apiDeleteTagPriv($gitlabID, $projectID, $tag);
$response = $this->apiCreateTagPriv($gitlabID, $projectID, $priv);
if(!empty($response->id))
{
$action = empty($tag) ? 'created' : 'edited';
$this->loadModel('action')->create('gitlabtagpriv', $response->id, $action, '', $response->name);
return true;
}
return $this->apiErrorHandling($response);
}
/**
* Get single protct tag by API.
*
* @param int $gitlabID
* @param int $projectID
* @param string $tag
* @access public
* @return object
*/
public function apiGetSingleTagPriv($gitlabID, $projectID, $tag)
{
if(empty($gitlabID)) return false;
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/protected_tags/$tag");
return json_decode(commonModel::http($url));
}
/**
* Create a gitab protect tag by api.
*
* @param int $gitlabID
* @param int $projectID
* @param object $priv
* @access public
* @return object
*/
public function apiCreateTagPriv($gitlabID, $projectID, $priv)
{
if(empty($gitlabID)) return false;
if(empty($priv->name)) return false;
$url = sprintf($this->getApiRoot($gitlabID), "/projects/" . $projectID . '/protected_tags');
return json_decode(commonModel::http($url, $priv));
}
/**
* Check access level.
*