From 0d35fbd227a14b2e9cbe7da58814e2a4857d310c Mon Sep 17 00:00:00 2001 From: driazati Date: Wed, 3 Aug 2022 14:29:37 -0700 Subject: [PATCH] Fix tests --- .../ci/{test_mergebot.py => test_tvmbot.py} | 11 ++++--- tests/scripts/github_tvmbot.py | 33 ++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) rename tests/python/ci/{test_mergebot.py => test_tvmbot.py} (95%) diff --git a/tests/python/ci/test_mergebot.py b/tests/python/ci/test_tvmbot.py similarity index 95% rename from tests/python/ci/test_mergebot.py rename to tests/python/ci/test_tvmbot.py index ccdfdc653901..0b55bdaa29ee 100644 --- a/tests/python/ci/test_mergebot.py +++ b/tests/python/ci/test_tvmbot.py @@ -81,7 +81,7 @@ "invalid-author": { "number": 10786, "filename": "pr10786-invalid-author.json", - "expected": "Comment is not from from PR author or collaborator, quitting", + "expected": "Failed auth check 'collaborators', quitting", "comment": "@tvm-bot merge", "user": "not-abc", "detail": "Merge requester is not a committer and cannot merge", @@ -89,7 +89,7 @@ "unauthorized-comment": { "number": 11244, "filename": "pr11244-unauthorized-comment.json", - "expected": "Comment is not from from PR author or collaborator, quitting", + "expected": "Failed auth check 'collaborators'", "comment": "@tvm-bot merge", "user": "not-abc2", "detail": "Check that a merge comment not from a CONTRIBUTOR is rejected", @@ -135,7 +135,7 @@ [tuple(d.values()) for d in TEST_DATA.values()], ids=TEST_DATA.keys(), ) -def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, detail): +def test_tvmbot(tmpdir_factory, number, filename, expected, comment, user, detail): """ Test the mergebot test cases """ @@ -156,7 +156,7 @@ def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, det "login": user, }, } - collaborators = [] + collaborators = ["abc"] proc = subprocess.run( [ @@ -170,6 +170,8 @@ def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, det json.dumps(test_data), "--testing-collaborators-json", json.dumps(collaborators), + "--testing-mentionable-users-json", + json.dumps(collaborators), "--trigger-comment-json", json.dumps(comment), ], @@ -178,6 +180,7 @@ def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, det encoding="utf-8", env={ "TVM_BOT_JENKINS_TOKEN": "123", + "GH_ACTIONS_TOKEN": "123", }, cwd=git.cwd, check=False, diff --git a/tests/scripts/github_tvmbot.py b/tests/scripts/github_tvmbot.py index 7229f23092e8..3f7db60d3384 100755 --- a/tests/scripts/github_tvmbot.py +++ b/tests/scripts/github_tvmbot.py @@ -534,15 +534,18 @@ def rerun_github_actions(self) -> None: user=self.github.user, repo=self.github.repo, token=GH_ACTIONS_TOKEN ) for job_id in job_ids: - try: - actions_github.post(f"actions/jobs/{job_id}/rerun", data={}) - except RuntimeError as e: - # Ignore errors about jobs that are part of the same workflow to avoid - # having to figure out which jobs are in which workflows ahead of time - if "The workflow run containing this job is already running" in str(e): - pass - else: - raise e + if self.dry_run: + try: + actions_github.post(f"actions/jobs/{job_id}/rerun", data={}) + except RuntimeError as e: + # Ignore errors about jobs that are part of the same workflow to avoid + # having to figure out which jobs are in which workflows ahead of time + if "The workflow run containing this job is already running" in str(e): + pass + else: + raise e + else: + logging.info(f"Dry run, not restarting {job_id}") def comment_failure(self, msg: str, exception: Exception): if not self.dry_run: @@ -567,26 +570,26 @@ def check_collaborator(pr, triggering_comment, args): logging.info("Checking collaborators") # Get the list of collaborators for the repo filtered by the comment # author + commment_author = triggering_comment["user"]["login"] if args.testing_collaborators_json: collaborators = json.loads(args.testing_collaborators_json) else: - collaborators = pr.search_collaborator(triggering_comment["user"]["login"]) + collaborators = pr.search_collaborator(commment_author) logging.info(f"Found collaborators: {collaborators}") - return len(collaborators) > 0 + return len(collaborators) > 0 and commment_author in collaborators def check_mentionable_users(pr, triggering_comment, args): logging.info("Checking mentionable users") - # Get the list of collaborators for the repo filtered by the comment - # author + commment_author = triggering_comment["user"]["login"] if args.testing_mentionable_users_json: mentionable_users = json.loads(args.testing_mentionable_users_json) else: - mentionable_users = pr.search_mentionable_users(triggering_comment["user"]["login"]) + mentionable_users = pr.search_mentionable_users(commment_author) logging.info(f"Found mentionable_users: {mentionable_users}") - return len(mentionable_users) > 0 + return len(mentionable_users) > 0 and commment_author in mentionable_users AUTH_CHECKS = {