From a74e8c06ad9ce2cf4a0c3ea68e63cecb8a5cb797 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 29 Jul 2024 10:52:08 +0800 Subject: [PATCH] + [task#124017] Add method to create tag for gitlab. --- lib/scm/gitlab.class.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index e4a8235841..4db3bd160d 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -219,6 +219,28 @@ class gitlabRepo return array('result' => empty($result->name) ? 'fail' : 'success', 'message' => empty($result->name) ? $result->message : ''); } + /** + * Creates a new tag in the GitLab repository. + * + * @param string $tagName The name of the tag to be created. + * @param string $ref The revision of the tag, a commit SHA, another tag name, or branch name. + * @param string $comment An optional comment for the tag. + * @return array Returns an array with the result of the operation and a message. If the tag already exists, the result will be 'fail' and the message will be 'Tag is exists'. If the operation fails, the result will be 'fail' and the message will be 'Created fail.'. Otherwise, the result will be 'success' and the message will be an empty string. + */ + public function createTag($tagName = '', $ref = 'master', $comment = '') + { + global $app; + + $tag = new stdclass(); + $tag->tag_name = $tagName; + $tag->ref = $ref; /* Create a tag from a commit SHA, another tag name, or branch name. */ + $tag->comment = $comment; + + $result = $app->control->loadModel('gitlab')->apiCreateTag($this->repo->serviceHost, $this->repo->serviceProject, $tag); + + return array('result' => empty($result->name) ? 'fail' : 'success', 'message' => empty($result->name) ? $result->message : ''); + } + /** * Get last log. *