Skip to content

Commit

Permalink
Merge pull request #25 from OpenRailAssociation/handle-collaborators
Browse files Browse the repository at this point in the history
Handle collaborator permissions
  • Loading branch information
mxmehl authored Jul 12, 2024
2 parents a80f8f2 + 285a22d commit 81c057c
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 33 deletions.
18 changes: 18 additions & 0 deletions gh_org_mgr/_gh_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import os
import sys

import requests


def get_github_token(token: str = "") -> str:
"""Get the GitHub token from config or environment, while environment overrides"""
Expand All @@ -25,3 +27,19 @@ def get_github_token(token: str = "") -> str:
)

return token


# Function to execute GraphQL query
def run_graphql_query(query, variables, token):
"""Run a query against the GitHub GraphQL API"""
headers = {"Authorization": f"Bearer {token}"}
request = requests.post(
"https://api.github.com/graphql",
json={"query": query, "variables": variables},
headers=headers,
timeout=10,
)
if request.status_code == 200:
return request.json()

sys.exit(f"Query failed to run by returning code of {query}: {request.status_code}")
Loading

0 comments on commit 81c057c

Please sign in to comment.