github-api - Python GitHub "Status Check"POST 未找到错误! (404)

标签 github-api pull-request

这个answer :“如何在 github 存储库中执行状态检查?” ..

引用以下文章:

https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks https://developer.github.com/v3/guides/building-a-ci-server/#working-with-statuses

因此,要更新状态检查,我需要创建一个(并同时更新状态);按照:https://developer.github.com/v3/repos/statuses/#create-a-status ...发出 POST 至:

/repos/:owner/:repo/statuses/:sha

但是,每当我尝试将负载发布到端点 URL 时,我都会收到 404 (response.status_code: 404)。 注意:我正在使用来自 GitHub web-hook 本身的信息构建 URL,即

content['repository']['owner']['login']
content['repository']['name']
content['pull_request']['head']['sha']

JSON有效负载:

payload = { "state": "pending", "description": "The build succeeded!", "context": "continuous-integration/audit-compliance"}

请求:

headers = {'Content-Type': 'application/json',
                       'Authorization': "token "+gittokn}
url = https://github.com/api/v3/repos/<OWNER>/<REPO>/statuses/<PR-HEAD-SHA>
response = requests.post(url, headers=headers, json=payload, verify=False)

回应:

{'message': 'Not Found', 'documentation_url': 'https://developer.github.com/enterprise/2.18/v3/repos/statuses/#create-a-status'}

使用 curl :

curl -Is --user USER:PASS https://github.com/api/v3/repos/<OWNER>/<REPO>/statuses/<PR-HEAD-SHA> | head -1
    HTTP/1.1 200 OK

curl -Is --user USER:PASS https://api.github.com/repos/<OWNER>/<REPO>/statuses/<PR-HEAD-SHA> | head -1
# no result

我哪里出错了?

可以根据要求提供额外信息; TIA。

最佳答案

请注意,在示例中,网址没有 v3 前缀,下面的模板适合您:

https://api.github.com/repos/ORGNAME/REPONAME/statuses/<SHA>

更新答案

https://github.com/api/v3/repos///状态/ ..工作正常。

GitHub token 的权限设置是问题所在; Github 确实需要修复他们的异常处理;第404章 不是!

关于github-api - Python GitHub "Status Check"POST 未找到错误! (404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62213068/

相关文章:

github 远程标签推送无需克隆 repo

windows - 在 Windows 上使用 R 将本地仓库推送到 github

security - 公开 GH_TOKEN 以与 electron-builder 一起用于发布/更新应用程序是否存在任何安全问题?

git - 在 Github 中将 pull 请求 merge 到与默认分支不同的分支

git - 如何为以前的或旧的提交创建分支和 pull 请求?

Github 无法从基础分支发出 Pull 请求

git - 将 Gitflow 与 pull 请求一起使用的正确方法

curl - 在 Github API 上按受让人或标签过滤 PullRequest

Github API 分页限制

git - 当 cherry pick 了 pull request 时我该怎么办?