如何解决使用 PyGithub API 时出现错误“'Repository' 对象没有属性 'create_deployment'”
我正在尝试使用 PyGithub
(https://pygithub.readthedocs.io/en/latest/apis.html) 获取部署并在其他地方报告状态。我有以下脚本:
from github import Github
# Github Enterprise with custom hostname
g = Github(base_url="https://{hostname}/api/v3",login_or_token="sometoken")
# get the repository
repo = g.get_repo("PyGithub/PyGithub")
# HTTP POST to /repos/:owner/:repo/deployments
deployment = repo.create_deployment(ref = 'master',environment = 'DEV',description= 'Deploying to the environment')
# getting the status
status = deployment.get_status(deployment.id)
# HTTP POST to /repos/:owner/:repo/deployments/:deployment_id/statuses
deployment.create_status(state = status.state,description = 'deploying completed')
但它抱怨:
'Repository' 对象没有属性 'create_deployment'
当我在 (https://pygithub.readthedocs.io/en/latest/github_objects/Repository.html#github.Repository.Repository) 中看到函数时。
我错过了什么?
我基本上想使用这两个端点。我无法在 python 中找到任何其他 github API,但即使这样也很好。
解决方法
首先,确保您使用的是 PyGithub 的更新版本。
部署 API 仅在 release version 1.47 上添加。
- 发行说明:
- 公关 #1424:
添加一个新类 Deployment 来描述使用执行的部署 GitHub。将三个方法添加到 Repository 中以列出它们并创建它们。
如果您使用的是
其次,我认为您误解了 deployment.get_status
的参数。
文档有点不清楚,但它需要部署状态 ID,不是部署 ID。该方法向 /repos/{owner}/{repo}/deployments/{deployment_id}/statuses/{status_id} 端点发出请求以“查看部署的部署状态”,并且代码将传入的 id
附加到 {{1}网址:
https://github.com/PyGithub/PyGithub/blob/master/github/Deployment.py#L180
/statuses/
正确的 API 可能是 get_statuses
,用于列出特定部署的所有部署状态。然后获取这些 ID 之一并将其传递给 def get_status(self,id_):
"""
:calls: `GET /repos/:owner/deployments/:deployment_id/statuses/:status_id <https://developer.github.com/v3/repos/deployments/#get-a-deployment-status>`_
:param id_: int
:rtype: :class:`github.DeploymentStatus.DeploymentStatus`
"""
assert isinstance(id_,int),id_
headers,data = self._requester.requestJsonAndCheck(
"GET",self.url + "/statuses/" + str(id_),headers={"Accept": self._get_accept_header()},)
以获取特定的 DeploymentStatus 对象。 (不过,您也可以循环遍历 get_status
列表,每个列表都已经是一个 DeploymentStatus 对象)。如果您还没有任何部署状态,那么您可以使用 get_statuses
创建一个:
create_status
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。