-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_all.py
More file actions
34 lines (29 loc) · 1.13 KB
/
get_all.py
File metadata and controls
34 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from git import Repo, exc
from git.exc import GitCommandError
from github import Github
import logging
ROUTE_DIR = 'localpath'
ORGANIZATION = 'companyname'
LOGIN = 'gitlogin'
PASS = 'gitpass'
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M:%S')
log = logging.getLogger(__name__)
logging.getLogger('git').setLevel(logging.INFO)
logging.getLogger('github').setLevel(logging.INFO)
g = Github(login_or_token=LOGIN, password=PASS)
org = g.get_organization(ORGANIZATION)
repos = org.get_repos()
for repo in repos:
try:
Repo.clone_from('git@github.com:{}/{}'.format(ORGANIZATION, repo.name), '{}{}'.format(ROUTE_DIR, repo.name))
print('Cloned - {}'.format(repo.name))
except GitCommandError as e:
try:
local_repo = Repo(path='{}{}'.format(ROUTE_DIR, repo.name))
local_repo.remotes.origin.pull()
print('Pulled - {}'.format(repo.name))
except Exception as e2:
logging.info("Error with repo - {}".format(repo.name))
logging.exception(e2.message)