Skip to content

Commit

Permalink
Use GITHUB_GRAPHQL_URL (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi authored Mar 15, 2021
1 parent e66abec commit 6258fef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions publish/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class Settings:
token: str
api_url: str
graphql_url: str
event: dict
event_name: str
repo: str
Expand Down Expand Up @@ -281,7 +282,7 @@ def get_pull_request_comments(self, pull: PullRequest) -> List[Mapping[str, Any]
)

headers, data = self._req.requestJsonAndCheck(
"POST", f'{self._settings.api_url}/graphql', input=query
"POST", self._settings.graphql_url, input=query
)

return data \
Expand All @@ -300,7 +301,7 @@ def hide_comment(self, comment_node_id) -> bool:
r'}'
)
headers, data = self._req.requestJsonAndCheck(
"POST", f'{self._settings.api_url}/graphql', input=input
"POST", self._settings.graphql_url, input=input
)
return data \
.get('data', {}) \
Expand Down
2 changes: 2 additions & 0 deletions publish_unit_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def get_settings(options: dict) -> Settings:
with open(event, 'r') as f:
event = json.load(f)
api_url = options.get('GITHUB_API_URL') or github.MainClass.DEFAULT_BASE_URL
graphql_url = options.get('GITHUB_GRAPHQL_URL') or f'{github.MainClass.DEFAULT_BASE_URL}/graphql'
test_changes_limit = get_var('TEST_CHANGES_LIMIT', options)
test_changes_limit = int(test_changes_limit) if test_changes_limit and test_changes_limit.isdigit() else 10

Expand All @@ -139,6 +140,7 @@ def get_settings(options: dict) -> Settings:
settings = Settings(
token=get_var('GITHUB_TOKEN', options),
api_url=api_url,
graphql_url=graphql_url,
event=event,
event_name=event_name,
repo=get_var('GITHUB_REPOSITORY', options),
Expand Down
8 changes: 7 additions & 1 deletion test/test_action_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_event_sha(self):
@staticmethod
def get_settings(token='token',
api_url='http://github.api.url/',
graphql_url='http://github.graphql.url/',
event={},
event_name='event name',
repo='repo',
Expand All @@ -119,6 +120,7 @@ def get_settings(token='token',
return Settings(
token=token,
api_url=api_url,
graphql_url=graphql_url,
event=event.copy(),
event_name=event_name,
repo=repo,
Expand All @@ -139,12 +141,15 @@ def test_get_settings(self):
options = self.do_test_get_settings()
options = {f'INPUT_{key}': value
for key, value in options.items()
if key not in {'GITHUB_API_URL', 'GITHUB_SHA'}}
if key not in {'GITHUB_API_URL', 'GITHUB_GRAPHQL_URL', 'GITHUB_SHA'}}
self.do_test_get_settings(**options)

def test_get_settings_github_api_url_default(self):
self.do_test_get_settings(GITHUB_API_URL=None, expected=self.get_settings(api_url='https://api.github.com'))

def test_get_settings_github_graphql_url_default(self):
self.do_test_get_settings(GITHUB_GRAPHQL_URL=None, expected=self.get_settings(graphql_url='https://api.github.com/graphql'))

def test_get_settings_commit_default(self):
event = {'pull_request': {'head': {'sha': 'sha2'}}}
self.do_test_get_settings(INPUT_COMMIT='sha', GITHUB_EVENT_NAME='pull_request', event=event, GITHUB_SHA='default', expected=self.get_settings(commit='sha', event=event, event_name='pull_request'))
Expand Down Expand Up @@ -241,6 +246,7 @@ def do_test_get_settings(self, event: dict = {}, expected: Settings = get_settin
GITHUB_EVENT_PATH=filepath,
GITHUB_EVENT_NAME='event name',
GITHUB_API_URL='http://github.api.url/', #defaults to github
GITHUB_GRAPHQL_URL='http://github.graphql.url/', #defaults to github
TEST_CHANGES_LIMIT='10', # not an int
CHECK_NAME='check name', # defaults to 'Unit Test Results'
GITHUB_TOKEN='token',
Expand Down
5 changes: 3 additions & 2 deletions test/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def create_settings(comment_on_pr=False,
return Settings(
token=None,
api_url='https://the-github-api-url',
graphql_url='https://the-github-graphql-url',
event=event,
event_name=event_name,
repo='owner/repo',
Expand Down Expand Up @@ -892,7 +893,7 @@ def test_get_pull_request_comments(self):

self.assertEqual(['node'], response)
req.requestJsonAndCheck.assert_called_once_with(
'POST', 'https://the-github-api-url/graphql',
'POST', 'https://the-github-graphql-url',
input={
'query': 'query ListComments {'
' repository(owner:"login", name:"owner/repo") {'
Expand Down Expand Up @@ -1002,7 +1003,7 @@ def test_hide_comment(self):

self.assertEqual(True, response)
req.requestJsonAndCheck.assert_called_once_with(
'POST', 'https://the-github-api-url/graphql',
'POST', 'https://the-github-graphql-url',
input={
'query': 'mutation MinimizeComment {'
' minimizeComment(input: { subjectId: "node id", classifier: OUTDATED } ) {'
Expand Down

0 comments on commit 6258fef

Please sign in to comment.