+ [task#124017] Add method to create tag.

This commit is contained in:
dingguodong
2024-07-29 15:31:16 +08:00
committed by 翟晓剑
parent 303be6d876
commit 122a4c6bb3
+23
View File
@@ -179,6 +179,29 @@ class gogsRepo
return array('result' => 'success', 'message' => '');
}
/**
* 创建标签。
* Create a tag in the 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, $comment = '')
{
$tags = $this->tags('', 'HEAD');
if(isset($tags[$tagName])) return array('result' => 'fail', 'message' => 'Tag is exists');
chdir($this->root);
execCmd(escapeCmd("{$this->client} stash"));
$res = execCmd(escapeCmd("{$this->client} tag {$tagName} {$ref} -m '{$comment}'"), 'array');
if(empty($res[0])) return array('result' => 'fail', 'message' => 'Created fail.');
execCmd(escapeCmd("{$this->client} push origin {$tagName}"), 'array');
return array('result' => 'success', 'message' => '');
}
/**
* Get last log.
*