Beispiel #1
0
def task_log_gitlab_issue_open(issue_title, issue_content, trace_raw):
    """
    Proceed the issue opening task
    """
    gitlab = GitlabIssuesHelper.gitlab()

    print("Opening issue: %s..." % issue_title)

    # Create issue
    success, response = gitlab.createissue(
        settings.GITLAB_PROJECT_ID,
        issue_title,

        description=issue_content,
        assignee_id=getattr(settings, 'GITLAB_ASSIGNEE_ID', ''),
        labels='backend, error, bug',
    )

    if success:
        issue_id = response.get('id', None)

        if issue_id is not None:
            print("Issue opened: %s [ID: %s]" % (issue_title, issue_id))

            GitlabIssuesHelper.store_issue(trace_raw, settings.GITLAB_PROJECT_ID, response['id'])
    else:
        print("Issue could not be opened: %s" % issue_title)
Beispiel #2
0
def task_log_gitlab_issue_reopen(issue_id):
    """
    Proceed the issue re-opening task
    """
    print("Re-opening issue [ID: %s]" % issue_id)

    success, _ = GitlabIssuesHelper.gitlab().editissue(
        settings.GITLAB_PROJECT_ID,
        issue_id,

        state_event='reopen',
    )

    if success:
        print("Issue re-opened [ID: %s]" % issue_id)
    else:
        print("Issue could not be re-opened [ID: %s]" % issue_id)
Beispiel #3
0
    def emit(self, record):
        """
        Fired when an error is emitted
        """
        from django.conf import settings
        from django.views.debug import get_exception_reporter_filter
        from helpers import GitlabIssuesHelper

        try:
            has_repr, request_repr = True, '\n{0}'.format(
                get_exception_reporter_filter(record.request).get_request_repr(
                    record.request))
        except Exception:
            has_repr, request_repr = False, ':warning: Request data unavailable.'

        # Generate issue title
        title = '[{level}@{environment}] {message}'.format(
            level=record.levelname,
            message=record.getMessage(),
            environment=getattr(settings, 'ENVIRONMENT', 'default'),
        )

        # Generate issue content
        trace_raw = self.format(record)
        contents = {
            'head': '#### :zap: Note: this issue has been automatically opened.',
            'trace': '```python\n%s\n```' % trace_raw,
            'repr': '```\n%s\n```' % request_repr if has_repr\
                                                      else ('*%s*' % request_repr),
        }

        issue_exists, issue_id = GitlabIssuesHelper.check_issue(
            settings.GITLAB_PROJECT_ID, trace_raw)

        if not issue_exists:
            content = '{head}\n\n---\n\n{trace}\n\n---\n\n{repr}'.format(
                head=contents['head'],
                trace=contents['trace'],
                repr=contents['repr'],
            )

            self.__open_issue(title, content, trace_raw)
        elif issue_id:
            self.__reopen_issue(issue_id)