Skip to content

Commit 860b5d4

Browse files
committed
More tests written and passing
1 parent c823afa commit 860b5d4

File tree

2 files changed

+240
-195
lines changed

2 files changed

+240
-195
lines changed

homu/pull_req_state.py

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ def process_event(self, event):
339339
applied as a result of this event.
340340
"""
341341

342+
# TODO: Don't hardcode botname!
343+
botname = 'bors'
344+
# TODO: Don't hardcode hooks!
345+
hooks = []
346+
342347
result = ProcessEventResult()
343348
if event.event_type == 'PullRequestCommit':
344349
result.changed = self.head_sha != event['commit']['oid']
@@ -354,14 +359,18 @@ def process_event(self, event):
354359
result.changed = result.changed or self.approved_by != ''
355360
self.approved_by = ''
356361

362+
elif event.event_type == 'BaseRefChangedEvent':
363+
# Base ref changed: no longer approved
364+
result.changed = self.approved_by != ''
365+
self.approved_by = ''
366+
367+
357368
elif event.event_type == 'IssueComment':
358369
comments = parse_issue_comment(
359370
username=event['author']['login'],
360371
body=event['body'],
361372
sha=self.head_sha,
362-
# TODO: Don't hardcode 'bors'
363-
botname='bors',
364-
# TODO: Hooks!
373+
botname=botname,
365374
hooks=[])
366375

367376
for comment in comments:
@@ -441,11 +450,13 @@ def process_issue_comment(self, event, command):
441450
# TODO: Don't hardcode botname
442451
botname = 'bors'
443452
username = event['author']['login']
453+
# TODO: Don't hardcode repo_cfg
454+
repo_cfg = {}
444455
_assert_reviewer_auth_verified = functools.partial(
445456
assert_authorized,
446457
username,
447458
self.repo_label,
448-
{}, # repo_cfg
459+
repo_cfg,
449460
self,
450461
AuthState.REVIEWER,
451462
botname,
@@ -454,7 +465,7 @@ def process_issue_comment(self, event, command):
454465
assert_authorized,
455466
username,
456467
self.repo_label,
457-
{}, # repo_cfg
468+
repo_cfg,
458469
self,
459470
AuthState.TRY,
460471
botname,
@@ -542,37 +553,38 @@ def process_issue_comment(self, event, command):
542553
.format(treeclosed)
543554
)
544555

545-
# elif command.action == 'unapprove':
546-
# # Allow the author of a pull request to unapprove their own PR.
547-
# # The author can already perform other actions that effectively
548-
# # unapprove the PR (change the target branch, push more
549-
# # commits, etc.) so allowing them to directly unapprove it is
550-
# # also allowed.
551-
# if state.author != username:
552-
# assert_authorized(username, repo_label, repo_cfg, state,
553-
# AuthState.REVIEWER, my_username)
554-
#
555-
# state.approved_by = ''
556-
# state.save()
557-
# if realtime:
558-
# state.change_labels(LabelEvent.REJECTED)
559-
#
560-
# elif command.action == 'prioritize':
561-
# assert_authorized(username, repo_label, repo_cfg, state,
562-
# AuthState.TRY, my_username)
563-
#
564-
# pvalue = command.priority
565-
#
566-
# if pvalue > global_cfg['max_priority']:
567-
# if realtime:
568-
# state.add_comment(
569-
# ':stop_sign: Priority higher than {} is ignored.'
570-
# .format(global_cfg['max_priority'])
571-
# )
572-
# #continue
573-
# state.priority = pvalue
574-
# state.save()
575-
#
556+
elif command.action == 'unapprove':
557+
# Allow the author of a pull request to unapprove their own PR.
558+
# The author can already perform other actions that effectively
559+
# unapprove the PR (change the target branch, push more
560+
# commits, etc.) so allowing them to directly unapprove it is
561+
# also allowed.
562+
if self.author != username:
563+
assert_authorized(username, self.repo_label, repo_cfg, self,
564+
AuthState.REVIEWER, botname)
565+
566+
self.approved_by = ''
567+
result.changed = True
568+
result.label_events.append(LabelEvent.REJECTED)
569+
570+
elif command.action == 'prioritize':
571+
assert_authorized(username, self.repo_label, repo_cfg, self,
572+
AuthState.TRY, botname)
573+
574+
pvalue = command.priority
575+
576+
# TODO: Don't hardcode max_priority
577+
# global_cfg['max_priority']
578+
max_priority = 9001
579+
if pvalue > max_priority:
580+
result.comments.append(
581+
':stop_sign: Priority higher than {} is ignored.'
582+
.format(max_priority)
583+
)
584+
return result
585+
result.changed = self.priority != pvalue
586+
self.priority = pvalue
587+
576588
# elif command.action == 'delegate':
577589
# assert_authorized(username, repo_label, repo_cfg, state,
578590
# AuthState.REVIEWER, my_username)
@@ -644,13 +656,12 @@ def process_issue_comment(self, event, command):
644656
# # to any meaningful labeling events.
645657
# state.change_labels(LabelEvent.TRY)
646658
#
647-
# elif command.action == 'rollup':
648-
# _assert_try_auth_verified()
649-
#
650-
# state.rollup = command.rollup_value
651-
#
652-
# state.save()
653-
#
659+
elif command.action == 'rollup':
660+
_assert_try_auth_verified()
661+
662+
result.changed = self.rollup != command.rollup_value
663+
self.rollup = command.rollup_value
664+
654665
# elif command.action == 'force' and realtime:
655666
# _assert_try_auth_verified()
656667
#

0 commit comments

Comments
 (0)