123123class Githubfs (object ):
124124 """This class implements some higher level functionality on top of the Github api"""
125125
126- def __init__ (self , githubuser , reponame , branchname = "master" , username = None , password = None , token = None ):
126+ def __init__ (self , githubuser , reponame , branchname = None , username = None , password = None , token = None ):
127127 """Construct a new githubfs object
128128 :param githubuser: the github user's repo we want to use.
129129 :param reponame: The name of the repository we want to use.
130- :param branchname: Then name of the branch to use (defaults to master)
130+ :param branchname: Then name of the branch to use (defaults to 'main' for easybuilders org, ' master' otherwise )
131131 :param username: (optional) your github username.
132132 :param password: (optional) your github password.
133133 :param token: (optional) a github api token.
134134 """
135+ if branchname is None :
136+ if githubuser == GITHUB_EB_MAIN :
137+ branchname = 'main'
138+ else :
139+ branchname = 'master'
140+
135141 if token is None :
136142 token = fetch_github_token (username )
137143 self .log = fancylogger .getLogger (self .__class__ .__name__ , fname = False )
@@ -218,7 +224,7 @@ def read(self, path, api=True):
218224 """Read the contents of a file and return it
219225 Or, if api=False it will download the file and return the location of the downloaded file"""
220226 # we don't need use the api for this, but can also use raw.github.com
221- # https://raw.github.com/easybuilders/easybuild/master /README.rst
227+ # https://raw.github.com/easybuilders/easybuild/main /README.rst
222228 if not api :
223229 outfile = tempfile .mkstemp ()[1 ]
224230 url = '/' .join ([GITHUB_RAW , self .githubuser , self .reponame , self .branchname , path ])
@@ -301,7 +307,7 @@ def github_api_put_request(request_f, github_user=None, token=None, **kwargs):
301307 return (status , data )
302308
303309
304- def fetch_latest_commit_sha (repo , account , branch = 'master' , github_user = None , token = None ):
310+ def fetch_latest_commit_sha (repo , account , branch = None , github_user = None , token = None ):
305311 """
306312 Fetch latest SHA1 for a specified repository and branch.
307313 :param repo: GitHub repository
@@ -311,6 +317,14 @@ def fetch_latest_commit_sha(repo, account, branch='master', github_user=None, to
311317 :param token: GitHub token to use
312318 :return: latest SHA1
313319 """
320+ if branch is None :
321+ # use 'main' as default branch for 'easybuilders' organisation,
322+ # otherwise use 'master'
323+ if account == GITHUB_EB_MAIN :
324+ branch = 'main'
325+ else :
326+ branch = 'master'
327+
314328 status , data = github_api_get_request (lambda x : x .repos [account ][repo ].branches ,
315329 github_user = github_user , token = token , per_page = GITHUB_MAX_PER_PAGE )
316330 if status != HTTP_STATUS_OK :
@@ -332,7 +346,7 @@ def fetch_latest_commit_sha(repo, account, branch='master', github_user=None, to
332346 return res
333347
334348
335- def download_repo (repo = GITHUB_EASYCONFIGS_REPO , branch = 'master' , account = GITHUB_EB_MAIN , path = None , github_user = None ):
349+ def download_repo (repo = GITHUB_EASYCONFIGS_REPO , branch = None , account = GITHUB_EB_MAIN , path = None , github_user = None ):
336350 """
337351 Download entire GitHub repo as a tar.gz archive, and extract it into specified path.
338352 :param repo: repo to download
@@ -341,6 +355,14 @@ def download_repo(repo=GITHUB_EASYCONFIGS_REPO, branch='master', account=GITHUB_
341355 :param path: path to extract to
342356 :param github_user: name of GitHub user to use
343357 """
358+ if branch is None :
359+ # use 'main' as default branch for 'easybuilders' organisation,
360+ # otherwise use 'master'
361+ if account == GITHUB_EB_MAIN :
362+ branch = 'main'
363+ else :
364+ branch = 'master'
365+
344366 # make sure path exists, create it if necessary
345367 if path is None :
346368 path = tempfile .mkdtemp ()
@@ -1940,7 +1962,7 @@ def check_github():
19401962 branch_name = 'test_branch_%s' % '' .join (random .choice (ascii_letters ) for _ in range (5 ))
19411963 try :
19421964 git_repo = init_repo (git_working_dir , GITHUB_EASYCONFIGS_REPO , silent = not debug )
1943- remote_name = setup_repo (git_repo , github_account , GITHUB_EASYCONFIGS_REPO , 'master ' ,
1965+ remote_name = setup_repo (git_repo , github_account , GITHUB_EASYCONFIGS_REPO , 'main ' ,
19441966 silent = not debug , git_only = True )
19451967 git_repo .create_head (branch_name )
19461968 res = getattr (git_repo .remotes , remote_name ).push (branch_name )
0 commit comments