我可以通过 GitHub REST API 使用 Curl 在 GitHub 存储库上创建(推送)一个新文件,并将我的文件转换为 Base64 格式。这是我用于推的工作卷曲:
curl -X PUT -H "Authorization: token xxx" https://api.github.com/repos/{owner}/{repo}/contents/{path}/{fileName} -d "{\"message\":\"your commit message\",\"content\":\"file in BASE64\"}"
现在我想通过curl 创建一个到GitHub 存储库的拉取请求。我阅读了 GitHub Docs,但我找不到该主题的任何工作示例。谁能提供样品吗?
POST /repos/:owner/:repo/pulls
# Request Payload
PR_PAYLOAD='{
"title": "'"${PR_TITLE}"'",
"body": "'"${PR_BODY}"'",
"head": "'"${USERNAME}:${HEAD_BRANCH}"'",
"base": "'"${BASE_BRANCH}"'"
}'
# The actual request
curl -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d "${PR_PAYLOAD}" \
"https://api.github.com/repos/${USERNAME}/${REPO}/pulls"
文档中的完整示例:
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/pulls \
-d '{"title":"Amazing new feature","body":"Please pull these awesome changes in!","head":"octocat:new-feature","base":"master"}'