Beispiel #1
0
    def translate(cls, payload, headers=None):
        """Translate event.

        :param payload:
        :param headers:
        :return:
        """
        event_key = headers.get('HTTP_X_EVENT_KEY')
        scm_type = payload.get('repository', {}).get('scm')
        if event_key not in BitBucketEventTypes.values():
            cls.event_notification_client.send_message_to_notification_center(
                CODE_JOB_CI_INVALID_EVENT_TYPE,
                detail={'event_type': event_key})
            raise UnrecognizableEventType(
                'Unrecognizable event type',
                detail='Unrecognizable event type ({})'.format(event_key))
        if scm_type not in ScmTypes.values():
            cls.event_notification_client.send_message_to_notification_center(
                CODE_JOB_CI_INVALID_SCM_TYPE, detail={'scm_type': scm_type})
            raise UnsupportedSCMType(
                'Unsupported SCM type',
                detail='Unsupported SCM type ({})'.format(scm_type))
        if event_key in {
                BitBucketEventTypes.PULL_REQUEST_CREATED,
                BitBucketEventTypes.PULL_REQUEST_UPDATED
        }:
            return cls._translate_pull_request(payload)
        elif event_key == BitBucketEventTypes.PULL_REQUEST_FULFILLED:
            return cls._translate_pull_request_merge(payload)
        elif event_key == BitBucketEventTypes.PULL_REQUEST_COMMENT_CREATED:
            return cls._translate_pull_request_comment(payload)
        else:
            return cls._translate_push(payload)
Beispiel #2
0
    def translate(cls, payload, headers=None):
        """Translate event.

        :param payload:
        :param headers:
        :return:
        """
        event_key = headers.get('HTTP_X_GITLAB_EVENT')
        if event_key not in GitLabEventTypes.values():
            raise UnrecognizableEventType('Unrecognizable event type', detail='Unrecognizable event type ({})'.format(event_key))
        if event_key == GitLabEventTypes.MERGE_REQUEST:
            return cls._translate_pull_request(payload)
        elif event_key == GitLabEventTypes.NOTES:
            return cls._translate_pull_request_comment(payload)
        else:
            return cls._translate_push(payload)
Beispiel #3
0
    def translate(cls, payload, headers=None):
        """Translate event.

        :param payload:
        :param headers:
        :return:
        """
        event_key = headers.get('HTTP_X_GITHUB_EVENT')
        if event_key not in GitHubEventTypes.values():
            raise UnrecognizableEventType(
                'Unrecognizable event type',
                detail='Unrecognizable event type ({})'.format(event_key))
        if event_key == GitHubEventTypes.PING:
            return cls._translate_ping()
        elif event_key == GitHubEventTypes.CREATE:
            return cls._translate_create(payload)
        elif event_key == GitHubEventTypes.PULL_REQUEST:
            return cls._translate_pull_request(payload)
        elif event_key == GitHubEventTypes.ISSUE_COMMENT:
            return cls._translate_pull_request_comment(payload)
        else:
            return cls._translate_push(payload)