+ Add user info for scm create branch.

This commit is contained in:
caoyanyi
2023-11-02 14:14:05 +08:00
parent d2f1458f6f
commit 9720ed1bc1
2 changed files with 13 additions and 7 deletions
+9 -5
View File
@@ -188,12 +188,16 @@ class Gitea
*/
public function createBranch($branchName = '', $ref = 'master')
{
chdir($this->root);
$res = execCmd(escapeCmd("{$this->client} checkout -b {$branchName} origin/{$ref}"), 'array');
if(empty($res[0])) return array('result' => 'fail', 'message' => 'Branch is exists.');
global $app;
$project = $app->control->loadModel('gitea')->getApiRoot($this->repo->serviceHost);
execCmd(escapeCmd("{$this->client} push origin {$branchName}"), 'array');
return array('result' => 'success', 'message' => '');
$url = sprintf($apiRoot, "/repos/{$this->repo->serviceProject}/branches");
$param = new stdclass();
$param->old_branch_name = $ref;
$param->new_branch_name = $branchName;
$result = json_decode(commonModel::http($url), $param);
return array('result' => empty($result->name) ? 'fail' : 'success', 'message' => zget($result, 'message', 'Error'));
}
/**
+4 -2
View File
@@ -22,6 +22,7 @@ class gitlab
$this->root = rtrim($root, '/') . '/';
$this->token = $password;
$this->branch = isset($_COOKIE['repoBranch']) ? $_COOKIE['repoBranch'] : 'HEAD';
$this->repo = $repo;
}
/**
@@ -209,12 +210,13 @@ class gitlab
*/
public function createBranch($branchName = '', $ref = 'master')
{
global $app;
$param = new stdclass();
$param->ref = $ref;
$param->branch = $branchName;
$result = $app->control->loadModel('gitlab')->apiCreateBranch($this->repo->serviceHost, $this->repo->serviceProject, $param);
$api = $this->root . 'branches?private_token=' . $this->token;
$result = json_decode(commonModel::http($api, $param));
return array('result' => empty($result->name) ? 'fail' : 'success', 'message' => $result->message);
}