From 9720ed1bc14e5eb6f3d2f394704d1a2146c01e20 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Thu, 2 Nov 2023 14:14:03 +0800 Subject: [PATCH] + Add user info for scm create branch. --- lib/scm/gitea.class.php | 14 +++++++++----- lib/scm/gitlab.class.php | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index f95ee982d8..3f04c2ea2b 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -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')); } /** diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index 0a68ef1374..89236de238 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -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); }