def get_artifacts_to_download()

in buildkite/download-artifact/download_artifacts.py [0:0]


def get_artifacts_to_download(pattern: str, request_url: str, artifacts: list = None) -> list:
    """
    Recursively gets all artifacts match the given pattern from a paginated artifacts list request.
    See https://buildkite.com/docs/apis/rest-api/artifacts#list-artifacts-for-a-build
    :param pattern: glob path
    :param request_url: artifacts list request URL
    :param artifacts: buildkite artifacts
    :return:
    """
    if artifacts is None:
        artifacts = []
    response = requests.get(
        request_url,
        headers=HEADERS
    )
    matching_artifacts = find_all_matching_artifacts(
        response.json(),
        pattern
    )
    next_url = get_next_artifacts_url(response)
    combined_artifacts = artifacts + matching_artifacts
    if next_url is None:
        return combined_artifacts
    else:
        return get_artifacts_to_download(pattern, next_url, combined_artifacts)