driazati commented on code in PR #12695:
URL: https://github.com/apache/tvm/pull/12695#discussion_r965247817
##########
ci/scripts/git_utils.py:
##########
@@ -51,34 +54,62 @@ def post(url: str, body: Optional[Any] = None, auth:
Optional[Tuple[str, str]] =
return response.read()
+def dry_run_token(is_dry_run: bool) -> Any:
+ if is_dry_run:
+ return DRY_RUN
+ return os.environ["GITHUB_TOKEN"]
+
+
class GitHubRepo:
- def __init__(self, user, repo, token):
+ def __init__(self, user, repo, token, test_data=None):
self.token = token
self.user = user
self.repo = repo
+ self.test_data = test_data
+ self.num_calls = 0
self.base = f"https://api.github.com/repos/{user}/{repo}/"
def headers(self):
return {
"Authorization": f"Bearer {self.token}",
}
+ def dry_run(self) -> bool:
+ return self.token == DRY_RUN
+
def graphql(self, query: str, variables: Optional[Dict[str, str]] = None)
-> Dict[str, Any]:
query = compress_query(query)
if variables is None:
variables = {}
+
+ url = "https://api.github.com/graphql"
response = self._request(
- "https://api.github.com/graphql",
+ url,
{"query": query, "variables": variables},
method="POST",
)
+ if self.dry_run():
+ return self.testing_response("POST", url)
+
if "data" not in response:
msg = f"Error fetching data with
query:\n{query}\n\nvariables:\n{variables}\n\nerror:\n{json.dumps(response,
indent=2)}"
raise RuntimeError(msg)
return response
+ def testing_response(self, method: str, url: str) -> Any:
+ self.num_calls += 1
+ key = f"[{self.num_calls}] {method} - {url}"
+ if self.test_data is not None and key in self.test_data:
+ return self.test_data[key]
+ logging.info(f"Unknown URL in dry run: {key}")
Review Comment:
Not all the tests use this mechanism (and even in those that do it's a
little tedious to spell out every request / response), it'd be good to follow
up with a PR to just use mock responses for everything instead of special
args/casing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]