Esempio n. 1
0
    def process(self, db, user, repository_id, commit_ids, branch, summary,
                reviewfilters, recipientfilters, applyfilters, applyparentfilters,
                description=None, frombranch=None, trackedbranch=None):
        if not branch.startswith("r/"):
            raise OperationFailure(code="invalidbranch",
                                   title="Invalid review branch name",
                                   message="'%s' is not a valid review branch name; it must have a \"r/\" prefix." % branch)

        repository = gitutils.Repository.fromId(db, repository_id)
        commits = [gitutils.Commit.fromId(db, repository, commit_id) for commit_id in commit_ids]
        commitset = CommitSet(commits)

        reviewfilters = parseReviewFilters(db, reviewfilters)
        recipientfilters = parseRecipientFilters(db, recipientfilters)

        review = createReview(db, user, repository, commits, branch, summary, description,
                              from_branch_name=frombranch,
                              reviewfilters=reviewfilters,
                              recipientfilters=recipientfilters,
                              applyfilters=applyfilters,
                              applyparentfilters=applyparentfilters)

        extensions_output = StringIO()
        kwargs = {}

        if configuration.extensions.ENABLED:
            if executeProcessCommits(db, user, review, commits, None, commitset.getHeads().pop(), extensions_output):
                kwargs["extensions_output"] = extensions_output.getvalue().lstrip()

        if trackedbranch:
            cursor = db.cursor()
            cursor.execute("""INSERT INTO trackedbranches (repository, local_name, remote, remote_name, forced, delay)
                                   VALUES (%s, %s, %s, %s, false, '1 hour')
                                RETURNING id""",
                           (repository_id, branch, trackedbranch["remote"], trackedbranch["name"]))

            trackedbranch_id = cursor.fetchone()[0]

            cursor.execute("""INSERT INTO trackedbranchusers (branch, uid)
                                   VALUES (%s, %s)""",
                           (trackedbranch_id, user.id))

            db.commit()

            pid = int(open(configuration.services.BRANCHTRACKER["pidfile_path"]).read().strip())
            os.kill(pid, signal.SIGHUP)

        return OperationResult(review_id=review.id, **kwargs)
Esempio n. 2
0
    def process(self, db, user, repository, branch, summary, commit_ids=None,
                commit_sha1s=None, applyfilters=True, applyparentfilters=True,
                reviewfilters=None, recipientfilters=None, description=None,
                frombranch=None, trackedbranch=None):
        if not branch.startswith("r/"):
            raise OperationFailure(code="invalidbranch",
                                   title="Invalid review branch name",
                                   message="'%s' is not a valid review branch name; it must have a \"r/\" prefix." % branch)

        if reviewfilters is None:
            reviewfilters = []
        if recipientfilters is None:
            recipientfilters = {}

        components = branch.split("/")
        for index in range(1, len(components)):
            try:
                repository.revparse("refs/heads/%s" % "/".join(components[:index]))
            except gitutils.GitReferenceError:
                continue

            message = ("Cannot create branch with name<pre>%s</pre>since there is already a branch named<pre>%s</pre>in the repository." %
                       (htmlutils.htmlify(branch), htmlutils.htmlify("/".join(components[:index]))))
            raise OperationFailure(code="invalidbranch",
                                   title="Invalid review branch name",
                                   message=message,
                                   is_html=True)

        if commit_sha1s is not None:
            commits = [gitutils.Commit.fromSHA1(db, repository, commit_sha1) for commit_sha1 in commit_sha1s]
        elif commit_ids is not None:
            commits = [gitutils.Commit.fromId(db, repository, commit_id) for commit_id in commit_ids]
        else:
            commits = []

        commitset = CommitSet(commits)

        reviewfilters = parseReviewFilters(db, reviewfilters)
        recipientfilters = parseRecipientFilters(db, recipientfilters)

        review = createReview(db, user, repository, commits, branch, summary, description,
                              from_branch_name=frombranch,
                              reviewfilters=reviewfilters,
                              recipientfilters=recipientfilters,
                              applyfilters=applyfilters,
                              applyparentfilters=applyparentfilters)

        extensions_output = StringIO()
        kwargs = {}

        if configuration.extensions.ENABLED:
            if extensions.role.processcommits.execute(db, user, review, commits, None, commitset.getHeads().pop(), extensions_output):
                kwargs["extensions_output"] = extensions_output.getvalue().lstrip()

        if trackedbranch:
            cursor = db.cursor()

            cursor.execute("""SELECT 1
                                FROM knownremotes
                               WHERE url=%s
                                 AND pushing""",
                           (trackedbranch["remote"],))

            if cursor.fetchone():
                delay = "1 week"
            else:
                delay = "1 hour"

            cursor.execute("""INSERT INTO trackedbranches (repository, local_name, remote, remote_name, forced, delay)
                                   VALUES (%s, %s, %s, %s, false, %s)
                                RETURNING id""",
                           (repository.id, branch, trackedbranch["remote"], trackedbranch["name"], delay))

            trackedbranch_id = cursor.fetchone()[0]

            cursor.execute("""INSERT INTO trackedbranchusers (branch, uid)
                                   VALUES (%s, %s)""",
                           (trackedbranch_id, user.id))

            db.commit()

            pid = int(open(configuration.services.BRANCHTRACKER["pidfile_path"]).read().strip())
            os.kill(pid, signal.SIGHUP)

        return OperationResult(review_id=review.id, **kwargs)
Esempio n. 3
0
    def process(self,
                db,
                user,
                repository,
                branch,
                summary,
                commit_ids=None,
                commit_sha1s=None,
                applyfilters=True,
                applyparentfilters=True,
                reviewfilters=None,
                recipientfilters=None,
                description=None,
                frombranch=None,
                trackedbranch=None):
        if not branch.startswith("r/"):
            raise OperationFailure(
                code="invalidbranch",
                title="Invalid review branch name",
                message=
                "'%s' is not a valid review branch name; it must have a \"r/\" prefix."
                % branch)

        if reviewfilters is None:
            reviewfilters = []
        if recipientfilters is None:
            recipientfilters = {}

        components = branch.split("/")
        for index in range(1, len(components)):
            try:
                repository.revparse("refs/heads/%s" %
                                    "/".join(components[:index]))
            except gitutils.GitReferenceError:
                continue

            message = (
                "Cannot create branch with name<pre>%s</pre>since there is already a branch named<pre>%s</pre>in the repository."
                % (htmlutils.htmlify(branch),
                   htmlutils.htmlify("/".join(components[:index]))))
            raise OperationFailure(code="invalidbranch",
                                   title="Invalid review branch name",
                                   message=message,
                                   is_html=True)

        if commit_sha1s is not None:
            commits = [
                gitutils.Commit.fromSHA1(db, repository, commit_sha1)
                for commit_sha1 in commit_sha1s
            ]
        elif commit_ids is not None:
            commits = [
                gitutils.Commit.fromId(db, repository, commit_id)
                for commit_id in commit_ids
            ]
        else:
            commits = []

        commitset = CommitSet(commits)

        reviewfilters = parseReviewFilters(db, reviewfilters)
        recipientfilters = parseRecipientFilters(db, recipientfilters)

        review = createReview(db,
                              user,
                              repository,
                              commits,
                              branch,
                              summary,
                              description,
                              from_branch_name=frombranch,
                              reviewfilters=reviewfilters,
                              recipientfilters=recipientfilters,
                              applyfilters=applyfilters,
                              applyparentfilters=applyparentfilters)

        extensions_output = StringIO()
        kwargs = {}

        if configuration.extensions.ENABLED:
            if extensions.role.processcommits.execute(
                    db, user, review, commits, None,
                    commitset.getHeads().pop(), extensions_output):
                kwargs["extensions_output"] = extensions_output.getvalue(
                ).lstrip()

        if trackedbranch:
            cursor = db.cursor()

            cursor.execute(
                """SELECT 1
                                FROM knownremotes
                               WHERE url=%s
                                 AND pushing""", (trackedbranch["remote"], ))

            if cursor.fetchone():
                delay = "1 week"
            else:
                delay = "1 hour"

            cursor.execute(
                """INSERT INTO trackedbranches (repository, local_name, remote, remote_name, forced, delay)
                                   VALUES (%s, %s, %s, %s, false, %s)
                                RETURNING id""",
                (repository.id, branch, trackedbranch["remote"],
                 trackedbranch["name"], delay))

            trackedbranch_id = cursor.fetchone()[0]
            kwargs["trackedbranch_id"] = trackedbranch_id

            cursor.execute(
                """INSERT INTO trackedbranchusers (branch, uid)
                                   VALUES (%s, %s)""",
                (trackedbranch_id, user.id))

            db.commit()

            pid = int(
                open(configuration.services.BRANCHTRACKER["pidfile_path"]).
                read().strip())
            os.kill(pid, signal.SIGHUP)

        return OperationResult(review_id=review.id, **kwargs)