Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer GITHUB_GRAPHQL_URL environment variable #279

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading