Ejemplo n.º 1
0
    def get_reviewer(cls, change_id, account_id):
        """Fetch a reviewer info

        Sends a GET request to Gerrit to fetch details about a reviewer of a
        change. Returns None if the reviewer does not exists or is not a
        reviewer of 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
        :rtype: ReviewerInfo | None
        :raise: PyCRError if the Gerrit server returns an error
        """

        cls.log.debug('Reviewer lookup: "%s" for %s', account_id, change_id)

        try:
            endpoint = changes.reviewer(change_id, account_id)
            _, response = RequestFactory.get(endpoint)

        except RequestError as why:
            if why.status_code == 404:
                # The user does not exist or is not a reviewer of the change
                return None

            raise UnexpectedError(why)

        return ReviewerInfo.parse(response)
Ejemplo n.º 2
0
    def get_reviewer(cls, change_id, account_id):
        """Fetch a reviewer info

        Sends a GET request to Gerrit to fetch details about a reviewer of a
        change. Returns None if the reviewer does not exists or is not a
        reviewer of 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
        :rtype: ReviewerInfo | None
        :raise: PyCRError if the Gerrit server returns an error
        """

        cls.log.debug('Reviewer lookup: "%s" for %s', account_id, change_id)

        try:
            endpoint = changes.reviewer(change_id, account_id)
            _, response = RequestFactory.get(endpoint)

        except RequestError as why:
            if why.status_code == 404:
                # The user does not exist or is not a reviewer of the change
                return None

            raise UnexpectedError(why)

        return ReviewerInfo.parse(response)
Ejemplo n.º 3
0
    def delete_reviewer(cls, change_id, account_id):
        """Remove a reviewer from the list of reviewer of a change

        Sends a DELETE request to Gerrit to delete one user from the reviewer's
        list of a change. Returns None if the reviewer does not exists or is
        not a reviewer of 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
        :rtype: ReviewerInfo | None
        :raise: PyCRError if the Gerrit server returns an error
        """

        cls.log.debug('Delete reviewer: "%s" for %s', account_id, change_id)

        try:
            endpoint = changes.reviewer(change_id, account_id)

            _, response = RequestFactory.get(endpoint)
            RequestFactory.delete(endpoint)

        except RequestError as why:
            if why.status_code == 403:
                raise PyCRError(
                    'no sufficient permissions or already submitted')

            if why.status_code == 404:
                # The user does not exist or is not a reviewer of the change
                return None

            raise UnexpectedError(why)

        assert len(response) == 1
        return ReviewerInfo.parse(response[0])
Ejemplo n.º 4
0
    def get_reviews(cls, change_id):
        """Fetch the reviews for a change

        Sends a GET request to Gerrit to fetch the reviews for 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: tuple[ReviewerInfo]
        :raise: NoSuchChangeError if the change does not exists
        :raise: PyCRError on any other error
        """

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

        try:
            endpoint = changes.reviewers(change_id)
            _, response = RequestFactory.get(endpoint)

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

            raise UnexpectedError(why)

        # If 'approvals' field is missing, then there is no reviewer

        # NOTE: This seems to be against the specifications for this method:
        # https://gerrit-review.googlesource.com/Documentation/
        #   rest-api-changes.html#list-reviewers
        # "As result a list of ReviewerInfo entries is returned."
        # A ReviewerInfo entry is expected to have an "approvals" field, but
        # experiences show that it's not always the case, and that the change
        # owner can also be in the list although not a reviewers.

        return tuple(
            [ReviewerInfo.parse(r) for r in response if 'approvals' in r])
Ejemplo n.º 5
0
    def delete_reviewer(cls, change_id, account_id):
        """Remove a reviewer from the list of reviewer of a change

        Sends a DELETE request to Gerrit to delete one user from the reviewer's
        list of a change. Returns None if the reviewer does not exists or is
        not a reviewer of 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
        :rtype: ReviewerInfo | None
        :raise: PyCRError if the Gerrit server returns an error
        """

        cls.log.debug('Delete reviewer: "%s" for %s', account_id, change_id)

        try:
            endpoint = changes.reviewer(change_id, account_id)

            _, response = RequestFactory.get(endpoint)
            RequestFactory.delete(endpoint)

        except RequestError as why:
            if why.status_code == 403:
                raise PyCRError(
                    'no sufficient permissions or already submitted')

            if why.status_code == 404:
                # The user does not exist or is not a reviewer of the change
                return None

            raise UnexpectedError(why)

        assert len(response) == 1
        return ReviewerInfo.parse(response[0])
Ejemplo n.º 6
0
    def get_reviews(cls, change_id):
        """Fetch the reviews for a change

        Sends a GET request to Gerrit to fetch the reviews for 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: tuple[ReviewerInfo]
        :raise: NoSuchChangeError if the change does not exists
        :raise: PyCRError on any other error
        """

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

        try:
            endpoint = changes.reviewers(change_id)
            _, response = RequestFactory.get(endpoint)

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

            raise UnexpectedError(why)

        # If 'approvals' field is missing, then there is no reviewer

        # NOTE: This seems to be against the specifications for this method:
        # https://gerrit-review.googlesource.com/Documentation/
        #   rest-api-changes.html#list-reviewers
        # "As result a list of ReviewerInfo entries is returned."
        # A ReviewerInfo entry is expected to have an "approvals" field, but
        # experiences show that it's not always the case, and that the change
        # owner can also be in the list although not a reviewers.

        return tuple(
            [ReviewerInfo.parse(r) for r in response if 'approvals' in r])