-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgh_default_branch.py
40 lines (35 loc) · 2.04 KB
/
gh_default_branch.py
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
35
36
37
38
39
import config
import calendar
from github import Github
import time
ACCESS_TOKEN = config.gh_api_key
g = Github(ACCESS_TOKEN)
def repo_default_branch(filterkey):
orgname = config.gh_orgname
repositories = g.search_repositories(query='org:{}'.format(orgname))
for repo in repositories:
rate_limit = g.get_rate_limit()
corerate = rate_limit.core
if corerate.remaining == 0:
print(f'You have 0/{corerate.limit} core API calls remaining. Reset time: {corerate.reset}')
reset_timestamp = calendar.timegm(rate.reset.timetuple())
sleep_time = reset_timestamp - calendar.timegm(time.gmtime()) + 5 # add 5 seconds to be sure the rate limit has been reset
time.sleep(sleep_time)
return
else:
print(f'Your API call rate for core: {corerate.remaining}/{corerate.limit}')
if repo.private == False:
if filterkey in repo.full_name:
repo = g.get_repo(repo.full_name)
defaultbranch = repo.default_branch
if defaultbranch == 'master':
print('Repo: ', repo.full_name, 'has a default branch named master.')
# You could automatically log an Issue asking maintainers to change default branch to main
# repo.create_issue(title="Make the default branch main instead of master",
# body="Our required terminology policy makes the main branch the default
# as standard for all our organization repositories. Here's a link
# to the [GitHub documentation on renaming a branch](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/changing-the-default-branch).")
if __name__ == '__main__':
filterkey = input('Enter a keyword such as ansible, labs, to filter a list of repo names in an org: ')
#filterkey = 'ansible'
repo_default_branch(filterkey)