def list_changes(cls, status='open', owner='self'): """List changes Sends a GET request to Gerrit to fetch the list of changes with the given STATUS and from the given OWNER. :param status: the status of the change (open, merged, ...) :type status: str :param owner: the account_id of the owner of the changes :type owner: str :rtype: tuple[ChangeInfo] :raise: NoSuchChangeError if no change match the query criterion :raise: PyCRError on any other error """ cls.log.debug( 'Changes lookup with status:%s & owner:%s', status, owner) try: endpoint = changes.search_query(status=status, owner=owner) # DETAILED_ACCOUNTS option ensures that the owner email address is # sent in the response extra_params = {'o': 'DETAILED_ACCOUNTS'} _, response = RequestFactory.get(endpoint, params=extra_params) except RequestError as why: if why.status_code == 404: raise QueryError('no result for query criterion') raise UnexpectedError(why) return tuple([ChangeInfo.parse(c) for c in response])
def get_change(cls, change_id): """Fetch a change details Sends a GET request to Gerrit to fetch the data on 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: PyCRError on any other error """ cls.log.debug('Change lookup: %s', change_id) try: endpoint = changes.detailed_changes(change_id) # CURRENT_REVISION describe the current revision (patch set) of the # change, including the commit SHA-1 and URLs to fetch from extra_params = {'o': 'CURRENT_REVISION'} _, response = RequestFactory.get(endpoint, params=extra_params) except RequestError as why: if why.status_code == 404: raise NoSuchChangeError(change_id) raise UnexpectedError(why) return ChangeInfo.parse(response)
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)
def list_changes(cls, status='open', owner='self'): """List changes Sends a GET request to Gerrit to fetch the list of changes with the given STATUS and from the given OWNER. :param status: the status of the change (open, merged, ...) :type status: str :param owner: the account_id of the owner of the changes :type owner: str :rtype: tuple[ChangeInfo] :raise: NoSuchChangeError if no change match the query criterion :raise: PyCRError on any other error """ cls.log.debug('Changes lookup with status:%s & owner:%s', status, owner) try: endpoint = changes.search_query(status=status, owner=owner) # DETAILED_ACCOUNTS option ensures that the owner email address is # sent in the response extra_params = {'o': 'DETAILED_ACCOUNTS'} _, response = RequestFactory.get(endpoint, params=extra_params) except RequestError as why: if why.status_code == 404: raise QueryError('no result for query criterion') raise UnexpectedError(why) return tuple([ChangeInfo.parse(c) for c in response])
def get_starred_changes(cls, account_id='self'): """Fetch Gerrit account starred changes :param account_id: identifier that uniquely identifies one account :type account: str :rtype: tuple[ChangeInfo] :raise: PyCRError on any other error """ cls.log.debug('List Gerrit account starred changes') try: _, response = RequestFactory.get( accounts.starred_changes(account_id)) except RequestError as why: if why.status_code == 404: raise QueryError('no such account') raise UnexpectedError(why) return tuple([ChangeInfo.parse(c) for c in response])
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