driazati commented on code in PR #11594: URL: https://github.com/apache/tvm/pull/11594#discussion_r894720868
########## tests/scripts/github_docs_comment.py: ########## @@ -0,0 +1,75 @@ +#!/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 os +import logging +import argparse +from urllib import error + +from git_utils import git, GitHubRepo, parse_remote +from cmd_utils import init_log + + +def build_docs_url(base_url_docs, pr_number, build_number): + return ( + base_url_docs + "/tvm/PR-" + str(pr_number) + "/" + str(build_number) + "/docs/index.html" + ) Review Comment: nit: f-string ```suggestion return f"{base_url_docs}/tvm/PR-{pr_number}/{build_number}/docs/index.html" ``` ########## tests/scripts/github_docs_comment.py: ########## @@ -0,0 +1,75 @@ +#!/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 os +import logging +import argparse +from urllib import error + +from git_utils import git, GitHubRepo, parse_remote +from cmd_utils import init_log + + +def build_docs_url(base_url_docs, pr_number, build_number): + return ( + base_url_docs + "/tvm/PR-" + str(pr_number) + "/" + str(build_number) + "/docs/index.html" + ) + + +def get_pr_and_build_numbers(target_url): + target_url = target_url[target_url.find("PR-") : len(target_url)] + split = target_url.split("/") + pr_number = split[0].strip("PR-") + build_number = split[1] + return {"pr_number": pr_number, "build_number": build_number} + + +if __name__ == "__main__": + help = "Add comment with link to docs" + parser = argparse.ArgumentParser(description=help) + parser.add_argument("--remote", default="origin", help="ssh remote to parse") + parser.add_argument("--base-url-docs", default="https://d3f1x5ne0bf47p.cloudfront.net") + parser.add_argument( + "--dry-run", + action="store_true", + default=False, + help="run but don't send any request to GitHub", + ) + args = parser.parse_args() + init_log() + + remote = git(["config", "--get", f"remote.{args.remote}.url"]) + user, repo = parse_remote(remote) + + target_url = os.environ["TARGET_URL"] + pr_and_build = get_pr_and_build_numbers(target_url) + + docs_url = build_docs_url( + args.base_url_docs, pr_and_build["pr_number"], pr_and_build["build_number"] + ) + + url = f'/issues/{pr_and_build["pr_number"]}/comments' + body = f"Built docs can be found [here]({docs_url})." Review Comment: is it easy to grab the SHA from GitHub as well? it's supposedly on the [status webhook](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-object-47), including it here might be nice in case a build is currently in flight and its not clear which version of the docs it is. ```suggestion body = f"Built docs for {commit_sha} can be found [here]({docs_url})." ``` If it's not just a one-liner env variable in the actions yaml we can skip this ########## tests/scripts/github_docs_comment.py: ########## @@ -0,0 +1,75 @@ +#!/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 os +import logging +import argparse +from urllib import error + +from git_utils import git, GitHubRepo, parse_remote +from cmd_utils import init_log + + +def build_docs_url(base_url_docs, pr_number, build_number): + return ( + base_url_docs + "/tvm/PR-" + str(pr_number) + "/" + str(build_number) + "/docs/index.html" + ) + + +def get_pr_and_build_numbers(target_url): + target_url = target_url[target_url.find("PR-") : len(target_url)] + split = target_url.split("/") + pr_number = split[0].strip("PR-") + build_number = split[1] + return {"pr_number": pr_number, "build_number": build_number} + + +if __name__ == "__main__": + help = "Add comment with link to docs" + parser = argparse.ArgumentParser(description=help) + parser.add_argument("--remote", default="origin", help="ssh remote to parse") + parser.add_argument("--base-url-docs", default="https://d3f1x5ne0bf47p.cloudfront.net") + parser.add_argument( + "--dry-run", + action="store_true", + default=False, + help="run but don't send any request to GitHub", + ) + args = parser.parse_args() + init_log() + + remote = git(["config", "--get", f"remote.{args.remote}.url"]) + user, repo = parse_remote(remote) + + target_url = os.environ["TARGET_URL"] + pr_and_build = get_pr_and_build_numbers(target_url) + + docs_url = build_docs_url( + args.base_url_docs, pr_and_build["pr_number"], pr_and_build["build_number"] + ) + Review Comment: sorry to tack on another thing after the fact but this may lead to a lot of bot comments on peoples PRs, we should roll it out slowly instead of affecting everyone all at once. What do you think about querying GitHub for the PR here so we can check the author and only comment for a certain list of users at first (maybe you, me, and @areusch) and after a day or two of seeing it work in prod then remove the gate? -- 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]
