示例#1
0
    def submit_issues(cls, github, github_repo, loglines, similar_issues):
        """Submit issues to github."""
        results = []
        for line in loglines:
            gist = cls.create_gist(github, line)
            message = cls.create_issue_data(line, log_url=gist.html_url if gist else None)
            similar_issue = similar_issues.get(line.key)
            issue_id = None
            if similar_issue:
                if similar_issue.raw_data['locked']:
                    submitter_result = cls.EXISTING_ISSUE_LOCKED.format(number=similar_issue.number)
                    log.warning(submitter_result)
                else:
                    similar_issue.create_comment(message)
                    issue_id = similar_issue.number
                    submitter_result = cls.COMMENTED_EXISTING_ISSUE.format(number=issue_id)
                    log.info(submitter_result)
                    ErrorViewer.remove(line)
            else:
                issue = github_repo.create_issue('{prefix}{title}'.format(prefix=cls.TITLE_PREFIX, title=line.issue_title), message)
                issue_id = issue.number
                submitter_result = cls.ISSUE_CREATED.format(number=issue_id)
                log.info(submitter_result)
                ErrorViewer.remove(line)
            results.append((submitter_result, issue_id))

        return results
def test_submit_issues(monkeypatch, github, github_repo, create_github_issue, p):
    # Given
    message = p['input']
    logline = LogLine.from_line('2016-08-25 20:12:03 ERROR SEARCHQUEUE-MANUAL-290853 :: [ProviderName] :: [d4ea5af] {message}'.format(message=message))
    ErrorViewer.add(logline)
    create_comment = Mock()
    similar_issues = dict()
    locked = p.get('locked', False)
    similar = p.get('similar')
    if similar:
        similar_issue = create_github_issue(similar[1], number=similar[0], locked=locked)
        monkeypatch.setattr(similar_issue, 'create_comment', create_comment)
        similar_issues[logline.key] = similar_issue
    monkeypatch.setattr(github_repo, 'create_issue', create_github_issue)
    expected = p['expected']

    # When
    actual = sut.submit_issues(github, github_repo, [logline], similar_issues)

    # Then
    assert [expected] == actual
    if expected[1] is not None:
        assert logline not in ErrorViewer.errors
        if similar:
            assert create_comment.called
            assert message in create_comment.call_args[0][0]
        else:
            assert not create_comment.called
    else:
        assert logline in ErrorViewer.errors
        assert not create_comment.called
示例#3
0
def test_submit_issues(monkeypatch, github, github_repo, create_github_issue, p):
    # Given
    message = p['input']
    logline = LogLine.from_line('2016-08-25 20:12:03 ERROR SEARCHQUEUE-MANUAL-290853 :: [ProviderName] :: [d4ea5af] {message}'.format(message=message))
    ErrorViewer.add(logline)
    create_comment = Mock()
    similar_issues = dict()
    locked = p.get('locked', False)
    similar = p.get('similar')
    if similar:
        similar_issue = create_github_issue(similar[1], number=similar[0], locked=locked)
        monkeypatch.setattr(similar_issue, 'create_comment', create_comment)
        similar_issues[logline.key] = similar_issue
    monkeypatch.setattr(github_repo, 'create_issue', create_github_issue)
    expected = p['expected']

    # When
    actual = sut.submit_issues(github, github_repo, [logline], similar_issues)

    # Then
    assert [expected] == actual
    if expected[1] is not None:
        assert logline not in ErrorViewer.errors
        if similar:
            assert create_comment.called
            assert message in create_comment.call_args[0][0]
        else:
            assert not create_comment.called
    else:
        assert logline in ErrorViewer.errors
        assert not create_comment.called
示例#4
0
    def clearerrors(self, level=logging.ERROR):
        """Clear the errors or warnings."""
        # @TODO: Replace this with DELETE /api/v2/log/{logLevel} or /api/v2/log/
        if int(level) == logging.WARNING:
            WarningViewer.clear()
        else:
            ErrorViewer.clear()

        return self.redirect('/errorlogs/viewlog/')
示例#5
0
    def clearerrors(self, level=logging.ERROR):
        """Clear the errors or warnings."""
        # @TODO: Replace this with DELETE /api/v2/log/{logLevel} or /api/v2/log/
        if int(level) == logging.WARNING:
            WarningViewer.clear()
        else:
            ErrorViewer.clear()

        return self.redirect('/errorlogs/viewlog/')
示例#6
0
    def submit_issues(github, github_repo, loglines, similar_issues):
        """Submit issues to github.

        :param github:
        :type github: Github
        :param github_repo:
        :type github_repo: github.Repository.Repository
        :param loglines:
        :type loglines: list of medusa.logger.LogLine
        :param similar_issues:
        :type similar_issues: dict(str, github.Issue.Issue)
        :return:
        :rtype: list of tuple(str, str)
        """
        results = []
        for logline in loglines:
            gist = IssueSubmitter.create_gist(github, logline)
            message = IssueSubmitter.create_issue_data(
                logline, log_url=gist.html_url if gist else None)
            similar_issue = similar_issues.get(logline.key)
            issue_id = None
            if similar_issue:
                if similar_issue.raw_data['locked']:
                    submitter_result = IssueSubmitter.EXISTING_ISSUE_LOCKED.format(
                        number=similar_issue.number)
                    log.warning(submitter_result)
                else:
                    similar_issue.create_comment(message)
                    issue_id = similar_issue.number
                    submitter_result = IssueSubmitter.COMMENTED_EXISTING_ISSUE.format(
                        number=issue_id)
                    log.info(submitter_result)
                    ErrorViewer.remove(logline)
            else:
                issue = github_repo.create_issue(
                    '{prefix}{title}'.format(
                        prefix=IssueSubmitter.TITLE_PREFIX,
                        title=logline.issue_title), message)
                issue_id = issue.number
                submitter_result = IssueSubmitter.ISSUE_CREATED.format(
                    number=issue_id)
                log.info(submitter_result)
                ErrorViewer.remove(logline)
            results.append((submitter_result, issue_id))

        return results