├── .gitignore ├── .gitmodules ├── README.md ├── basicExample.py ├── createRepoForAnOrganization.py ├── listAllMyRepos.py └── listAllReposForAnOrganization.py /.gitignore: -------------------------------------------------------------------------------- 1 | # emacs backup files 2 | *~ 3 | 4 | # compiled Python code 5 | 6 | *.py[cod] 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Packages 12 | *.egg 13 | *.egg-info 14 | dist 15 | build 16 | eggs 17 | parts 18 | bin 19 | var 20 | sdist 21 | develop-eggs 22 | .installed.cfg 23 | lib 24 | lib64 25 | 26 | # Installer logs 27 | pip-log.txt 28 | 29 | # Unit test / coverage reports 30 | .coverage 31 | .tox 32 | nosetests.xml 33 | 34 | # Translations 35 | *.mo 36 | 37 | # Mr Developer 38 | .mr.developer.cfg 39 | .project 40 | .pydevproject 41 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "PyGithub"] 2 | path = PyGithub 3 | url = git://github.com/jacquev6/PyGithub.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PyGitHubExamples 2 | ================ 3 | 4 | Simple Examples of using PyGithub (https://github.com/jacquev6/PyGithub/) 5 | 6 | This repo exists primiarly to support development of examples for the wiki page at: 7 | 8 | * https://github.com/jacquev6/PyGithub/wiki/Examples 9 | 10 | -------------------------------------------------------------------------------- /basicExample.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | sys.path.append("./PyGithub"); 5 | from github import Github 6 | 7 | import getpass 8 | 9 | # Authenticate to github.com and create PyGithub "Github" object 10 | username = raw_input("Github Username:") 11 | pw = getpass.getpass() 12 | g = Github(username, pw) 13 | 14 | # Use the PyGithub Github object g to do whatever you want, 15 | # for example, list all your own repos (user is whichever user authenticated) 16 | 17 | for repo in g.get_user().get_repos(): 18 | print (repo.name) 19 | -------------------------------------------------------------------------------- /createRepoForAnOrganization.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | sys.path.append("./PyGithub"); 5 | from github import Github 6 | 7 | import getpass 8 | import argparse 9 | 10 | 11 | from github import Github 12 | from github import GithubException 13 | 14 | parser = argparse.ArgumentParser(description='List all repos for an org') 15 | parser.add_argument('orgName',help='github Organization name') 16 | 17 | args = parser.parse_args() 18 | 19 | username = raw_input("Github Username:") 20 | pw = getpass.getpass() 21 | g = Github(username, pw) 22 | orgName = args.orgName 23 | 24 | try: 25 | org = g.get_organization(orgName) 26 | except GithubException as ghe: 27 | print(ghe) 28 | 29 | try: 30 | org.create_repo( 31 | "myNewRepo", # name -- string 32 | "My new repo, created using PyGithub", # description -- string 33 | "http://www.example.org", # homepage -- string 34 | True, # private -- bool 35 | True, # has_issues -- bool 36 | True, # has_wiki -- bool 37 | True, # has_downloads -- bool 38 | auto_init=True, 39 | gitignore_template="Python") 40 | 41 | # You could also set team_id= to something of type github.Team.Team 42 | 43 | except GithubException as ghe: 44 | print(ghe) 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /listAllMyRepos.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import getpass 4 | import sys 5 | 6 | # In the main directory of the repo where you are developing with PyGithub, 7 | # type: 8 | # git submodule add git://github.com/jacquev6/PyGithub.git PyGithub 9 | # git submodule init 10 | # git submodule update 11 | # 12 | # That will populate a PyGithub subdirectory with a clone of PyGithub 13 | # Then, to add it to your Python path, you can do: 14 | 15 | sys.path.append("./PyGithub"); 16 | 17 | from github import Github 18 | from github import GithubException 19 | 20 | username = raw_input("Github Username:") 21 | pw = getpass.getpass() 22 | g = Github(username, pw) 23 | 24 | for repo in g.get_user().get_repos(): 25 | print (repo.name) 26 | 27 | -------------------------------------------------------------------------------- /listAllReposForAnOrganization.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import getpass 4 | import sys 5 | import argparse 6 | 7 | # In the main directory of the repo where you are developing with PyGithub, 8 | # type: 9 | # git submodule add git://github.com/jacquev6/PyGithub.git PyGithub 10 | # git submodule init 11 | # git submodule update 12 | # 13 | # That will populate a PyGithub subdirectory with a clone of PyGithub 14 | # Then, to add it to your Python path, you can do: 15 | 16 | sys.path.append("./PyGithub"); 17 | 18 | from github import Github 19 | from github import GithubException 20 | 21 | parser = argparse.ArgumentParser(description='List all repos for an org') 22 | parser.add_argument('orgName',help='github Organization name') 23 | 24 | args = parser.parse_args() 25 | 26 | username = raw_input("Github Username:") 27 | pw = getpass.getpass() 28 | g = Github(username, pw) 29 | 30 | print("All repos for organization: ",args.orgName) 31 | 32 | org = g.get_organization(args.orgName) 33 | 34 | ## TODO: Add some error checking code here to see whether 35 | ## the lookup was successful. Do we try/except or check the return value? 36 | 37 | repos = org.get_repos() 38 | 39 | for repo in repos: 40 | print (repo.name) 41 | 42 | --------------------------------------------------------------------------------