示例#1
0
文件: gerrit.py 项目: enzbang/pycr
    def add_reviewer(cls, change_id, account_id, force=False):
        """
        Send a POST request to the Gerrit Code Review server to add one user or
        all members of one group as reviewer to the change.

        PARAMETERS
            change_id: any identification number for the change (UUID,
                Change-Id, or legacy numeric change ID)
            account_id: any identification string for an account (name,
                username, email)
            force: do not prompt the user for confirmation if gerrit needs a
                confirmation to add multiple reviewers at once (group).
                Defaults to False

        RETURNS
            The list of newly added reviewers on success, None otherwise

        RAISES
            PyCRError if the Gerrit server returns an error
        """

        cls.log.debug('Assign review to %s: %s' % (account_id, change_id))

        payload = {'reviewer': account_id}
        headers = {'content-type': 'application/json'}

        try:
            endpoint = Api.reviewers(change_id)
            _, response = RequestFactory.post(endpoint,
                                              data=json.dumps(payload),
                                              headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            raise PyCRError('unexpected error', why)

        if 'confirm' in response:
            assert 'error' in response, 'missing "error" field in response'

            cls.log.debug('Assigning review: confirmation requested')

            do_add_reviewers = True if force else confirm(response['error'])

            if not do_add_reviewers:
                info('reviewer not added, aborting...')
                return None

            try:
                payload['confirmed'] = True
                _, response = RequestFactory.post(endpoint,
                                                  data=json.dumps(payload),
                                                  headers=headers)

            except RequestError as why:
                raise PyCRError('unexpected error', why)

        assert 'reviewers' in response, '"reviewers" not in HTTP response'
        return [AccountInfo.parse(r) for r in response['reviewers']]
示例#2
0
文件: client.py 项目: 0xcharly/pycr
    def add_reviewer(cls, change_id, account_id, force=False):
        """Add a reviewer

        Sends a POST request to Gerrit to add one user or all members of one
        group as reviewer to the change.

        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :param account_id: any identification string for an account (name,
            username, email)
        :type account_id: str
        :param force: do not prompt the user for confirmation if gerrit needs a
            confirmation to add multiple reviewers at once (group).  Defaults
            to False
        :type force: bool
        :rtype: tuple(AccountInfo)
        :raise: PyCRError if the Gerrit server returns an error
        """

        cls.log.debug('Assign review to %s: %s', account_id, change_id)

        payload = {'reviewer': account_id}
        headers = {'content-type': 'application/json'}

        try:
            endpoint = changes.reviewers(change_id)
            _, response = RequestFactory.post(endpoint,
                                              data=json.dumps(payload),
                                              headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            raise UnexpectedError(why)

        if 'confirm' in response:
            assert 'error' in response, 'missing "error" field in response'

            cls.log.debug('Assigning review: confirmation requested')

            do_add_reviewers = True if force else confirm(response['error'])

            if not do_add_reviewers:
                info('reviewer not added, aborting...')
                return None

            try:
                payload['confirmed'] = True
                _, response = RequestFactory.post(endpoint,
                                                  data=json.dumps(payload),
                                                  headers=headers)

            except RequestError as why:
                raise UnexpectedError(why)

        assert 'reviewers' in response, '"reviewers" not in HTTP response'
        return tuple([AccountInfo.parse(r) for r in response['reviewers']])
示例#3
0
文件: client.py 项目: sjl421/pycr
    def add_reviewer(cls, change_id, account_id, force=False):
        """Add a reviewer

        Sends a POST request to Gerrit to add one user or all members of one
        group as reviewer to the change.

        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :param account_id: any identification string for an account (name,
            username, email)
        :type account_id: str
        :param force: do not prompt the user for confirmation if gerrit needs a
            confirmation to add multiple reviewers at once (group).  Defaults
            to False
        :type force: bool
        :rtype: tuple(AccountInfo)
        :raise: PyCRError if the Gerrit server returns an error
        """

        cls.log.debug('Assign review to %s: %s', account_id, change_id)

        payload = {'reviewer': account_id}
        headers = {'content-type': 'application/json'}

        try:
            endpoint = changes.reviewers(change_id)
            _, response = RequestFactory.post(endpoint,
                                              data=json.dumps(payload),
                                              headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            raise UnexpectedError(why)

        if 'confirm' in response:
            assert 'error' in response, 'missing "error" field in response'

            cls.log.debug('Assigning review: confirmation requested')

            do_add_reviewers = True if force else confirm(response['error'])

            if not do_add_reviewers:
                info('reviewer not added, aborting...')
                return None

            try:
                payload['confirmed'] = True
                _, response = RequestFactory.post(endpoint,
                                                  data=json.dumps(payload),
                                                  headers=headers)

            except RequestError as why:
                raise UnexpectedError(why)

        assert 'reviewers' in response, '"reviewers" not in HTTP response'
        return tuple([AccountInfo.parse(r) for r in response['reviewers']])
示例#4
0
文件: client.py 项目: 0xcharly/pycr
    def rebase(cls, change_id):
        """Rebase a change

        Sends a POST request to Gerrit to rebase the given change.

        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :rtype: ChangeInfo
        :raise: NoSuchChangeError if the change does not exists
        :raise: ConflictError if could not rebase the change
        :raise: PyCRError on any other error
        """

        cls.log.debug('rebase: %s', change_id)

        try:
            _, change = RequestFactory.post(changes.rebase(change_id))

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 409:
                # There was a conflict rebasing the change
                # Error message is return as PLAIN text
                raise ConflictError(why.response.text.strip())

            raise UnexpectedError(why)

        return ChangeInfo.parse(change)
示例#5
0
文件: gerrit.py 项目: enzbang/pycr
    def rebase(cls, change_id):
        """
        Send a POST request to the Gerrit Code Review server to rebase the
        given change.

        PARAMETERS
            change_id: any identification number for the change (UUID,
                Change-Id, or legacy numeric change ID)

        RETURNS
            a ChangeInfo

        RAISES
            NoSuchChangeError if the change does not exist
            ConflictError if could not submit the change
            PyCRError on any other error
        """

        cls.log.debug('rebase: %s' % change_id)

        try:
            _, change = RequestFactory.post(Api.rebase(change_id))

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 409:
                # There was a conflict rebasing the change
                # Error message is return as PLAIN text
                raise ConflictError(why.response.text.strip())

            raise PyCRError('unexpected error', why)

        return ChangeInfo.parse(change)
示例#6
0
文件: client.py 项目: sjl421/pycr
    def rebase(cls, change_id):
        """Rebase a change

        Sends a POST request to Gerrit to rebase the given change.

        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :rtype: ChangeInfo
        :raise: NoSuchChangeError if the change does not exists
        :raise: ConflictError if could not rebase the change
        :raise: PyCRError on any other error
        """

        cls.log.debug('rebase: %s', change_id)

        try:
            _, change = RequestFactory.post(changes.rebase(change_id))

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 409:
                # There was a conflict rebasing the change
                # Error message is return as PLAIN text
                raise ConflictError(why.response.text.strip())

            raise UnexpectedError(why)

        return ChangeInfo.parse(change)
示例#7
0
文件: client.py 项目: sjl421/pycr
    def set_review(cls,
                   score,
                   message,
                   change_id,
                   label,
                   revision_id='current'):
        """Set a review score

        Sends a POST request to Gerrit to review the given change.

        :param score: the score (-2, -1, 0, +1, +2)
        :type score: str
        :param message: the review message
        :type message: str
        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :param label: the label to score
        :type label: str
        :param revision_id: identifier that uniquely identifies one revision of
            a change (current, a commit ID (SHA1) or abbreviated commit ID, or
            a legacy numeric patch number)
        :type revision_id: str
        :rtype: ChangeInfo
        :raise: NoSuchChangeError if the change does not exists
        :raise: PyCRError on any other error
        """

        cls.log.debug('Set review: %s (revision: %s)', change_id, revision_id)
        cls.log.debug('Score:   %s', score)
        cls.log.debug('Label:   %s', label)
        cls.log.debug('Message: %s', message)

        assert score in Gerrit.SCORES

        payload = {'message': message, 'labels': {label: score}}
        headers = {'content-type': 'application/json'}

        try:
            endpoint = changes.review(change_id, revision_id)
            _, review = RequestFactory.post(endpoint,
                                            data=json.dumps(payload),
                                            headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 400:
                raise QueryError('invalid score "%s" for label "%s"' %
                                 (score, label))

            raise UnexpectedError(why)

        return ReviewInfo.parse(review)
示例#8
0
文件: client.py 项目: 0xcharly/pycr
    def set_review(cls, score, message, change_id, label,
                   revision_id='current'):
        """Set a review score

        Sends a POST request to Gerrit to review the given change.

        :param score: the score (-2, -1, 0, +1, +2)
        :type score: str
        :param message: the review message
        :type message: str
        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :param label: the label to score
        :type label: str
        :param revision_id: identifier that uniquely identifies one revision of
            a change (current, a commit ID (SHA1) or abbreviated commit ID, or
            a legacy numeric patch number)
        :type revision_id: str
        :rtype: ChangeInfo
        :raise: NoSuchChangeError if the change does not exists
        :raise: PyCRError on any other error
        """

        cls.log.debug('Set review: %s (revision: %s)', change_id, revision_id)
        cls.log.debug('Score:   %s', score)
        cls.log.debug('Label:   %s', label)
        cls.log.debug('Message: %s', message)

        assert score in Gerrit.SCORES

        payload = {
            'message': message,
            'labels': {label: score}
        }
        headers = {'content-type': 'application/json'}

        try:
            endpoint = changes.review(change_id, revision_id)
            _, review = RequestFactory.post(endpoint,
                                            data=json.dumps(payload),
                                            headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 400:
                raise QueryError(
                    'invalid score "%s" for label "%s"' % (score, label))

            raise UnexpectedError(why)

        return ReviewInfo.parse(review)
示例#9
0
文件: gerrit.py 项目: enzbang/pycr
    def set_review(cls, score, message, change_id, revision_id='current'):
        """
        Send a POST request to the Gerrit Code Review server to review the
        given change.

        PARAMETERS
            score: the score (-2, -1, 0, +1, +2)
            message: the review message
            change_id: any identification number for the change (UUID,
                Change-Id, or legacy numeric change ID)
            revision_id: identifier that uniquely identifies one revision of a
                change (current, a commit ID (SHA1) or abbreviated commit ID,
                or a legacy numeric patch number)

        RETURNS
            a ChangeInfo

        RAISES
            NoSuchChangeError if the change does not exist
            PyCRError on any other error
        """

        cls.log.debug('Set review: %s (revision: %s)' %
                      (change_id, revision_id))
        cls.log.debug('Score:   %s', score)
        cls.log.debug('Message: %s', message)

        assert score in Gerrit.SCORES

        payload = {
            'message': message,
            'labels': {'Code-Review': score}
        }
        headers = {'content-type': 'application/json'}

        try:
            endpoint = Api.review(change_id, revision_id)
            _, review = RequestFactory.post(endpoint,
                                            data=json.dumps(payload),
                                            headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            raise PyCRError('unexpected error', why)

        return ReviewInfo.parse(review)
示例#10
0
文件: gerrit.py 项目: enzbang/pycr
    def submit(cls, change_id):
        """
        Send a POST request to the Gerrit Code Review server to submit the
        given change.

        PARAMETERS
            change_id: any identification number for the change (UUID,
                Change-Id, or legacy numeric change ID)

        RETURNS
            True if the change was successfully merged, False otherwise

        RAISES
            NoSuchChangeError if the change does not exist
            ConflictError if could not submit the change
            PyCRError on any other error
        """

        cls.log.debug('submit: %s' % change_id)

        payload = {'wait_for_merge': True}
        headers = {'content-type': 'application/json'}

        try:
            _, change = RequestFactory.post(Api.submit(change_id),
                                            data=json.dumps(payload),
                                            headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 409:
                # There was a conflict rebasing the change
                # Error message is return as PLAIN text
                raise ConflictError(why.response.text.strip())

            raise PyCRError('unexpected error', why)

        return ChangeInfo.parse(change).status == ChangeInfo.MERGED
示例#11
0
文件: client.py 项目: 0xcharly/pycr
    def submit(cls, change_id):
        """Submit a change

        Sends a POST request to Gerrit to submit the given change. Returns True
        if the change was successfully merged, False otherwise.

        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :rtype: bool
        :raise: NoSuchChangeError if the change does not exists
        :raise: ConflictError if could not submit the change
        :raise: PyCRError on any other error
        """

        cls.log.debug('submit: %s', change_id)

        payload = {'wait_for_merge': True}
        headers = {'content-type': 'application/json'}

        try:
            _, change = RequestFactory.post(changes.submit(change_id),
                                            data=json.dumps(payload),
                                            headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 409:
                # There was a conflict rebasing the change
                # Error message is return as PLAIN text
                raise ConflictError(why.response.text.strip())

            raise UnexpectedError(why)

        return ChangeInfo.parse(change).status == ChangeInfo.MERGED
示例#12
0
文件: client.py 项目: sjl421/pycr
    def submit(cls, change_id):
        """Submit a change

        Sends a POST request to Gerrit to submit the given change. Returns True
        if the change was successfully merged, False otherwise.

        :param change_id: any identification number for the change (UUID,
            Change-Id, or legacy numeric change ID)
        :type change_id: str
        :rtype: bool
        :raise: NoSuchChangeError if the change does not exists
        :raise: ConflictError if could not submit the change
        :raise: PyCRError on any other error
        """

        cls.log.debug('submit: %s', change_id)

        payload = {'wait_for_merge': True}
        headers = {'content-type': 'application/json'}

        try:
            _, change = RequestFactory.post(changes.submit(change_id),
                                            data=json.dumps(payload),
                                            headers=headers)

        except RequestError as why:
            if why.status_code == 404:
                raise NoSuchChangeError(change_id)

            if why.status_code == 409:
                # There was a conflict rebasing the change
                # Error message is return as PLAIN text
                raise ConflictError(why.response.text.strip())

            raise UnexpectedError(why)

        return ChangeInfo.parse(change).status == ChangeInfo.MERGED