gitgithub3.py

How to Get And List All files from a Github Repository


I am trying to list all files from a Github repository.

def listFiles(self, filepath):
    git = githubHandler(GH_USERNAME, GH_PASSWORD)
    gh, repo, branch = git.connect_to_github()        
    tree = branch.commit.commit.tree.recurse()
    print repo.blob
    print branch

So far I can only output the repo branch and name. Any ideas?


Solution

  • So this is how I solved it after struggling for a while:

    def list_filenames(self, filepath):
        git = githubHandler(GH_USERNAME, GH_PASSWORD)
        gh, repo, branch = git.connect_to_github()        
        tree = branch.commit.commit.tree.recurse()
        for filename in tree.tree: 
            print("[*] Found file {0}".format(filename.path)) 
            print filename.path
        return None