Get all file names from a Github repo through the Github API

后端 未结 4 1305
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 01:02

Is it possible to get all the file names from repository using the GitHub API?

I\'m currently trying to tinker this using PyGithub, but I\'m totally ok with manually

4条回答
  •  盖世英雄少女心
    2020-12-10 01:48

    As Dan mentioned: github trees

    See working example below

    import requests
    
    user = "grumbach"
    repo = "ft_ping"
    
    url = "https://api.github.com/repos/{}/{}/git/trees/master?recursive=1".format(user, repo)
    r = requests.get(url)
    res = r.json()
    
    for file in res["tree"]:
        print(file["path"])
    

    For the sake of simplicity I omitted error management, velociraptors are extinct anyway…

提交回复
热议问题