4

您好我正在尝试使用 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"
    }
}  
4

2 回答 2

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'
于 2016-07-08T18:01:27.203 回答
1

用于创建新标签的GiLab API位于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是验证方式的错误。

于 2016-07-08T07:58:55.240 回答