4

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"
    }
}  
Pramod Setlur
  • 811
  • 1
  • 15
  • 27

2 Answers2

4

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'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Pramod Setlur
  • 811
  • 1
  • 15
  • 27
1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you, but it is still the same ➜ /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 { "message": null, "name": "tags/v1.0.0" } i suppose this is what you asked me to try? if not can you please elaborate?\ – Pramod Setlur Jul 08 '16 at 08:53
  • @PramodSetlur Try and modify https://github.com/gitlabhq/gitlabhq/blob/91fa250038e9182988319f088fb84741b6e2efc9/lib/gitlab/git_ref_validator.rb to add more trace, in order to see what exact git command is run. – VonC Jul 08 '16 at 08:54
  • Dont have access to the box hosting the API. :/ – Pramod Setlur Jul 08 '16 at 08:56
  • 1
    @PramodSetlur OK. Try and install one on your desk and test it with curl calls to localhost: there you would be able to modify anything you want. – VonC Jul 08 '16 at 08:57