コード例 #1
0
ファイル: createcomment.py プロジェクト: zhanghaibo/critic
    def process(self, db, user, chain_id, text):
        chain = CommentChain.fromId(db, chain_id, user)
        comment_id = createComment(db, user, chain_id, text)

        db.commit()

        return OperationResult(comment_id=comment_id, draft_status=chain.review.getDraftStatus(db, user))
コード例 #2
0
ファイル: createcomment.py プロジェクト: beauhoyt/critic
    def process(self, db, user, chain_id, text):
        checkComment(text)

        chain = CommentChain.fromId(db, chain_id, user)
        comment_id = createComment(db, user, chain_id, text)

        db.commit()

        return OperationResult(comment_id=comment_id,
                               draft_status=chain.review.getDraftStatus(
                                   db, user))
コード例 #3
0
    def process(self, db, user, chain_id, commit_id, sha1, offset, count):
        chain = CommentChain.fromId(db, chain_id, user)
        existing = chain.lines_by_sha1.get(sha1)

        if not existing:
            cursor = db.cursor()
            cursor.execute("""INSERT INTO commentchainlines (chain, uid, commit, sha1, first_line, last_line)
                              VALUES (%s, %s, %s, %s, %s, %s)""",
                           (chain.id, user.id, commit_id, sha1, offset, offset + count - 1))
        elif offset != existing[0] or count != existing[1]:
            raise OperationError, "the comment chain is already present at other lines in same file version"

        return self.setChainState(db, user, chain, "addressed", "open", new_last_commit=commit_id)
コード例 #4
0
    def process(self, db, user, chain_id, new_type):
        chain = CommentChain.fromId(db, chain_id, user)
        review = chain.review

        if chain.type == new_type:
            raise OperationError("the comment chain's type is already '%s'" %
                                 new_type)
        elif new_type == "note" and chain.state in ("closed", "addressed"):
            raise OperationError(
                "can't convert resolved or addressed issue to a note")

        cursor = db.cursor()

        if chain.state == "draft":
            # The chain is still a draft; just change its type directly.
            cursor.execute(
                """UPDATE commentchains
                                 SET type=%s
                               WHERE id=%s""", (new_type, chain.id))

        elif chain.type_is_draft:
            # The user is reverting a draft chain type change; just undo the
            # draft change.
            cursor.execute(
                """DELETE FROM commentchainchanges
                               WHERE chain=%s
                                 AND uid=%s
                                 AND to_type IS NOT NULL""",
                (chain.id, user.id))

        else:
            # Otherwise insert a new row into the commentchainchanges table.
            cursor.execute(
                """INSERT INTO commentchainchanges (uid, chain, from_type, to_type)
                              VALUES (%s, %s, %s, %s)""",
                (user.id, chain.id, chain.type, new_type))

        db.commit()

        return OperationResult(draft_status=review.getDraftStatus(db, user))
コード例 #5
0
    def process(self, db, user, chain_id, new_type):
        chain = CommentChain.fromId(db, chain_id, user)
        review = chain.review

        if chain.type == new_type:
            raise OperationError, "the comment chain's type is already '%s'" % new_type
        elif new_type == "note" and chain.state in ("closed", "addressed"):
            raise OperationError, "can't convert resolved or addressed issue to a note"

        cursor = db.cursor()

        if chain.state == "draft":
            # The chain is still a draft; just change its type directly.
            cursor.execute("""UPDATE commentchains
                                 SET type=%s
                               WHERE id=%s""",
                           (new_type, chain.id))

        elif chain.type_is_draft:
            # The user is reverting a draft chain type change; just undo the
            # draft change.
            cursor.execute("""DELETE FROM commentchainchanges
                               WHERE chain=%s
                                 AND uid=%s
                                 AND to_type IS NOT NULL""",
                           (chain.id, user.id))

        else:
            # Otherwise insert a new row into the commentchainchanges table.
            cursor.execute("""INSERT INTO commentchainchanges (review, uid, chain, from_type, to_type)
                              VALUES (%s, %s, %s, %s, %s)""",
                           (review.id, user.id, chain.id, chain.type, new_type))

        db.commit()

        return OperationResult(draft_status=review.getDraftStatus(db, user))
コード例 #6
0
 def process(self, db, user, chain_id):
     return self.setChainState(db, user, CommentChain.fromId(db, chain_id, user), "open", "closed")
コード例 #7
0
ファイル: manipulatecomment.py プロジェクト: ryfow/critic
    def process(self, db, user, chain_id, commit_id, sha1, offset, count):
        chain = CommentChain.fromId(db, chain_id, user)
        existing = chain.lines_by_sha1.get(sha1)

        if chain.state != "addressed":
            raise OperationFailure(code="invalidoperation",
                                   title="Invalid operation",
                                   message="The comment chain is not marked as addressed!")

        if not existing:
            assert commit_id == chain.addressed_by.getId(db)

            chain.review.branch.loadCommits(db)

            commits = chain.review.getCommitSet(db).without(chain.addressed_by.parents)

            propagation = propagate.Propagation(db)
            propagation.setExisting(chain.review, chain.id, chain.addressed_by, chain.file_id, offset, offset + count - 1, True)
            propagation.calculateAdditionalLines(commits, chain.review.branch.head)

            commentchainlines_values = []

            for file_sha1, (first_line, last_line) in propagation.new_lines.items():
                commentchainlines_values.append((chain.id, user.id, file_sha1, first_line, last_line))

            cursor = db.cursor()
            cursor.executemany("""INSERT INTO commentchainlines (chain, uid, sha1, first_line, last_line)
                                  VALUES (%s, %s, %s, %s, %s)""",
                               commentchainlines_values)

            if not propagation.active:
                old_addressed_by_id = chain.addressed_by.getId(db)
                new_addressed_by_id = propagation.addressed_by[0].child.getId(db)

                if chain.addressed_by_is_draft:
                    cursor.execute("""UPDATE commentchainchanges
                                         SET to_addressed_by=%s
                                       WHERE chain=%s
                                         AND uid=%s
                                         AND state='draft'
                                         AND to_addressed_by=%s""",
                                   (new_addressed_by_id, chain.id, user.id, old_addressed_by_id))
                else:
                    cursor.execute("""INSERT INTO commentchainchanges (review, uid, chain, from_addressed_by, to_addressed_by)
                                      VALUES (%s, %s, %s, %s, %s)""",
                                   (chain.review.id, user.id, chain.id, old_addressed_by_id, new_addressed_by_id))

                old_last_commit_id = chain.last_commit.getId(db)
                new_last_commit_id = chain.addressed_by.getId(db)

                if chain.last_commit_is_draft:
                    cursor.execute("""UPDATE commentchainchanges
                                         SET to_last_commit=%s
                                       WHERE chain=%s
                                         AND uid=%s
                                         AND state='draft'
                                         AND to_last_commit=%s""",
                                   (new_last_commit_id, chain.id, user.id, old_last_commit_id))
                else:
                    cursor.execute("""INSERT INTO commentchainchanges (review, uid, chain, from_last_commit, to_last_commit)
                                      VALUES (%s, %s, %s, %s, %s)""",
                                   (chain.review.id, user.id, chain.id, old_last_commit_id, new_last_commit_id))

                db.commit()

                return OperationResult(old_state='addressed', new_state='addressed',
                                       draft_status=chain.review.getDraftStatus(db, user))
        elif offset != existing[0] or count != existing[1]:
            raise OperationFailure(code="invalidoperation",
                                   title="Invalid operation",
                                   message="The comment chain is already present at other lines in same file version")

        return self.setChainState(db, user, chain, "addressed", "open", new_last_commit=commit_id)
コード例 #8
0
    def process(self, db, user, chain_id, commit_id, sha1, offset, count):
        chain = CommentChain.fromId(db, chain_id, user)
        existing = chain.lines_by_sha1.get(sha1)

        if chain.state != "addressed":
            raise OperationFailure(code="invalidoperation",
                                   title="Invalid operation",
                                   message="The comment chain is not marked as addressed!")

        if not existing:
            assert commit_id == chain.addressed_by.getId(db)

            chain.review.branch.loadCommits(db)

            commits = chain.review.getCommitSet(db).without(chain.addressed_by.parents)

            propagation = propagate.Propagation(db)
            propagation.setExisting(chain.review, chain.id, chain.addressed_by, chain.file_id, offset, offset + count - 1, True)
            propagation.calculateAdditionalLines(commits, chain.review.branch.head)

            commentchainlines_values = []

            for file_sha1, (first_line, last_line) in propagation.new_lines.items():
                commentchainlines_values.append((chain.id, user.id, file_sha1, first_line, last_line))

            cursor = db.cursor()
            cursor.executemany("""INSERT INTO commentchainlines (chain, uid, sha1, first_line, last_line)
                                  VALUES (%s, %s, %s, %s, %s)""",
                               commentchainlines_values)

            if not propagation.active:
                old_addressed_by_id = chain.addressed_by.getId(db)
                new_addressed_by_id = propagation.addressed_by[0].child.getId(db)

                if chain.addressed_by_is_draft:
                    cursor.execute("""UPDATE commentchainchanges
                                         SET to_addressed_by=%s
                                       WHERE chain=%s
                                         AND uid=%s
                                         AND state='draft'
                                         AND to_addressed_by=%s""",
                                   (new_addressed_by_id, chain.id, user.id, old_addressed_by_id))
                else:
                    cursor.execute("""INSERT INTO commentchainchanges (uid, chain, from_addressed_by, to_addressed_by)
                                      VALUES (%s, %s, %s, %s)""",
                                   (user.id, chain.id, old_addressed_by_id, new_addressed_by_id))

                old_last_commit_id = chain.last_commit.getId(db)
                new_last_commit_id = chain.addressed_by.getId(db)

                if chain.last_commit_is_draft:
                    cursor.execute("""UPDATE commentchainchanges
                                         SET to_last_commit=%s
                                       WHERE chain=%s
                                         AND uid=%s
                                         AND state='draft'
                                         AND to_last_commit=%s""",
                                   (new_last_commit_id, chain.id, user.id, old_last_commit_id))
                else:
                    cursor.execute("""INSERT INTO commentchainchanges (uid, chain, from_last_commit, to_last_commit)
                                      VALUES (%s, %s, %s, %s)""",
                                   (user.id, chain.id, old_last_commit_id, new_last_commit_id))

                db.commit()

                return OperationResult(old_state='addressed', new_state='addressed',
                                       draft_status=chain.review.getDraftStatus(db, user))
        elif offset != existing[0] or count != existing[1]:
            raise OperationFailure(code="invalidoperation",
                                   title="Invalid operation",
                                   message="The comment chain is already present at other lines in same file version")

        return self.setChainState(db, user, chain, "addressed", "open", new_last_commit=commit_id)
コード例 #9
0
 def process(self, db, user, chain_id):
     return self.setChainState(db, user, CommentChain.fromId(db, chain_id, user), "closed", "open")