def build_github_url(
    repo,
    branch=None,
    path='requirements.txt',
    token=None
):
    """
    Builds a URL to a file inside a Github repository.
    """

    repo = re.sub(r"^http(s)?://github.com/", "", repo).strip('/')

    # args come is as 'None' instead of not being provided
    if not path:
        path = 'requirements.txt'

    if not branch:
        branch = get_default_branch(repo)

    url = 'https://raw.githubusercontent.com/{}/{}/{}'.format(
        repo, branch, path
    )

    if token:
        url = '{}?token={}'.format(url, token)

    return url
def build_github_url ( repo , branch = None , path = 'requirements.txt' , token = None ) : repo = re . sub ( r"^http(s)?://github.com/" , "" , repo ) . strip ( '/' ) if not path : path = 'requirements.txt' if not branch : branch = get_default_branch ( repo ) url = 'https://raw.githubusercontent.com/{}/{}/{}' . format ( repo , branch , path ) if token : url = '{}?token={}' . format ( url , token ) return url
Builds a URL to a file inside a Github repository.