From 6258fef5dd97fac88771f59350d2d9ab2dd11b5e Mon Sep 17 00:00:00 2001 From: Enrico Minack Date: Mon, 15 Mar 2021 17:48:01 +0100 Subject: [PATCH] Use GITHUB_GRAPHQL_URL (#94) --- publish/publisher.py | 5 +++-- publish_unit_test_results.py | 2 ++ test/test_action_script.py | 8 +++++++- test/test_publisher.py | 5 +++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/publish/publisher.py b/publish/publisher.py index b3353579..f6fe1707 100644 --- a/publish/publisher.py +++ b/publish/publisher.py @@ -17,6 +17,7 @@ class Settings: token: str api_url: str + graphql_url: str event: dict event_name: str repo: str @@ -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 \ @@ -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', {}) \ diff --git a/publish_unit_test_results.py b/publish_unit_test_results.py index af7b1032..66756a95 100644 --- a/publish_unit_test_results.py +++ b/publish_unit_test_results.py @@ -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 @@ -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), diff --git a/test/test_action_script.py b/test/test_action_script.py index 713d0b15..25e0e3ec 100644 --- a/test/test_action_script.py +++ b/test/test_action_script.py @@ -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', @@ -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, @@ -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')) @@ -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', diff --git a/test/test_publisher.py b/test/test_publisher.py index b0c629b8..daf5d6bc 100644 --- a/test/test_publisher.py +++ b/test/test_publisher.py @@ -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', @@ -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") {' @@ -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 } ) {'