gitlab api Tag creation error

橙三吉。 提交于 2021-02-07 08:15:33

问题


Hi I am trying to create a tag to a project using the gitlab api, but it keeps saying tag name not valid. I even tried using the sample in gitlab api doc.

Here is my attempt:

➜  /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"
    }
}  

回答1:


I got it working this way.

It is a post request:

curl -X POST -k -H 'PRIVATE-TOKEN: XXXXXXX' \
'https://mygitlabserver.com/api/v3/projects/9733/repository/tags?tag_name=0.0.9&ref=develop'



回答2:


The GiLab API for creating a new tag is inlib/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])

It calls app/services/create_tag_service.rb

valid_tag = Gitlab::GitRefValidator.validate(tag_name)

That, in lib/gitlab/git_ref_validator.rb actually wrap a call to 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

Since one of the rules is:

They must contain at least one /. This enforces the presence of a category like heads/, tags/ etc. but the actual names are not restricted.

Try, just for testing with a tag name starting with tags/xxx.

If that work, that would be a bug in how the tag_name is validated.



来源:https://stackoverflow.com/questions/38260467/gitlab-api-tag-creation-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!