Python / gql软件包-使用GraphQL更新GitHub Repository Branch Protection规则

问题描述

我一直在尝试通过Python集成GitHub存储库设置,并且使用GitHub软件包可以使一切顺利进行。不幸的是,该软件包不包含任何创建新的回购分支保护规则的功能,因此我不得不切换到gql软件包。我很难理解有关该软件包的术语,经过数周的在线搜索后,我对该主题一无所获。

目标是选择到我的仓库的运输工具,创建客户端,设置查询并运行客户端。我相信前两个设置正确,这是我认为我可能搞砸了的查询。我一直在使用这两个链接来指导我:https://github.community/t/rest-api-v3-wildcard-branch-protection/13593/8https://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)

这将导致以下错误

数据= asyncio.run(client.execute_async(查询=查询,变量=变量))

TypeError:execute_async()缺少1个必需的位置参数:“ document”

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)