【问题标题】:Using curl command for git release使用 curl 命令发布 git
【发布时间】:2018-03-18 05:40:32
【问题描述】:

我不熟悉使用以下命令。我在 git bash 中运行了这个命令,但无法创建标签。

curl -s -k -X POST -H "Content-Type:application/json" "https://github.com/XXXXXX/custom-component/releases?1.2," -d '{ "user" : { 'email' : 'XXXXXXX', 'password' : 'XXXXX'} ,"tag_name": "1.2.1", "target_commitish": "master", "name": "1234", "body": "Release of version 1234", "draft": false, "prerelease": false}' -b cookie

执行上述命令后,我在存储库中找不到任何更改

我的输出会喜欢一些 html 输出

  <!DOCTYPE html>
       <html>
            <head>
         <meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; b-uri 'self'; connect-src 'self'; form-action 'self'; img-src data:; script-srself'; style-src 'unsafe-inline'">
<meta content="origin" name="referrer">
<title>Oh no &middot; GitHub</title>
<style type="text/css" media="screen">
  body {
    background-color: #f1f1f1;
    margin: 0;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  }

  .container { margin: 50px auto 40px auto; width: 600px; text-align: cen; }

  a { color: #4183c4; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { letter-spacing: -1px; line-height: 60px; font-size: 60px; font-wei: 100; margin: 0px; text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and (     -o-min-device-pixel-ratio: 2/1),
  only screen and (        min-device-pixel-ratio: 2),
  only screen and (                min-resolution: 192dpi),
  only screen and (                min-resolution: 2dppx) {
    .logo-img-1x { display: none; }
    .logo-img-2x { display: inline-block; }
  }

  #suggestions {
    margin-top: 35px;
    color: #ccc;

【问题讨论】:

  • 我怀疑这不是格式正确的 JSON 的原因。 (JSON 只是双引号,绝不是单引号)。但是你能粘贴命令输出吗? (好吧,再读一遍后,单引号也破坏了-d 参数,所以无论如何你都必须修复它)
  • @Arount 它就像一些 html 输出
  • 如果我更改为 api.github.com 出现类似 "message": "Not Found" 的错误, 如何发送请求?

标签: bash curl github


【解决方案1】:

首先,您应该使用api.github.com。其次,您需要将 Authorization token 传递到您的标题中。例如

curl -v -H "Authorization: token TOKEN" https://api.github.com/repos/octodocs-test/test

您可以在your personal access token page 上找到您的个人访问令牌。没有的话可以create一个。


所以你的命令可能看起来:

curl -v -s \
  -H "Authorization: token xxxxxxxxx" \
  -H "Content-Type:application/json" \
  "https://api.github.com/repos/:owner/:repo/releases" \
  -d '{ "user" : { "email" : "XXXXXXX", "password" : "XXXXX"}, "tag_name": "1.2.1", "target_commitish": "master", "name": "1234", "body": "Release of version 1234", "draft": false, "prerelease": false}'

见:GitHub API v3 | GitHub Developer Guide

REST API v3 Releases docs page查看可用的发布相关端点,例如:

  • 按标签名称获取版本:GET /repos/:owner/:repo/releases/tags/:tag
  • 创建版本:POST /repos/:owner/:repo/releases

另见:How to use Github Release API to make a release without source code?

【讨论】:

    猜你喜欢
    • 2017-03-31
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多