Skip to content

Updating GitHub Repository Branch Protection Rules #162

Closed
@kmbhanushali

Description

@kmbhanushali

Hello!

I have been trying to integrate GitHub repo settings via Python and everything was going smoothly using the GitHub package. Unfortunately, the package does not contain any functions on creating new repo branch protection rules, so I had to switch to the gql package. I'm having a difficult time understanding the lingo surrounding this package so I was hoping to get some help here.

I have been doing independent research, but I can't seem to find anything of relevance on the subject. I emailed a member of this community and they suggested I create an issue here. Thank you for the assistance.

My code:

from gql import gql, Client, AIOHTTPTransport
import asyncio

async def main():

    transport = AIOHTTPTransport(url="myURL", headers={'Authorization': 'myToken'}) #using my url and token here

    # Using `async with` on the client will start a connection on the transport
    # and provide a `session` variable to execute queries on this connection
    async with Client(
        transport=transport,
        fetch_schema_from_transport=True,
        ) as session:

        # Execute single query
        query = gql("""
                mutation($input: CreateBranchProtectionRuleInput!) {
                    createBranchProtectionRule(input: $input) {
                        branchProtectionRule {
                          id
                        } 
                    }
                }
            """
            )

        input = {"repositoryId": "012345", "pattern": "release/*"} #using my repoID here
        result = await session.execute(query, variable_values = input)
        print(result)

asyncio.run(main())

This code results in the following error:

RuntimeError: asyncio.run() cannot be called from a running event loop

A couple things to note that may cause this error:

  • The url I am trying to reach (the repo I'm adding branch protection rules to) is a GitHub enterprise, version 2.19.21
  • I'm not sure if the AIOTTHP function is what causes the running event loop - is there a way to call a syncronous transport using a token?

Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions