【发布时间】:2020-10-06 15:10:36
【问题描述】:
我一直在尝试通过 Python 集成 GitHub 存储库设置,并且使用 GitHub 包一切顺利。不幸的是,该包不包含任何创建新的 repo 分支保护规则的功能,所以我不得不切换到 gql 包。我很难理解这个包裹周围的术语,经过数周的在线搜索,我没有找到任何关于这个主题的内容。
目标是选择到我的存储库的传输、创建客户端、设置查询并运行客户端。我相信前两个设置正确,这是我认为我可能搞砸的查询。我一直在使用这两个链接来指导我:https://github.community/t/rest-api-v3-wildcard-branch-protection/13593/8 和 https://docs.github.com/en/free-pro-team@latest/graphql/reference/input-objects#createbranchprotectionruleinput
# Code:
# Select your transport with a defined url endpoint
transport = AIOHTTPTransport(url=myurl,
headers={'Authorization': 'mytoken'}) # I use my url and token
# Create a GraphQL client using the defined transport
client = Client(transport = transport, fetch_schema_from_transport = True)
方法:
# Provide a GraphQL query
def test(client):
query = gql("""
mutation($input: CreateBranchProtectionRuleInput!) {
createBranchProtectionRule(input: $variables) {
branchProtectionRule {
id
}
}
}
"""
)
variables = {"repositoryId": "123456", "pattern": "release/*"}
# Execute the query on the transport
data = asyncio.run(client.execute_async(query,variables))
print(data)
test(client)
这会导致以下错误:
data = asyncio.run(client.execute_async(query = query,variables = variables))
TypeError:execute_async() 缺少 1 个必需的位置参数:'document'
【问题讨论】: