Python GitHub“状态检查” POST未找到错误! (404)

时间:2020-06-05 10:18:50

标签: 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网络挂钩本身的信息(即

)来构建网址。
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 -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。

1 个答案:

答案 0 :(得分:1)

请注意,在该示例中,URL没有v3前缀,以下模板将为您工作:

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

更新的答案

https://github.com/api/v3/repos/ //状态/ ..效果很好。

问题是GitHub令牌的权限设置; Github确实需要修复其异常处理; 404不是!