import requests


def get_pack_dir(branch: str, pr_number: str, repo: str) -> str:
    """
    Get a pack dir name from a contribution pull request changed files
    Args:
        branch: The contrib branch
        pr_number: The contrib PR
        repo: The contrib repo

    Returns:
        A pack dir name, if found.
    """

    page = 1
    pack_dir_name = ''
    while True:
        response = requests.get(f'https://api.github.com/repos/demisto/content/pulls/{pr_number}/files',
                                params={'page': str(page)})
        response.raise_for_status()
        files = response.json()
        if not files:
            break
        for pr_file in files:
            if pr_file['filename'].startswith('Packs/'):
                pack_dir_name = pr_file['filename'].split('/')[1]
                break
        if pack_dir_name:
            break
        page += 1

    print(f'Copy the changes from the contributor branch {repo}/{branch} in the pack {pack_dir_name}')
    return pack_dir_name