areusch commented on code in PR #12695:
URL: https://github.com/apache/tvm/pull/12695#discussion_r965248207


##########
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:
   ok sgtm



-- 
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: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to