示例#1
0
    def _process_event(self, unique_event_id, bz_event, mongo_issue, change_date, author_id):
        """
        Processes the event. During the event processing the Issue is set back to its original state
        before the event occured.

        :param unique_event_id: unique identifier of the event
        :param bz_event: event that was received from the bugzilla API
        :param mongo_issue: issue that is/should be stored in the mongodb
        :param change_date: date when the event was created
        :param author_id: :class:`bson.objectid.ObjectId` of the author of the event
        """
        is_new_event = True
        try:
            mongo_event = Event.objects(external_id=unique_event_id, issue_id=mongo_issue.id).get()
            is_new_event = False
        except DoesNotExist:
            mongo_event = Event(
                external_id=unique_event_id,
                issue_id=mongo_issue.id,
                created_at=change_date,
                author_id=author_id
            )

        # We need to map back the status from the bz terminology to ours. Special: The assigned_to must be mapped to
        # assigned_to_detail beforehand, as we are using this for the issue parsing
        if bz_event['field_name'] == 'assigned_to':
            bz_at_name = 'assigned_to_detail'
        else:
            bz_at_name = bz_event['field_name']

        try:
            mongo_event.status = self.at_mapping[bz_at_name]
        except KeyError:
            logger.warning('Mapping for attribute %s not found.' % bz_at_name)
            mongo_event.status = bz_at_name

        # Check if the mongo_issue has the attribute.
        # If yes: We can use the mongo_issue to set the old and new value of the event
        # If no: We use the added / removed fields
        if hasattr(mongo_issue, mongo_event.status):
            mongo_event.new_value = copy.deepcopy(getattr(mongo_issue, mongo_event.status))
            self._set_back_mongo_issue(mongo_issue, mongo_event.status, bz_event)
            mongo_event.old_value = copy.deepcopy(getattr(mongo_issue, mongo_event.status))
        else:
            mongo_event.new_value = bz_event['added']
            mongo_event.old_value = bz_event['removed']

        return mongo_event, is_new_event
示例#2
0
    def _process_event(self, unique_event_id, bz_event, mongo_issue,
                       change_date, author_id):
        """
        Processes the event. During the event processing the Issue is set back to its original state
        before the event occured.

        :param unique_event_id: unique identifier of the event
        :param bz_event: event that was received from the bugzilla API
        :param mongo_issue: issue that is/should be stored in the mongodb
        :param change_date: date when the event was created
        :param author_id: :class:`bson.objectid.ObjectId` of the author of the event
        """
        try:
            mongo_event = Event.objects(external_id=unique_event_id,
                                        issue_id=mongo_issue.id).get()
            return mongo_event, False
        except DoesNotExist:
            mongo_event = Event(external_id=unique_event_id,
                                issue_id=mongo_issue.id,
                                created_at=change_date,
                                author_id=author_id)

        # We need to map back the status from the bz terminology to ours. Special: The assigned_to must be mapped to
        # assigned_to_detail beforehand, as we are using this for the issue parsing
        if bz_event['field_name'] == 'assigned_to':
            bz_at_name = 'assigned_to_detail'
        else:
            bz_at_name = bz_event['field_name']

        try:
            mongo_event.status = self.at_mapping[bz_at_name]
        except KeyError:
            logger.warning('Mapping for attribute %s not found.' % bz_at_name)
            mongo_event.status = bz_at_name

        if mongo_event.status == 'assignee_id':
            if bz_event['added'] is not None and bz_event['added']:
                people_id = self._get_people(bz_event['added'])
                mongo_event.new_value = people_id

            if bz_event['removed'] is not None and bz_event['removed']:
                people_id = self._get_people(bz_event['removed'])
                mongo_event.old_value = people_id
        elif bz_event['field_name'] == 'depends_on':
            if bz_event['added'] is not None and bz_event['added']:
                issue_id = self._get_issue_id_by_system_id(bz_event['added'])
                mongo_event.new_value = {
                    'issue_id': issue_id,
                    'type': 'Dependent',
                    'effect': 'depends on'
                }

            if bz_event['removed'] is not None and bz_event['removed']:
                issue_id = self._get_issue_id_by_system_id(bz_event['removed'])
                mongo_event.old_value = {
                    'issue_id': issue_id,
                    'type': 'Dependent',
                    'effect': 'depends on'
                }
        elif bz_event['field_name'] == 'blocks':
            if bz_event['added'] is not None and bz_event['added']:
                issue_id = self._get_issue_id_by_system_id(bz_event['added'])
                mongo_event.new_value = {
                    'issue_id': issue_id,
                    'type': 'Blocker',
                    'effect': 'blocks'
                }

            if bz_event['removed'] is not None and bz_event['removed']:
                issue_id = self._get_issue_id_by_system_id(bz_event['removed'])
                mongo_event.old_value = {
                    'issue_id': issue_id,
                    'type': 'Blocker',
                    'effect': 'blocks'
                }
        else:
            if bz_event['added'] is not None and bz_event['added']:
                mongo_event.new_value = bz_event['added']

            if bz_event['removed'] is not None and bz_event['removed']:
                mongo_event.old_value = bz_event['removed']

        return mongo_event, True