Example #1
0
    def __init__(self,
                 current_branch,
                 args,
                 commit_subject=None,
                 commit_description=None,
                 no_send_mail=False,
                 argv=None):
        """Constructor for ExportAction.

        Saves some environment data on the object such as the current branch and
        the metadata for the current branch.

        Args:
            current_branch: String; containing the name of a branch.
            args: An argparse.Namespace object to extract parameters from.
            commit_subject: The title for a commit message for the given review
                export. Defaults to None, in which case the git commit message
                of the most recent commit is used (or the user is allowed to
                pick one among the commits since last export).
            commit_description: The description for a commit message for the
                given review export. Defaults to None, in which case the git
                commit message of the most recent commit is used (or the user
                is allowed to pick one among the commits since last export).
            no_send_mail: Boolean representing whether or not --send_mail should
                be added to the upload.py call.
            argv: The original command line arguments that were parsed to create
                args. These may be used in a call to upload.py.
        """
        self.__branch = current_branch
        self.__current_head = utils.get_head_commit(
            current_branch=self.__branch)

        self.__rietveld_info = utils.RietveldInfo.from_branch(
            branch_name=self.__branch) or utils.RietveldInfo(self.__branch)
        self.__update_rietveld_info_from_args(args)

        # Add remote info if it isn't already there.
        if self.__rietveld_info.remote_info is None:
            remote_info = utils.get_remote_info(current_branch=self.__branch)
            self.__rietveld_info.remote_info = remote_info

        self.__rietveld_info.save()

        # TODO(dhermes): Should we check if the subject is Truth-y?
        if (commit_subject is None) ^ (commit_description is None):
            raise GitRvException('Subject and description must either both be '
                                 'specified or both be left out.')

        # Only need to check commit_subject since above also guarantees that
        # commit_description will also be non-null.
        self.__commit_message_overridden = commit_subject is not None
        commit_subject, commit_description = self.__get_commit_message_parts(
            commit_subject, commit_description)
        self.__commit_subject = commit_subject
        self.__commit_description = commit_description
        self.__argv = argv
        self.__no_send_mail = no_send_mail
        self.state = self.STARTING
        self.advance()
Example #2
0
    def __init__(self, current_branch, args, commit_subject=None,
                 commit_description=None, no_send_mail=False, argv=None):
        """Constructor for ExportAction.

        Saves some environment data on the object such as the current branch and
        the metadata for the current branch.

        Args:
            current_branch: String; containing the name of a branch.
            args: An argparse.Namespace object to extract parameters from.
            commit_subject: The title for a commit message for the given review
                export. Defaults to None, in which case the git commit message
                of the most recent commit is used (or the user is allowed to
                pick one among the commits since last export).
            commit_description: The description for a commit message for the
                given review export. Defaults to None, in which case the git
                commit message of the most recent commit is used (or the user
                is allowed to pick one among the commits since last export).
            no_send_mail: Boolean representing whether or not --send_mail should
                be added to the upload.py call.
            argv: The original command line arguments that were parsed to create
                args. These may be used in a call to upload.py.
        """
        self.__branch = current_branch
        self.__current_head = utils.get_head_commit(
                current_branch=self.__branch)

        self.__rietveld_info = utils.RietveldInfo.from_branch(
                branch_name=self.__branch) or utils.RietveldInfo(self.__branch)
        self.__update_rietveld_info_from_args(args)

        # Add remote info if it isn't already there.
        if self.__rietveld_info.remote_info is None:
            remote_info = utils.get_remote_info(current_branch=self.__branch)
            self.__rietveld_info.remote_info = remote_info

        self.__rietveld_info.save()

        # TODO(dhermes): Should we check if the subject is Truth-y?
        if (commit_subject is None) ^ (commit_description is None):
            raise GitRvException('Subject and description must either both be '
                                 'specified or both be left out.')

        # Only need to check commit_subject since above also guarantees that
        # commit_description will also be non-null.
        self.__commit_message_overridden = commit_subject is not None
        commit_subject, commit_description = self.__get_commit_message_parts(
            commit_subject, commit_description)
        self.__commit_subject = commit_subject
        self.__commit_description = commit_description
        self.__argv = argv
        self.__no_send_mail = no_send_mail
        self.state = self.STARTING
        self.advance()
Example #3
0
    def clean_up_review(self):
        """Cleans up the issue on the review server after successful commit.

        If possible to detect, adds message explaining where the reviewed
        changes were committed. If not explicitly asked to be left open by the
        user (via --leave_open), the issue will be closed as well.

        If successful, sets state to FINISHED and advances the state machine.
        """
        rpc_server, xsrf_token = self.__get_xsrf_server()
        # We know this will be the commit just pushed since clean_up_local has
        # just succeeded.
        commit_hash = utils.get_head_commit(current_branch=self.__branch)

        self.__add_commit_link(rpc_server, xsrf_token, commit_hash)
        if self.__do_close:
            self.__close_issue(rpc_server, xsrf_token)

        self.state = self.FINISHED
        self.advance()
Example #4
0
    def clean_up_review(self):
        """Cleans up the issue on the review server after successful commit.

        If possible to detect, adds message explaining where the reviewed
        changes were committed. If not explicitly asked to be left open by the
        user (via --leave_open), the issue will be closed as well.

        If successful, sets state to FINISHED and advances the state machine.
        """
        rpc_server, xsrf_token = self.__get_xsrf_server()
        # We know this will be the commit just pushed since clean_up_local has
        # just succeeded.
        commit_hash = utils.get_head_commit(current_branch=self.__branch)

        self.__add_commit_link(rpc_server, xsrf_token, commit_hash)
        if self.__do_close:
            self.__close_issue(rpc_server, xsrf_token)

        self.state = self.FINISHED
        self.advance()
Example #5
0
    def check_new_sync(self):
        """Checks that a sync can be performed in the new case.

        We know the rietveld_info is valid and the current branch is clean.

        If a sync can't be begun, sets state to FINISHED. If it can be,
        sets state to FETCH_REMOTE.
        """
        if self.__sync_halted:
            print ('A "git rv sync" was previously halted in branch %r. Please '
                   'execute the command:\n\tgit rv sync --continue\n'
                   'instead.' % (self.__branch,))
            self.state = self.FINISHED
        else:
            head_commit = utils.get_head_commit(current_branch=self.__branch)
            if head_commit != self.__last_commit:
                print UNEXPORTED_CHANGES_BLOCK_SYNC
                self.state = self.FINISHED
            else:
                self.state = self.FETCH_REMOTE
        self.advance()
Example #6
0
    def check_new_sync(self):
        """Checks that a sync can be performed in the new case.

        We know the rietveld_info is valid and the current branch is clean.

        If a sync can't be begun, sets state to FINISHED. If it can be,
        sets state to FETCH_REMOTE.
        """
        if self.__sync_halted:
            print(
                'A "git rv sync" was previously halted in branch %r. Please '
                'execute the command:\n\tgit rv sync --continue\n'
                'instead.' % (self.__branch, ))
            self.state = self.FINISHED
        else:
            head_commit = utils.get_head_commit(current_branch=self.__branch)
            if head_commit != self.__last_commit:
                print UNEXPORTED_CHANGES_BLOCK_SYNC
                self.state = self.FINISHED
            else:
                self.state = self.FETCH_REMOTE
        self.advance()