Exemple #1
0
    def test_gets_by_target_and_ref(self):
        # commit
        self.clear_comments(CommitLineComment, TARGET_ID, FROM_SHA)
        c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                   OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                   20, 30, AUTHOR, CONTENT1)
        c2 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                   OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                   20, 30, AUTHOR, CONTENT1)
        c3 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                   OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                   20, 30, AUTHOR, CONTENT1)
        cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 3

        self.clear_comments(PullLineComment, TARGET_ID, FROM_SHA)
        # pull
        PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                            OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                            20, 30, AUTHOR, CONTENT1)
        PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                            OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                            20, 30, AUTHOR, CONTENT1)
        cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 2
Exemple #2
0
 def _toggle_whitespace(self, request, project, paths, ignore_space,
                        **kwargs):
     sha1 = kwargs.get('sha1')
     context_lines = kwargs.get('context_lines')
     ref = sha1
     if ref is None:
         ref = project.default_branch
     linecomments = CommitLineComment.gets_by_target_and_ref(project.id,
                                                             ref)
     kw = {
         'ref': sha1,
         'paths': paths,
         'ignore_space': ignore_space,
         'rename_detection': True,
         'linecomments': linecomments
     }
     if context_lines is not None:
         kw.update({'context_lines': context_lines})
     try:
         commit = project.repo.get_commit(sha1)
         # get_diff 默认与 parent diff
         diff = project.repo.get_diff(**kw)
         if not commit:
             raise TraversalError("not a valid commit ref")
     except IOError:
         raise TraversalError()
     return diff
Exemple #3
0
 def _toggle_whitespace(self, request, project, paths, ignore_space,
                        **kwargs):
     sha1 = kwargs.get('sha1')
     context_lines = kwargs.get('context_lines')
     ref = sha1
     if ref is None:
         ref = project.default_branch
     linecomments = CommitLineComment.gets_by_target_and_ref(
         project.id, ref)
     kw = {
         'ref': sha1,
         'paths': paths,
         'ignore_space': ignore_space,
         'rename_detection': True,
         'linecomments': linecomments
     }
     if context_lines is not None:
         kw.update({'context_lines': context_lines})
     try:
         commit = project.repo.get_commit(sha1)
         # get_diff 默认与 parent diff
         diff = project.repo.get_diff(**kw)
         if not commit:
             raise TraversalError("not a valid commit ref")
     except IOError:
         raise TraversalError()
     return diff
Exemple #4
0
    def test_delete_comment(self):
        # commit
        c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                   OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                   20, 30, AUTHOR, CONTENT1)
        cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 1
        c1.delete()
        cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 0

        # pull
        c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                 OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                 20, 30, AUTHOR, CONTENT1)
        cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 1
        c2.delete()
        cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 0
Exemple #5
0
    def test_delete_comment(self):
        # commit
        self.clear_comments(CommitLineComment, TARGET_ID, FROM_SHA)
        c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                   OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                   20, 30, AUTHOR, CONTENT1)
        cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 1
        c1.delete()
        cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 0

        # pull
        self.clear_comments(PullLineComment, TARGET_ID, FROM_SHA)
        c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                 OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                 20, 30, AUTHOR, CONTENT1)
        cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 1
        c2.delete()
        cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA)
        assert len(cs) == 0
Exemple #6
0
    def source(self, request, sha1, path=None):
        current_user = request.user
        # guibog 20120815 some inherited templates need current user as user
        user = request.user
        project = self.project
        if sha1.count('.') == 1:
            sha, diff_type = sha1.split('.')
            resp = request.response
            resp.set_header("Content-Type", "text/plain")
            if diff_type == 'patch':
                text = project.repo.get_patch_file(sha)
                return text.encode('utf-8')
            elif diff_type == 'diff':
                text = project.repo.get_diff_file(sha)
                return text.encode('utf-8')

        ref = sha1
        if ref is None:
            ref = project.default_branch
        branches = project.repo.branches
        tags = project.repo.tags
        ref_type = ('branch' if ref in branches else 'tag'
                    if ref in tags else 'tree')

        comments = Comment.gets_by_proj_and_ref(project.id, ref)
        linecomments = CommitLineComment.gets_by_target_and_ref(project.id,
                                                                ref)

        whitespace = request.get_form_var('w', '0')
        if whitespace.isdigit() and int(whitespace) == 1:
            ignore_space = True
        else:
            ignore_space = False
        try:
            commit = project.repo.get_commit(sha1)
            # get_diff 默认与 parent diff
            diff = project.repo.get_diff(ref=sha1,
                                         ignore_space=ignore_space,
                                         rename_detection=True,
                                         linecomments=linecomments,
                                         paths=[path] if path else None)
            if not commit:
                raise TraversalError("not a valid commit ref")
        except IOError:
            raise TraversalError()

        return st('commit.html', **locals())
Exemple #7
0
    def source(self, request, sha1, path=None):
        current_user = request.user
        # guibog 20120815 some inherited templates need current user as user
        user = request.user
        project = self.project
        if sha1.count('.') == 1:
            sha, diff_type = sha1.split('.')
            resp = request.response
            resp.set_header("Content-Type", "text/plain")
            if diff_type == 'patch':
                text = project.repo.get_patch_file(sha)
                return text.encode('utf-8')
            elif diff_type == 'diff':
                text = project.repo.get_diff_file(sha)
                return text.encode('utf-8')

        ref = sha1
        if ref is None:
            ref = project.default_branch
        branches = project.repo.branches
        tags = project.repo.tags
        ref_type = ('branch'
                    if ref in branches else 'tag' if ref in tags else 'tree')

        comments = Comment.gets_by_proj_and_ref(project.id, ref)
        linecomments = CommitLineComment.gets_by_target_and_ref(
            project.id, ref)

        whitespace = request.get_form_var('w', '0')
        if whitespace.isdigit() and int(whitespace) == 1:
            ignore_space = True
        else:
            ignore_space = False
        try:
            commit = project.repo.get_commit(sha1)
            # get_diff 默认与 parent diff
            diff = project.repo.get_diff(ref=sha1,
                                         ignore_space=ignore_space,
                                         rename_detection=True,
                                         linecomments=linecomments,
                                         paths=[path] if path else None)
            if not commit:
                raise TraversalError("not a valid commit ref")
        except IOError:
            raise TraversalError()

        return st('commit.html', **locals())