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


##########
ci/scripts/github_commenter.py:
##########
@@ -0,0 +1,130 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import re
+import logging
+from typing import Dict, Tuple, Any, Optional, List, Union
+
+from git_utils import GitHubRepo
+
+BOT_COMMENT_START = "<!---bot-comment-->"
+WELCOME_TEXT = "Thanks for contributing to TVM! Please refer to the 
contributing guidelines https://tvm.apache.org/docs/contribute/ for useful 
information and tips. Please request code reviews from 
[Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers)
 by @-ing them in a comment."
+
+
+class BotCommentBuilder:
+    def __init__(self, github: GitHubRepo, data: Dict[str, Any]):
+        self.github = github
+        self.pr_number = data["number"]
+        self.comment_data = data["comments"]["nodes"]
+        self.author = data["author"]["login"]
+
+    def find_bot_comment(self) -> Optional[Dict[str, Any]]:
+        """
+        Return the existing bot comment or None if it does not exist
+        """
+        for comment in self.comment_data:
+            logging.info(f"Checking comment {comment}")
+            if (
+                comment["author"]["login"] == "github-actions"
+                and BOT_COMMENT_START in comment["body"]
+            ):
+                logging.info("Found existing comment")
+                return comment
+        logging.info("No existing comment found")
+        return None
+
+    def find_existing_body(self) -> Dict[str, str]:
+        """
+        Find existing dynamic bullet point items
+        """
+        existing_comment = self.find_bot_comment()
+        if existing_comment is None:
+            logging.info(f"No existing comment while searching for body items")
+            return {}
+
+        matches = re.findall(
+            
r"<!--bot-comment-([a-z][a-z-]+)-start-->([\S\s]*?)<!--bot-comment-([a-z-]+)-end-->",
+            existing_comment["body"],
+            flags=re.MULTILINE,
+        )
+        logging.info(f"Fetch body item matches: {matches}")
+
+        items = {}
+        for start, text, end in matches:
+            if start != end:
+                raise RuntimeError(
+                    f"Malformed comment found: {start} marker did not have 
matching end, found instead {end}"
+                )
+            items[start] = text.strip().lstrip("* ")

Review Comment:
   so that later on the existing items extracted here from github can be 
treated the same way as newly produced ones (pretty much the `* ` is stripped 
off here and added back there)



-- 
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