如何在使用 Github Enterprise API 进行身份验证后创建拉取请求?

How to create a pull request after authentication using Github Enterprise API?

我写了一个 shell 脚本来创建 Github Enterprise API 的拉取请求。

#!/bin/sh
CURRENT_BRANCH=$(git branch --show-current)
git stash save
git checkout master
git pull
UUID=$(uuidgen)
git checkout -b "${UUID}"
npm version patch
git add package.json
git commit -m "#; update version script test"
git push origin "${UUID}"
curl -u [MY_USER_NAME]:[MY_TOKEN] https://github.[MY_ORGANIZATION].com/api/v3/user
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://github.[MY_ORGANIZATION].com/api/v3/repos/Modules/[MY_REPO]/pulls \
  -d "{'head':'${UUID}','base':'master'}"

日志显示如下。 它无法创建带有错误

的拉取请求

"message": "Must authenticate to access this API."

但是,身份验证似乎没有问题。

// omit some useless log here
remote:
To github.microstrategy.com:Modules/mstr-web-hierarchy.git
 * [new branch]      23CFA0E3-33D1-489E-9E55-D38F92BB1B99 -> 23CFA0E3-33D1-489E-9E55-D38F92BB1B99
{
  "login": "shizhang",
  "id": 1191,
  // some useless properties here
{
  "message": "Must authenticate to access this API.",
  "documentation_url": "https://docs.github.com/enterprise/3.0/rest"
}

您的第二个 curl 似乎没有包含任何 authentication information

尝试添加与第一个 curl 相同的 -u [MY_USER_NAME]:[MY_TOKEN]

换句话说,第一个 curl 成功并不意味着其他 curl 将从经过身份验证的会话中受益。


Problems parsing JSON

尝试使用更简单的 JSON,仅用于测试。
并注意引号:'${UUID}' 不会被扩展,并且会完全保持 '${UUID}'.
参见“How to include environment variable in bash line CURL?