コード例 #1
0
ファイル: test_linecomment.py プロジェクト: jackfrued/code-1
    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
コード例 #2
0
ファイル: diff.py プロジェクト: 000fan000/code
 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
コード例 #3
0
ファイル: diff.py プロジェクト: jackfrued/code-1
 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
コード例 #4
0
ファイル: line_comments.py プロジェクト: jackfrued/code-1
 def _q_lookup(self, request, comment_id):
     comment = CommitLineComment.get(comment_id)
     if not comment:
         raise TraversalError("Unable to find comment %s" % comment_id)
     else:
         self.linecomment = comment
         return self
コード例 #5
0
ファイル: line_comments.py プロジェクト: 000fan000/code
 def _q_lookup(self, request, comment_id):
     comment = CommitLineComment.get(comment_id)
     if not comment:
         raise TraversalError(
             "Unable to find comment %s" % comment_id)
     else:
         self.linecomment = comment
         return self
コード例 #6
0
ファイル: test_linecomment.py プロジェクト: jackfrued/code-1
    def test_update_comment(self):
        # commit
        c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                   OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                   20, 30, AUTHOR, CONTENT1)
        assert c1.content == CONTENT1
        c1.update(CONTENT2)
        c1 = CommitLineComment.get(c1.id)
        assert c1.content == CONTENT2

        # pull
        c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                 OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                 20, 30, AUTHOR, CONTENT2)
        assert c2.content == CONTENT2
        c2.update(CONTENT_ZH)
        c2 = CommitLineComment.get(c2.id)
        assert c2.content == CONTENT_ZH
コード例 #7
0
ファイル: test_linecomment.py プロジェクト: leeccong/code
    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
コード例 #8
0
ファイル: test_linecomment.py プロジェクト: jackfrued/code-1
    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
コード例 #9
0
ファイル: line_comments.py プロジェクト: jackfrued/code-1
    def create(self, request):
        user = request.user
        if not user:
            return dict(r=1)
        project = CodeDoubanProject.get_by_name(self.proj_name)
        project_id = project.id
        from_sha = request.get_form_var('from_sha')
        assert from_sha, "comment from_sha cannot be empty"
        old_path = request.get_form_var('old_path')
        assert old_path, "comment old_path cannot be empty"
        new_path = request.get_form_var('new_path')
        assert new_path, "comment new path cannot be empty"
        # position = request.get_form_var('position')
        # assert position, "comment position cannot be empty"
        from_oid = request.get_form_var('from_oid')
        assert from_oid, "comment from_oid cannot be empty"
        to_oid = request.get_form_var('to_oid')
        assert to_oid, "comment to_oid cannot be empty"
        old = request.get_form_var('old_no')
        old = int(old) if old.isdigit() else LINECOMMENT_INDEX_EMPTY
        new = request.get_form_var('new_no')
        new = int(new) if new.isdigit() else LINECOMMENT_INDEX_EMPTY
        content = request.get_form_var('content', '')
        # FIXME: commit_author is None
        commit_author = request.get_form_var('commit_author')
        if not content.strip():
            return {'error': 'Content is empty!'}

        comment = CommitLineComment.add(project_id, from_sha, '', old_path,
                                        new_path, from_oid, to_oid, old, new,
                                        user.name, content)

        dispatch('comment',
                 data={
                     'comment': comment,
                     'commit_author': commit_author,
                     'is_line_comment': True,
                 })

        # TODO: 目前只是回写一个链接,可以多传点信息支持直接回写到pr linecomment
        # for commit linecomments rewrite to pr
        dispatch('comment_actions',
                 data={
                     'type': 'commit_linecomment',
                     'comment': comment,
                     'commit_author': commit_author,
                 })

        comment_uid = comment.uid
        return dict(r=0, html=st('/commit_linecomment.html', **locals()))
コード例 #10
0
ファイル: line_comments.py プロジェクト: 000fan000/code
    def create(self, request):
        user = request.user
        if not user:
            return dict(r=1)
        project = CodeDoubanProject.get_by_name(self.proj_name)
        project_id = project.id
        from_sha = request.get_form_var('from_sha')
        assert from_sha, "comment from_sha cannot be empty"
        old_path = request.get_form_var('old_path')
        assert old_path, "comment old_path cannot be empty"
        new_path = request.get_form_var('new_path')
        assert new_path, "comment new path cannot be empty"
        # position = request.get_form_var('position')
        # assert position, "comment position cannot be empty"
        from_oid = request.get_form_var('from_oid')
        assert from_oid, "comment from_oid cannot be empty"
        to_oid = request.get_form_var('to_oid')
        assert to_oid, "comment to_oid cannot be empty"
        old = request.get_form_var('old_no')
        old = int(old) if old.isdigit() else LINECOMMENT_INDEX_EMPTY
        new = request.get_form_var('new_no')
        new = int(new) if new.isdigit() else LINECOMMENT_INDEX_EMPTY
        content = request.get_form_var('content', '')
        # FIXME: commit_author is None
        commit_author = request.get_form_var('commit_author')
        if not content.strip():
            return {'error': 'Content is empty!'}

        comment = CommitLineComment.add(project_id, from_sha, '',
                                        old_path, new_path,
                                        from_oid, to_oid,
                                        old, new, user.name, content)

        dispatch('comment', data={
            'comment': comment,
            'commit_author': commit_author,
            'is_line_comment': True,
        })

        # TODO: 目前只是回写一个链接,可以多传点信息支持直接回写到pr linecomment
        # for commit linecomments rewrite to pr
        dispatch('comment_actions', data={
            'type': 'commit_linecomment',
            'comment': comment,
            'commit_author': commit_author,
        })

        comment_uid = comment.uid
        return dict(r=0, html=st('/commit_linecomment.html', **locals()))
コード例 #11
0
def migrate_commit_linecomments():
    print '## run migrate_commit_linecomments'
    rs = store.execute("select comment_id "
                       "from codedouban_linecomments")
    for r in rs:
        id, = r
        c = LineComment.get(id)
        print '>>>', c.comment_id, c.project_id, c.ref, c.content
        PATH = c.path if c.path else ''
        CommitLineComment.add_raw(c.project_id,
                                  c.ref,
                                  EMPTY_TO_SHA,
                                  PATH,
                                  PATH,
                                  EMPTY_OIDS,
                                  EMPTY_OIDS,
                                  LINECOMMENT_INDEX_INVALID,  # commit linecomment老数据并没有记录linenum
                                  LINECOMMENT_INDEX_INVALID,
                                  c.author,
                                  c.content,
                                  c.position,
                                  c.created,
                                  c.created)
    print "migrate_commit_linecomments: %s records" % len(rs)
コード例 #12
0
ファイル: commit.py プロジェクト: 000fan000/code
    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())
コード例 #13
0
ファイル: commit.py プロジェクト: jackfrued/code-1
    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())
コード例 #14
0
ファイル: test_linecomment.py プロジェクト: jackfrued/code-1
    def test_add_comment(self):
        # commit
        c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                   OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                   20, 30, AUTHOR, CONTENT1)
        assert c1.target_id == TARGET_ID
        assert c1.target_type == LINECOMMENT_TYPE_COMMIT
        assert c1.from_sha == FROM_SHA
        assert c1.to_sha == TO_SHA
        assert c1.old_path == OLD_PATH
        assert c1.new_path == NEW_PATH
        assert c1.from_oid == FROM_OID
        assert c1.to_oid == TO_OID
        assert c1.old_linenum == 20
        assert c1.new_linenum == 30
        assert c1.linenum == (20, 30)
        assert c1.author == AUTHOR
        assert c1.content == CONTENT1
        assert c1.position is None
        assert c1.paths

        # pull
        c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA,
                                 OLD_PATH, NEW_PATH, FROM_OID, TO_OID,
                                 20, 30, AUTHOR, CONTENT2)
        assert c2.target_id == TARGET_ID
        assert c2.target_type == LINECOMMENT_TYPE_PULL
        assert c2.from_sha == FROM_SHA
        assert c2.to_sha == TO_SHA
        assert c2.old_path == OLD_PATH
        assert c2.new_path == NEW_PATH
        assert c2.from_oid == FROM_OID
        assert c2.to_oid == TO_OID
        assert c2.old_linenum == 20
        assert c2.new_linenum == 30
        assert c2.linenum == (20, 30)
        assert c2.author == AUTHOR
        assert c2.content == CONTENT2
        assert c2.position is None
        assert c2.paths