You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ar...@apache.org on 2022/03/24 20:30:09 UTC
[tvm] branch main updated: [ci] Check existing reviews and requested reviews before cc-ing (#10734)
This is an automated email from the ASF dual-hosted git repository.
areusch 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 9705b14 [ci] Check existing reviews and requested reviews before cc-ing (#10734)
9705b14 is described below
commit 9705b146fa5e1bb44c7868eea7c7a9918210d2e3
Author: driazati <94...@users.noreply.github.com>
AuthorDate: Thu Mar 24 13:29:32 2022 -0700
[ci] Check existing reviews and requested reviews before cc-ing (#10734)
This will re-request reviews from existing reviewers as in #10714 which is not intended, so this lists out existing reviews/requests and filters the new reviews to add based on those usernames.
cc @areusch
Co-authored-by: driazati <dr...@users.noreply.github.com>
---
tests/python/ci/test_ci.py | 59 ++++++++++++++++++++++++++++++------
tests/scripts/github_cc_reviewers.py | 33 ++++++++++++++++++--
2 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/tests/python/ci/test_ci.py b/tests/python/ci/test_ci.py
index 4c7ad7c..aa64ee8 100644
--- a/tests/python/ci/test_ci.py
+++ b/tests/python/ci/test_ci.py
@@ -37,33 +37,74 @@ class TempGit:
def test_cc_reviewers(tmpdir_factory):
reviewers_script = REPO_ROOT / "tests" / "scripts" / "github_cc_reviewers.py"
- def run(pr_body, expected_reviewers):
+ def run(pr_body, requested_reviewers, existing_review_users, expected_reviewers):
git = TempGit(tmpdir_factory.mktemp("tmp_git_dir"))
git.run("init")
git.run("checkout", "-b", "main")
git.run("remote", "add", "origin", "https://github.com/apache/tvm.git")
+ reviews = [{"user": {"login": r}} for r in existing_review_users]
+ requested_reviewers = [{"login": r} for r in requested_reviewers]
proc = subprocess.run(
- [str(reviewers_script), "--dry-run"],
+ [str(reviewers_script), "--dry-run", "--testing-reviews-json", json.dumps(reviews)],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
- env={"PR": json.dumps({"number": 1, "body": pr_body})},
+ env={
+ "PR": json.dumps(
+ {"number": 1, "body": pr_body, "requested_reviewers": requested_reviewers}
+ )
+ },
encoding="utf-8",
cwd=git.cwd,
)
if proc.returncode != 0:
raise RuntimeError(f"Process failed:\nstdout:\n{proc.stdout}\n\nstderr:\n{proc.stderr}")
- assert proc.stdout.strip().endswith(f"Adding reviewers: {expected_reviewers}")
+ assert f"After filtering existing reviewers, adding: {expected_reviewers}" in proc.stdout
- run(pr_body="abc", expected_reviewers=[])
- run(pr_body="cc @abc", expected_reviewers=["abc"])
- run(pr_body="cc @", expected_reviewers=[])
- run(pr_body="cc @abc @def", expected_reviewers=["abc", "def"])
- run(pr_body="some text cc @abc @def something else", expected_reviewers=["abc", "def"])
+ run(pr_body="abc", requested_reviewers=[], existing_review_users=[], expected_reviewers=[])
+ run(
+ pr_body="cc @abc",
+ requested_reviewers=[],
+ existing_review_users=[],
+ expected_reviewers=["abc"],
+ )
+ run(pr_body="cc @", requested_reviewers=[], existing_review_users=[], expected_reviewers=[])
+ run(
+ pr_body="cc @abc @def",
+ requested_reviewers=[],
+ existing_review_users=[],
+ expected_reviewers=["abc", "def"],
+ )
+ run(
+ pr_body="some text cc @abc @def something else",
+ requested_reviewers=[],
+ existing_review_users=[],
+ expected_reviewers=["abc", "def"],
+ )
run(
pr_body="some text cc @abc @def something else\n\n another cc @zzz z",
+ requested_reviewers=[],
+ existing_review_users=[],
expected_reviewers=["abc", "def", "zzz"],
)
+ run(
+ pr_body="some text cc @abc @def something else\n\n another cc @zzz z",
+ requested_reviewers=["abc"],
+ existing_review_users=[],
+ expected_reviewers=["def", "zzz"],
+ )
+ run(
+ pr_body="some text cc @abc @def something else\n\n another cc @zzz z",
+ requested_reviewers=["abc"],
+ existing_review_users=["abc"],
+ expected_reviewers=["def", "zzz"],
+ )
+ run(
+ pr_body="some text cc @abc @def something else\n\n another cc @zzz z",
+ requested_reviewers=[],
+ existing_review_users=["abc"],
+ expected_reviewers=["def", "zzz"],
+ )
def test_update_branch(tmpdir_factory):
diff --git a/tests/scripts/github_cc_reviewers.py b/tests/scripts/github_cc_reviewers.py
index 8e7198a..bfc0077 100755
--- a/tests/scripts/github_cc_reviewers.py
+++ b/tests/scripts/github_cc_reviewers.py
@@ -48,6 +48,7 @@ if __name__ == "__main__":
help = "Add @cc'ed people in a PR body as reviewers"
parser = argparse.ArgumentParser(description=help)
parser.add_argument("--remote", default="origin", help="ssh remote to parse")
+ parser.add_argument("--testing-reviews-json", help="(testing only) reviews as JSON")
parser.add_argument(
"--dry-run",
action="store_true",
@@ -66,8 +67,36 @@ if __name__ == "__main__":
if body is None:
body = ""
- to_add = find_reviewers(body)
- print("Adding reviewers:", to_add)
+ new_reviewers = find_reviewers(body)
+ print("Found these reviewers:", new_reviewers)
+
+ if args.testing_reviews_json:
+ existing_reviews = json.loads(args.testing_reviews_json)
+ else:
+ github = GitHubRepo(token=os.environ["GITHUB_TOKEN"], user=user, repo=repo)
+ existing_reviews = github.get(f"pulls/{number}/reviews")
+
+ existing_review_users = [review["user"]["login"] for review in existing_reviews]
+ print("PR has reviews from these users:", existing_review_users)
+ existing_review_users = set(r.lower() for r in existing_review_users)
+
+ existing_reviewers = [review["login"] for review in pr["requested_reviewers"]]
+ print("PR already had these reviewers requested:", existing_reviewers)
+
+ existing_reviewers_lower = {
+ existing_reviewer.lower() for existing_reviewer in existing_reviewers
+ }
+ to_add = []
+ for new_reviewer in new_reviewers:
+ if (
+ new_reviewer.lower() in existing_reviewers_lower
+ or new_reviewer.lower() in existing_review_users
+ ):
+ print(f"{new_reviewer} is already review requested, skipping")
+ else:
+ to_add.append(new_reviewer)
+
+ print(f"After filtering existing reviewers, adding: {to_add}")
if not args.dry_run:
github = GitHubRepo(token=os.environ["GITHUB_TOKEN"], user=user, repo=repo)