Skip to content

Commit

Permalink
Merge pull request #279 from dflook/ghes-graphql
Browse files Browse the repository at this point in the history
Prefer GITHUB_GRAPHQL_URL environment variable
  • Loading branch information
dflook authored Jul 15, 2023
2 parents 538b790 + 3d8d295 commit 3748155
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions image/src/github_actions/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ActionsEnv(TypedDict):
class GithubEnv(TypedDict):
"""Environment variables that are set by the actions runner."""
GITHUB_API_URL: str
GITHUB_GRAPHQL_URL: str
GITHUB_TOKEN: str
GITHUB_EVENT_PATH: str
GITHUB_EVENT_NAME: str
Expand Down
8 changes: 5 additions & 3 deletions image/src/github_pr_comment/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ def current_user(actions_env: GithubEnv) -> str:
cache_key = f'token-cache/{token_hash}'

def graphql() -> Optional[str]:
response = github.post(f'{actions_env["GITHUB_API_URL"]}/graphql', json={
graphql_url = actions_env.get('GITHUB_GRAPHQL_URL', f'{actions_env["GITHUB_API_URL"]}/graphql')

response = github.post(graphql_url, json={
'query': "query { viewer { login } }"
})
debug(f'graphql response: {response.content}')

if response.ok:
try:
debug(f'graphql response: {response.content}')
return response.json()['data']['viewer']['login']
except Exception as e:
pass
Expand All @@ -227,10 +229,10 @@ def graphql() -> Optional[str]:

def rest() -> Optional[str]:
response = github.get(f'{actions_env["GITHUB_API_URL"]}/user')
debug(f'rest response: {response.content}')

if response.ok:
user = response.json()
debug(f'rest response: {json.dumps(user)}')

return user['login']

Expand Down

0 comments on commit 3748155

Please sign in to comment.