def merge_proposal_modified(merge_proposal, event): """Notify branch subscribers when merge proposals are updated.""" # Check the user. if event.user is None: return if isinstance(event.user, UnauthenticatedPrincipal): from_person = None else: from_person = IPerson(event.user) # If the merge proposal was work in progress, then we don't want to send # out an email as the needs review email will cover that. old_status = event.object_before_modification.queue_status if old_status == BranchMergeProposalStatus.WORK_IN_PROGRESS: # Unless the new status is merged. If this occurs we really should # send out an email. if merge_proposal.queue_status != BranchMergeProposalStatus.MERGED: return # Create a delta of the changes. If there are no changes to report, then # we're done. delta = BranchMergeProposalNoPreviewDiffDelta.construct( event.object_before_modification, merge_proposal) if delta is None: return changes = text_delta( delta, delta.delta_values, delta.new_values, delta.interface) # Now create the job to send the email. getUtility(IMergeProposalUpdatedEmailJobSource).create( merge_proposal, changes, from_person)
def merge_proposal_modified(merge_proposal, event): """Notify branch subscribers when merge proposals are updated.""" # Check the user. if event.user is None: return if isinstance(event.user, UnauthenticatedPrincipal): from_person = None else: from_person = IPerson(event.user) # If the merge proposal was work in progress, then we don't want to send # out an email as the needs review email will cover that. old_status = event.object_before_modification.queue_status if old_status == BranchMergeProposalStatus.WORK_IN_PROGRESS: # Unless the new status is merged. If this occurs we really should # send out an email. if merge_proposal.queue_status != BranchMergeProposalStatus.MERGED: return # Create a delta of the changes. If there are no changes to report, then # we're done. delta = BranchMergeProposalNoPreviewDiffDelta.construct( event.object_before_modification, merge_proposal) if delta is None: return changes = text_delta(delta, delta.delta_values, delta.new_values, delta.interface) # Now create the job to send the email. getUtility(IMergeProposalUpdatedEmailJobSource).create( merge_proposal, changes, from_person)
def create(cls, branch, user, branch_delta): """See `IBranchModifiedMailJobSource`.""" metadata = { 'user': user.id, 'branch_delta': text_delta( branch_delta, branch_delta.delta_values, branch_delta.new_values, branch_delta.interface), } branch_job = BranchJob(branch, cls.class_job_type, metadata) job = cls(branch_job) job.celeryRunOnCommit() return job
def merge_proposal_modified(merge_proposal, event): """Notify branch subscribers when merge proposals are updated.""" # Check the user. if event.user is None: return if isinstance(event.user, UnauthenticatedPrincipal): from_person = None else: from_person = IPerson(event.user) old_status = event.object_before_modification.queue_status new_status = merge_proposal.queue_status in_progress_states = (BranchMergeProposalStatus.WORK_IN_PROGRESS, BranchMergeProposalStatus.NEEDS_REVIEW) # If the merge proposal was work in progress and is now needs review, # then we don't want to send out an email as the needs review email will # cover that. if (old_status != BranchMergeProposalStatus.WORK_IN_PROGRESS or new_status not in in_progress_states): # Create a delta of the changes. If there are no changes to report, # then we're done. delta = BranchMergeProposalNoPreviewDiffDelta.construct( event.object_before_modification, merge_proposal) if delta is not None: changes = text_delta(delta, delta.delta_values, delta.new_values, delta.interface) # Now create the job to send the email. getUtility(IMergeProposalUpdatedEmailJobSource).create( merge_proposal, changes, from_person) if getFeatureFlag(BRANCH_MERGE_PROPOSAL_WEBHOOKS_FEATURE_FLAG): payload = { "action": "modified", "old": _compose_merge_proposal_webhook_payload( event.object_before_modification), "new": _compose_merge_proposal_webhook_payload(merge_proposal), } # Some fields may not be in the before-modification snapshot; take # values for these from the new object instead. for field in payload["old"]: if not hasattr(event.object_before_modification, field): payload["old"][field] = payload["new"][field] _trigger_webhook(merge_proposal, payload)
def describe_repository_delta(repository_delta): output = text_delta( repository_delta, repository_delta.delta_values, repository_delta.new_values, repository_delta.interface).split("\n") if output and not output[-1]: # text_delta returned empty string output.pop() # Parts of the delta are only visible to people who can edit the # repository. output_for_editors = list(output) indent = " " * 4 for activity in repository_delta.activities: if activity.what_changed in activity_descriptions: description = activity_descriptions[activity.what_changed].format( old=activity.old_value, new=activity.new_value, changee=activity.changee_description, old_grants=describe_grants(activity.old_value), new_grants=describe_grants(activity.new_value)) output_for_editors.append(indent + description) return "\n".join(output), "\n".join(output_for_editors)
def textDelta(self): """Return a textual version of the class delta.""" return text_delta(self.delta, self.delta.delta_values, self.delta.new_values, self.delta.interface)