This is an automated email from the ASF dual-hosted git repository.
driazati pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 54f8176b47 [CI] Docs bot now edits previous comments (#11909)
54f8176b47 is described below
commit 54f8176b4749d53f94edd0812c3f5a1e536fc6f6
Author: Florin Blanaru <[email protected]>
AuthorDate: Wed Jun 29 05:36:29 2022 +0100
[CI] Docs bot now edits previous comments (#11909)
This PR improves the docs bot to edit a previous comment instead of making
new comments.
Fixes #11837
---
tests/python/ci/test_ci.py | 2 +-
tests/scripts/git_utils.py | 3 +++
tests/scripts/github_docs_comment.py | 33 +++++++++++++++++++++++++++++----
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/tests/python/ci/test_ci.py b/tests/python/ci/test_ci.py
index d8bcad0151..27297e165f 100644
--- a/tests/python/ci/test_ci.py
+++ b/tests/python/ci/test_ci.py
@@ -41,7 +41,7 @@ def parameterize_named(*values):
"https://pr-docs.tlcpack.ai",
"SHA",
"issues/11594/comments",
- "Built docs for commit SHA can be found "
+ "<!---docs-bot-comment-->\n\nBuilt docs for commit SHA can be
found "
"[here](https://pr-docs.tlcpack.ai/PR-11594/3/docs/index.html).",
)
],
diff --git a/tests/scripts/git_utils.py b/tests/scripts/git_utils.py
index aeaca164c2..7df8c0b93c 100644
--- a/tests/scripts/git_utils.py
+++ b/tests/scripts/git_utils.py
@@ -97,6 +97,9 @@ class GitHubRepo:
def put(self, url: str, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request(self.base + url, data, method="PUT")
+ def patch(self, url: str, data: Dict[str, Any]) -> Dict[str, Any]:
+ return self._request(self.base + url, data, method="PATCH")
+
def post(self, url: str, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request(self.base + url, data, method="POST")
diff --git a/tests/scripts/github_docs_comment.py
b/tests/scripts/github_docs_comment.py
index 5da32746df..64377b632c 100755
--- a/tests/scripts/github_docs_comment.py
+++ b/tests/scripts/github_docs_comment.py
@@ -25,11 +25,22 @@ from urllib import error
from git_utils import git, GitHubRepo, parse_remote
from cmd_utils import init_log
+DOCS_BOT_MARKER = "<!---docs-bot-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
def build_docs_url(base_url_docs, pr_number, build_number):
return
f"{base_url_docs}/PR-{str(pr_number)}/{str(build_number)}/docs/index.html"
+def get_pr_comments(github, url):
+ try:
+ return github.get(url)
+ except error.HTTPError as e:
+ logging.exception(f"Failed to retrieve PR comments: {url}: {e}")
+ return []
+
+
def get_pr_and_build_numbers(target_url):
target_url = target_url[target_url.find("PR-") : len(target_url)]
split = target_url.split("/")
@@ -38,6 +49,16 @@ def get_pr_and_build_numbers(target_url):
return {"pr_number": pr_number, "build_number": build_number}
+def search_for_docs_comment(comments):
+ for comment in comments:
+ if (
+ comment["user"]["login"] == GITHUB_ACTIONS_BOT_LOGIN
+ and DOCS_BOT_MARKER in comment["body"]
+ ):
+ return comment
+ return None
+
+
if __name__ == "__main__":
help = "Add comment with link to docs"
parser = argparse.ArgumentParser(description=help)
@@ -65,7 +86,7 @@ if __name__ == "__main__":
)
url = f'issues/{pr_and_build["pr_number"]}/comments'
- body = f"Built docs for commit {commit_sha} can be found
[here]({docs_url})."
+ body = f"{DOCS_BOT_MARKER}Built docs for commit {commit_sha} can be found
[here]({docs_url})."
if not args.dry_run:
github = GitHubRepo(token=os.environ["GITHUB_TOKEN"], user=user,
repo=repo)
@@ -77,9 +98,13 @@ if __name__ == "__main__":
logging.info(f"Skipping this action for user {author}")
sys.exit(0)
- try:
+ pr_comments = get_pr_comments(github, url)
+ comment = search_for_docs_comment(pr_comments)
+
+ if comment is not None:
+ comment_url = comment["url"]
+ github.patch(comment_url, {"body": body})
+ else:
github.post(url, {"body": body})
- except error.HTTPError as e:
- logging.exception(f"Failed to add docs comment {docs_url}: {e}")
else:
logging.info(f"Dry run, would have posted {url} with data {body}.")