Skip to content

Commit 0d35fbd

Browse files
committed
Fix tests
1 parent 1ed6a89 commit 0d35fbd

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@
8181
"invalid-author": {
8282
"number": 10786,
8383
"filename": "pr10786-invalid-author.json",
84-
"expected": "Comment is not from from PR author or collaborator, quitting",
84+
"expected": "Failed auth check 'collaborators', quitting",
8585
"comment": "@tvm-bot merge",
8686
"user": "not-abc",
8787
"detail": "Merge requester is not a committer and cannot merge",
8888
},
8989
"unauthorized-comment": {
9090
"number": 11244,
9191
"filename": "pr11244-unauthorized-comment.json",
92-
"expected": "Comment is not from from PR author or collaborator, quitting",
92+
"expected": "Failed auth check 'collaborators'",
9393
"comment": "@tvm-bot merge",
9494
"user": "not-abc2",
9595
"detail": "Check that a merge comment not from a CONTRIBUTOR is rejected",
@@ -135,7 +135,7 @@
135135
[tuple(d.values()) for d in TEST_DATA.values()],
136136
ids=TEST_DATA.keys(),
137137
)
138-
def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, detail):
138+
def test_tvmbot(tmpdir_factory, number, filename, expected, comment, user, detail):
139139
"""
140140
Test the mergebot test cases
141141
"""
@@ -156,7 +156,7 @@ def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, det
156156
"login": user,
157157
},
158158
}
159-
collaborators = []
159+
collaborators = ["abc"]
160160

161161
proc = subprocess.run(
162162
[
@@ -170,6 +170,8 @@ def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, det
170170
json.dumps(test_data),
171171
"--testing-collaborators-json",
172172
json.dumps(collaborators),
173+
"--testing-mentionable-users-json",
174+
json.dumps(collaborators),
173175
"--trigger-comment-json",
174176
json.dumps(comment),
175177
],
@@ -178,6 +180,7 @@ def test_mergebot(tmpdir_factory, number, filename, expected, comment, user, det
178180
encoding="utf-8",
179181
env={
180182
"TVM_BOT_JENKINS_TOKEN": "123",
183+
"GH_ACTIONS_TOKEN": "123",
181184
},
182185
cwd=git.cwd,
183186
check=False,

tests/scripts/github_tvmbot.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,18 @@ def rerun_github_actions(self) -> None:
534534
user=self.github.user, repo=self.github.repo, token=GH_ACTIONS_TOKEN
535535
)
536536
for job_id in job_ids:
537-
try:
538-
actions_github.post(f"actions/jobs/{job_id}/rerun", data={})
539-
except RuntimeError as e:
540-
# Ignore errors about jobs that are part of the same workflow to avoid
541-
# having to figure out which jobs are in which workflows ahead of time
542-
if "The workflow run containing this job is already running" in str(e):
543-
pass
544-
else:
545-
raise e
537+
if self.dry_run:
538+
try:
539+
actions_github.post(f"actions/jobs/{job_id}/rerun", data={})
540+
except RuntimeError as e:
541+
# Ignore errors about jobs that are part of the same workflow to avoid
542+
# having to figure out which jobs are in which workflows ahead of time
543+
if "The workflow run containing this job is already running" in str(e):
544+
pass
545+
else:
546+
raise e
547+
else:
548+
logging.info(f"Dry run, not restarting {job_id}")
546549

547550
def comment_failure(self, msg: str, exception: Exception):
548551
if not self.dry_run:
@@ -567,26 +570,26 @@ def check_collaborator(pr, triggering_comment, args):
567570
logging.info("Checking collaborators")
568571
# Get the list of collaborators for the repo filtered by the comment
569572
# author
573+
commment_author = triggering_comment["user"]["login"]
570574
if args.testing_collaborators_json:
571575
collaborators = json.loads(args.testing_collaborators_json)
572576
else:
573-
collaborators = pr.search_collaborator(triggering_comment["user"]["login"])
577+
collaborators = pr.search_collaborator(commment_author)
574578
logging.info(f"Found collaborators: {collaborators}")
575579

576-
return len(collaborators) > 0
580+
return len(collaborators) > 0 and commment_author in collaborators
577581

578582

579583
def check_mentionable_users(pr, triggering_comment, args):
580584
logging.info("Checking mentionable users")
581-
# Get the list of collaborators for the repo filtered by the comment
582-
# author
585+
commment_author = triggering_comment["user"]["login"]
583586
if args.testing_mentionable_users_json:
584587
mentionable_users = json.loads(args.testing_mentionable_users_json)
585588
else:
586-
mentionable_users = pr.search_mentionable_users(triggering_comment["user"]["login"])
589+
mentionable_users = pr.search_mentionable_users(commment_author)
587590
logging.info(f"Found mentionable_users: {mentionable_users}")
588591

589-
return len(mentionable_users) > 0
592+
return len(mentionable_users) > 0 and commment_author in mentionable_users
590593

591594

592595
AUTH_CHECKS = {

0 commit comments

Comments
 (0)