Skip to content

Commit

Permalink
Record an Activity when assigning a reviewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobbins committed Aug 30, 2024
1 parent 2ea0e2f commit 74d78c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
16 changes: 15 additions & 1 deletion api/reviews_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from internals import approval_defs, notifier_helpers
from internals.core_enums import *
from internals.core_models import FeatureEntry, Stage
from internals.review_models import Gate, Vote
from internals.review_models import Gate, Vote, Amendment, Activity


def get_user_feature_and_gate(handler, kwargs) -> Tuple[
Expand Down Expand Up @@ -84,7 +84,21 @@ def do_post(self, **kwargs) -> dict[str, str]:
fe, stage, gate_id)

if new_state in (Vote.REVIEW_REQUESTED, Vote.NA_REQUESTED):
old_assignees = gate.assignee_emails[:]
approval_defs.auto_assign_reviewer(gate)
new_assignees = gate.assignee_emails[:]
if old_assignees != new_assignees:
amendment = Amendment(
field_name='review_assignee',
old_value=', '.join(old_assignees),
new_value=', '.join(new_assignees))
activity = Activity(
feature_id=fe.key.integer_id(), gate_id=gate_id,
author=user.email(), amendments=[amendment])
activity.put()
# Note: We don't notify assignee about autoassignment, because they
# will get a notification of review state change anyway.

notifier_helpers.notify_approvers_of_reviews(
fe, gate, new_state, user.email())
else:
Expand Down
7 changes: 7 additions & 0 deletions internals/notifier_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ def notify_assignees(
}

cloud_tasks_helpers.enqueue_task('/tasks/email-assigned', params)
amendment = Amendment(
field_name='review_assignee',
old_value=', '.join(old_assignees), new_value=', '.join(new_assignees))
gate_id = gate.key.integer_id()
activity = Activity(feature_id=fe.key.integer_id(), gate_id=gate_id,
author=triggering_user_email, amendments=[amendment])
activity.put()


def notify_subscribers_of_new_comments(fe: 'FeatureEntry', gate: Gate,
Expand Down
2 changes: 1 addition & 1 deletion internals/review_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Amendment(ndb.Model):
new_value = ndb.TextProperty()


class Activity(ndb.Model): # copy from Comment
class Activity(ndb.Model):
"""An activity log entry (comment + amendments) on a gate or feature."""
feature_id = ndb.IntegerProperty(required=True)
gate_id = ndb.IntegerProperty() # The gate commented on, or general comment.
Expand Down

0 comments on commit 74d78c4

Please sign in to comment.