From 29e78f3321eb55a87c5d571db0cff1926843e686 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 29 Jul 2024 10:54:17 +0800 Subject: [PATCH] + [task#124017] Add method to create tag by gitlab API. --- module/gitlab/model.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index c854f14e35..a9065e853f 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -940,6 +940,25 @@ class gitlabModel extends model return json_decode(commonModel::http($url, $branch, array(), array(), 'json')); } + /** + * 通过API创建一个标签。 + * Creates a new tag in the GitLab repository using the GitLab API. + * @link https://docs.gitlab.com/ee/api/tags.html#create-a-new-tag + * + * @param int $gitlabID The ID of the GitLab instance. + * @param int $projectID The ID of the project in GitLab. + * @param object $tag An object containing the tag details, including the tag name and reference. + * @return object|array|null|false The response from the GitLab API, or false if the tag name or reference is empty. + */ + public function apiCreateTag(int $gitlabID, int $projectID, object $tag): object|array|null|false + { + if(empty($tag->tag_name) or empty($tag->ref)) return false; + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/repository/tags"); + return json_decode(commonModel::http($url, $tag, array(), array(), 'json')); + } + /** * 通过api获取一个项目信息。 * Get single project by API.