您好我正在尝试使用gitlab api为项目创建标记,但它一直说标记名称无效。我甚至尝试在gitlab api doc中使用该示例。
这是我的尝试:
➜ /tmp curl -X POST -d @body.json https://mygitlabserver.com/api/v3/projects/9733/repository/tags --header "Content-Type:application/json" -H "PRIVATE-TOKEN:sNW8AGtLMdSGAJiGQ-gV"
{"message":"Tag name invalid"}%
➜ /tmp cat body.json
{
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-05-28T04:42:42-07:00",
"committed_date": "2012-05-28T04:42:42-07:00",
"committer_email": "jack@example.com",
"committer_name": "Jack Smith",
"id": "2695effb5807a22ff3d138d593fd856244e155e7",
"message": "Initial commit",
"parents_ids": [
"2a4b78934375d7f53875269ffd4f45fd83a84ebe"
]
},
"message": null,
"name": "v1.0.0",
"release": {
"description": "Amazing release. Wow",
"tag_name": "1.0.0"
}
}
答案 0 :(得分:4)
我这样做了。
这是一个帖子请求:
curl -X POST -k -H 'PRIVATE-TOKEN: XXXXXXX' \
'https://mygitlabserver.com/api/v3/projects/9733/repository/tags?tag_name=0.0.9&ref=develop'
答案 1 :(得分:1)
GiLab API for creating a new tag位于lib/api/tags.rb
# Create tag
#
# Parameters:
# id (required) - The ID of a project
# tag_name (required) - The name of the tag
# ref (required) - Create tag from commit sha or branch
# message (optional) - Specifying a message creates an annotated tag.
# Example Request:
# POST /projects/:id/repository/tags
post ':id/repository/tags' do
authorize_push_project
message = params[:message] || nil
result = CreateTagService.new(user_project, current_user).
execute(params[:tag_name], params[:ref], message, params[:release_description])
它会调用app/services/create_tag_service.rb
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
那,lib/gitlab/git_ref_validator.rb
实际上打电话给git check-ref-format
:
def validate(ref_name)
Gitlab::Utils.system_silent(
%W(#{Gitlab.config.git.bin_path} check-ref-format refs/#{ref_name}))
end
由于其中一条规则是:
它们必须包含至少一个
/
。这会强制存在类似heads/
,tags/
等类别,但实际名称不受限制。
尝试,仅用于使用以tags/xxx
开头的标记名进行测试。
如果这项工作,那将是tag_name
如何验证的错误。