【问题标题】:gitlab api Tag creation errorgitlab api标签创建错误
【发布时间】:2016-11-10 15:46:30
【问题描述】:

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

【问题讨论】:

    标签: gitlab gitlab-api


    【解决方案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 验证方式的错误。

    【讨论】:

    • 谢谢,还是一样 ➜ /tmp curl -X POST -d @body.json 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" } 我想这就是你问我试试?如果不能,请详细说明?\
    • @PramodSetlur 尝试修改 github.com/gitlabhq/gitlabhq/blob/… 以添加更多跟踪,以便查看运行的确切 git 命令。
    • 无权访问托管 API 的框。 ://
    • @PramodSetlur 好的。尝试在您的办公桌上安装一个,并通过 curl 调用 localhost 对其进行测试:您可以在那里修改您想要的任何内容。
    【解决方案2】:

    我是这样弄的。

    这是一个post请求:

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

    【讨论】:

    • 很好地抓住了 ref 参数,我在回答中看到了这一点。 +1
    猜你喜欢
    • 2021-12-03
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多