Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati committed Aug 3, 2022
1 parent 1ed6a89 commit 0d35fbd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@
"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",
},
"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",
Expand Down Expand Up @@ -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
"""
Expand All @@ -156,7 +156,7 @@ def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, det
"login": user,
},
}
collaborators = []
collaborators = ["abc"]

proc = subprocess.run(
[
Expand All @@ -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),
],
Expand All @@ -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,
Expand Down
33 changes: 18 additions & 15 deletions tests/scripts/github_tvmbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = {
Expand Down

0 comments on commit 0d35fbd

Please sign in to comment.