Skip to content

Commit

Permalink
Changed define_stat_collection to load_pr_statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
gshefer committed Dec 30, 2017
1 parent 84a06a9 commit bd30006
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions nudgebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _process_flow(self, session_id, stat_collection, tree, cases_checksum=None):
cases_checksum = md5.new()
if isinstance(tree, dict):
for case, node in tree.items():
case.define_stat_collection(stat_collection)
case.load_pr_statistics(stat_collection)
if case.state:
cases_checksum.update(case.hash)
self._process_flow(session_id, stat_collection, node, cases_checksum)
Expand All @@ -63,7 +63,7 @@ def _process_flow(self, session_id, stat_collection, tree, cases_checksum=None):
self._process_flow(session_id, stat_collection, action, cases_checksum)
elif isinstance(tree, Action):
action = tree
action.define_stat_collection(stat_collection)
action.load_pr_statistics(stat_collection)
is_done = ([record for record in db().records.find({
'case_checksum': cases_checksum.hexdigest(),
'action.checksum': action.hash})
Expand Down
44 changes: 22 additions & 22 deletions nudgebot/lib/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(self, **kwargs):
def name(self):
return self.__class__.__name__

def define_stat_collection(self, stat_collection):
self._stat_collection = stat_collection
def load_pr_statistics(self, pr_statistics):
self._pr_statistics = pr_statistics

def run(self):
if config().config.testing_mode:
Expand All @@ -37,7 +37,7 @@ def action(self):

def _md5(self, *strings):
checksum = md5.new()
checksum.update(str(self._stat_collection.number))
checksum.update(str(self._pr_statistics.number))
for str_ in strings:
checksum.update(str(str_))
return checksum.hexdigest()
Expand All @@ -56,7 +56,7 @@ def __init__(self, *title_tags, **kwargs):
super(PullRequestTitleTagSet, self).__init__(**kwargs)

def action(self):
self._stat_collection.pull_request.title_tags = self._tags
self._pr_statistics.pull_request.title_tags = self._tags
return {'title_tags': [tag.raw for tag in self._tags]}

@property
Expand All @@ -71,7 +71,7 @@ def __init__(self, *title_tags, **kwargs):
super(PullRequestTitleTagRemove, self).__init__(**kwargs)

def action(self):
self._stat_collection.pull_request.remove_title_tags(*self._tags)
self._pr_statistics.pull_request.remove_title_tags(*self._tags)
return {'title_tags': [tag.raw for tag in self._tags]}

@property
Expand All @@ -86,7 +86,7 @@ def __init__(self, reviewer, **kwargs):
super(AddReviewer, self).__init__(**kwargs)

def action(self):
self._stat_collection.pull_request.add_reviewers([self._reviewer])
self._pr_statistics.pull_request.add_reviewers([self._reviewer])
return {'reviewer': self._reviewer.login}

@property
Expand All @@ -102,9 +102,9 @@ def __init__(self, level, **kwargs):
super(AddReviewerFromPool, self).__init__(**kwargs)

def action(self):
self._reviewer = self._stat_collection.repo.reviewers_pool.pull_reviewer(
self._level, self._stat_collection.pull_request)
self._stat_collection.pull_request.add_reviewers([self._reviewer])
self._reviewer = self._pr_statistics.repo.reviewers_pool.pull_reviewer(
self._level, self._pr_statistics.pull_request)
self._pr_statistics.pull_request.add_reviewers([self._reviewer])
return {'reviewer': self._reviewer.login}

@property
Expand All @@ -119,7 +119,7 @@ def __init__(self, reviewer, **kwargs):
super(RemoveReviewer, self).__init__(**kwargs)

def action(self):
self._stat_collection.pull_request.remove_reviewers([self._reviewer])
self._pr_statistics.pull_request.remove_reviewers([self._reviewer])
return {'reviewer': [reviewer.login for reviewer in self._reviewer]}

@property
Expand All @@ -134,7 +134,7 @@ def __init__(self, body, **kwargs):
super(CreateIssueComment, self).__init__(**kwargs)

def action(self):
comment = self._stat_collection.pull_request.create_issue_comment(self._body)
comment = self._pr_statistics.pull_request.create_issue_comment(self._body)
return {'body': self._body, 'created_at': comment.created_at}

@property
Expand All @@ -154,9 +154,9 @@ def event(self):
return getattr(self, 'EVENT', self.STATE)

def action(self):
self._stat_collection.pull_request.add_reviewers([self._github_obj])
review = self._stat_collection.pull_request.create_review(
list(self._stat_collection.commits)[-1], self._body or self.STATE, self.event)
self._pr_statistics.pull_request.add_reviewers([self._github_obj])
review = self._pr_statistics.pull_request.create_review(
list(self._pr_statistics.commits)[-1], self._body or self.STATE, self.event)
return {'review_id': review.id}

@property
Expand All @@ -183,8 +183,8 @@ def __init__(self, body, path=None, position=None, **kwargs):
super(CreateReviewComment, self).__init__(**kwargs)

def action(self):
commit = list(self._stat_collection.commits)[-1]
review_comment = self._stat_collection.pull_request.create_review_comment(
commit = list(self._pr_statistics.commits)[-1]
review_comment = self._pr_statistics.pull_request.create_review_comment(
self._body, commit, self._path, self._position)
return {
'review_comment': {
Expand All @@ -206,7 +206,7 @@ def __init__(self, description, **kwargs):
super(EditDescription, self).__init__(**kwargs)

def action(self):
self._stat_collection.pull_request.edit(body=self._description)
self._pr_statistics.pull_request.edit(body=self._description)
return {'description': self._description}

@property
Expand Down Expand Up @@ -247,11 +247,11 @@ def __init__(self, **kwargs):
super(ReportForInactivity, self).__init__(**kwargs)

def action(self):
last_update = self._stat_collection.last_update
last_update = self._pr_statistics.last_update
seconds_ago = int((datetime.now() - last_update).total_seconds())
days = seconds_ago / 86400
hours = (seconds_ago - days * 86400) / 3600
comment = self._stat_collection.pull_request.create_issue_comment(
comment = self._pr_statistics.pull_request.create_issue_comment(
('Pull request is inactive for {} days and {} hours- please do'
' some action - update it or close it').format(days, hours)
)
Expand All @@ -262,7 +262,7 @@ def action(self):

@property
def hash(self):
return self._md5(self._stat_collection.last_update)
return self._md5(self._pr_statistics.last_update)


class AskForReviewCommentReactions(Action):
Expand All @@ -274,7 +274,7 @@ def __init__(self, days, hours, **kwargs):

def action(self):
emails_content, receviers = 'The following action required for this PR:\n', []
for status in self._stat_collection.review_comment_reaction_statuses:
for status in self._pr_statistics.review_comment_reaction_statuses:
if status['age_seconds'] > (self._days * 86400 + self._hours * 3600):
days = int(status['age_seconds']) / 86400
hours = (int(status['age_seconds']) - days * 86400) / 3600
Expand All @@ -293,7 +293,7 @@ def action(self):
if not receviers:
return
receviers = list(set(receviers))
subject = 'PR#{} is waiting for response'.format(self._stat_collection.number)
subject = 'PR#{} is waiting for response'.format(self._pr_statistics.number)
from nudgebot import NudgeBot
NudgeBot().send_email(receviers, subject, emails_content)
return {
Expand Down
30 changes: 15 additions & 15 deletions nudgebot/lib/cases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __repr__(self):
def name(self):
return self.__class__.__name__

def define_stat_collection(self, stat_collection):
self._stat_collection = stat_collection
def load_pr_statistics(self, pr_statistics):
self._pr_statistics = pr_statistics

def check_state(self):
raise NotImplementedError()
Expand All @@ -32,7 +32,7 @@ def state(self):
def _md5(self, *args):
strings = [str(arg) for arg in args]
checksum = md5.new()
checksum.update(str(self._stat_collection.number))
checksum.update(str(self._pr_statistics.number))
checksum.update(self.__class__.__name__)
checksum.update(str(self._not_case))
for str_ in strings:
Expand All @@ -54,7 +54,7 @@ def __init__(self, tag, *args, **kwargs):

def check_state(self):
for tag in self._tag_options:
for exists_tag in self._stat_collection.title_tags:
for exists_tag in self._pr_statistics.title_tags:
if (tag.match(exists_tag.name) if isinstance(tag, re._pattern_type)
else tag.lower() == exists_tag.name.lower()):
return True
Expand All @@ -73,7 +73,7 @@ def __init__(self, level=1, *args, **kwargs):
super(ReviewerWasSet, self).__init__(*args, **kwargs)

def check_state(self):
return self._level <= len(self._stat_collection.reviewers)
return self._level <= len(self._pr_statistics.reviewers)

@property
def hash(self):
Expand All @@ -88,8 +88,8 @@ def __init__(self, level=1, *args, **kwargs):

def check_state(self):
approvals = 0
for reviewer, state in self._stat_collection.review_states_by_user.items():
if (reviewer in self._stat_collection.repo.reviewers_pool.reviewers and
for reviewer, state in self._pr_statistics.review_states_by_user.items():
if (reviewer in self._pr_statistics.repo.reviewers_pool.reviewers and
state == Approve.STATE):
approvals += 1
return approvals == self._level
Expand All @@ -107,12 +107,12 @@ def __init__(self, days, hours, *args, **kwargs):
super(InactivityForPeriod, self).__init__(*args, **kwargs)

def check_state(self):
timedelta = datetime.now() - self._stat_collection.last_update
timedelta = datetime.now() - self._pr_statistics.last_update
return timedelta.total_seconds() > (self._days * 86400 + self._hours * 3600)

@property
def hash(self):
return self._md5(self._stat_collection.last_update)
return self._md5(self._pr_statistics.last_update)


class WaitingForReviewCommentReaction(Case):
Expand All @@ -123,7 +123,7 @@ def __init__(self, days, hours, *args, **kwargs):
super(WaitingForReviewCommentReaction, self).__init__(*args, **kwargs)

def check_state(self):
for status in self._stat_collection.review_comment_reaction_statuses:
for status in self._pr_statistics.review_comment_reaction_statuses:
if status['age_seconds'] > (self._days * 86400 + self._hours * 3600):
return True
return False
Expand All @@ -133,7 +133,7 @@ def hash(self):
last_comments_hash = ''.join([
status['last_comment'].user.login +
status['last_comment'].created_at.strftime('%d-%m-%y-%H-%M-%S')
for status in self._stat_collection.review_comment_reaction_statuses
for status in self._pr_statistics.review_comment_reaction_statuses
])
return self._md5(last_comments_hash, self._days, self._hours)

Expand All @@ -146,14 +146,14 @@ def __init__(self, text, *args, **kwargs):

def check_state(self):
if isinstance(self._text, re._pattern_type):
return bool(self._text.search(self._stat_collection.description))
return self._text in self._stat_collection.description
return bool(self._text.search(self._pr_statistics.description))
return self._text in self._pr_statistics.description

@property
def hash(self):
return self._md5(
getattr(self._text, 'pattern', self._text),
self._stat_collection.description
self._pr_statistics.description
)


Expand All @@ -164,7 +164,7 @@ def __init__(self, name, *args, **kwargs):
super(CurrentRepoName, self).__init__(*args, **kwargs)

def check_state(self):
return self._stat_collection.repo.name == self._name
return self._pr_statistics.repo.name == self._name

@property
def hash(self):
Expand Down

0 comments on commit bd30006

Please sign in to comment.