def changesets_for_pushid(pushid: int, push_json_url: str) -> List[str]: """Return a list of changeset IDs in a repository push. Reads data published by the Mozilla hgweb pushlog extension. Also see https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/pushlog.html#writing-agents-that-consume-pushlog-data Args: pushid: The integer pushlog pushid we want information about. push_json_url: The 'push_json_url' field from a hgpush message. See https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/notifications.html#changegroup-1 The pushid in the URL should match the pushid argument to this function. Returns: A list of changeset ID strings (40 char hex strings). """ log.info(f'processing pushid {pushid}') sentry.extra_context({'pushid': pushid}) response = requests_retry_session().get(push_json_url) response.raise_for_status() # See https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/pushlog.html#version-2 changesets = response.json()['pushes'][str(pushid)]['changesets'] log.info(f'got {len(changesets)} changesets for pushid {pushid}') return changesets
def fetch_bug_history(bug_id): """Fetch the given bug's history from Bugzilla.""" # Example: https://bugzilla.mozilla.org/rest/bug/1447193/history url = f'{config.BMO_API_URL}/bug/{bug_id}/history' response = requests_retry_session().get(url) # TODO Workaround for bug 1462349. Can be removed when API calls return the correct value. if 'error' in response.json(): response.status_code = 401 if response.status_code == 401: raise NotAuthorized() response.raise_for_status() history = response.json()['bugs'][0]['history'] return history
def fetch_attachments(bug_id): """Fetch the given bug's attachment list from Bugzilla.""" # Example: https://bugzilla.mozilla.org/rest/bug/1447193/attachment?exclude_fields=data url = f'{config.BMO_API_URL}/bug/{bug_id}/attachment?exclude_fields=data' response = requests_retry_session().get(url) # TODO Workaround for bug 1462349. Can be removed when API calls return the correct value. if 'error' in response.json(): response.status_code = 401 if response.status_code == 401: raise NotAuthorized() response.raise_for_status() attachments = response.json()['bugs'][str(bug_id)] return attachments
def fetch_raw_diff_for_changeset(changesetid: str, repo_url: str) -> str: """Fetch changeset raw 'hg export' patch text from hg.mozilla.org. Raises: NoSuchChangeset if the changeset does not exist on hg.mozilla.org. requests.HTTPError for all other problems. """ # Example URL: https://hg.mozilla.org/mozilla-central/raw-rev/f0fe810b3d7863cdb response = requests_retry_session().get( f'{repo_url}/raw-rev/{changesetid}') if response.status_code == 404: raise NoSuchChangeset( f'The changeset {changesetid} does not exist in repository {repo_url}' ) response.raise_for_status() return response.text
def fetch_changeset(changesetid: str, repo_url: str) -> Dict: """Fetch changeset JSON from hg.mozilla.org. Raises: NoSuchChangeset if the changeset does not exist on hg.mozilla.org. requests.HTTPError for all other problems. """ # Example URL: https://hg.mozilla.org/mozilla-central/json-rev/deafa2891c61 response = requests_retry_session().get( f'{repo_url}/json-rev/{changesetid}') if response.status_code == 404: raise NoSuchChangeset( f'The changeset {changesetid} does not exist in repository {repo_url}' ) response.raise_for_status() return response.json()
def pushes_for_range(repo_url, starting_push_id, ending_push_id): """Fetch a dict of pushes by ID from a repo pushlog. Args: repo_url: The full URL of the repo whose pushlog we want to process. starting_push_id: Integer. Process all pushes greater than this push id. ending_push_id: Integer. Process all pushes less than and including this push id. Returns: A dict of {'pushid': {pushdata}}. See https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/pushlog.html#version-2. """ # See https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/pushlog.html#version-2 params = dict(startID=starting_push_id, endID=ending_push_id, version=2) response = requests_retry_session().get(f'{repo_url}/json-pushes/', params=params) response.raise_for_status() pushlog = response.json() return pushlog['pushes']