Skip to content

Commit f61dc6a

Browse files
Merge pull request #3589 from boegel/github_main_branch
use 'main' rather than 'master' branch in GitHub integration functionality
2 parents 62bc65e + 21c81f4 commit f61dc6a

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

easybuild/tools/github.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,21 @@
123123
class 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)

test/framework/filetools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ def test_get_source_tarball_from_git(self):
23942394
git_config = {
23952395
'repo_name': 'testrepository',
23962396
'url': 'https://github.com/easybuilders',
2397-
'tag': 'master',
2397+
'tag': 'main',
23982398
}
23992399
target_dir = os.path.join(self.test_prefix, 'target')
24002400

test/framework/github.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
GITHUB_USER = "easybuilders"
6161
GITHUB_REPO = "testrepository"
6262
# branch to test
63-
GITHUB_BRANCH = 'master'
63+
GITHUB_BRANCH = 'main'
6464

6565

6666
class GithubTest(EnhancedTestCase):
@@ -71,12 +71,15 @@ class GithubTest(EnhancedTestCase):
7171
def setUp(self):
7272
"""setup"""
7373
super(GithubTest, self).setUp()
74+
7475
self.github_token = gh.fetch_github_token(GITHUB_TEST_ACCOUNT)
76+
7577
if self.github_token is None:
76-
self.ghfs = gh.Githubfs(GITHUB_USER, GITHUB_REPO, GITHUB_BRANCH, None, None, None)
78+
username, token = None, None
7779
else:
78-
self.ghfs = gh.Githubfs(GITHUB_USER, GITHUB_REPO, GITHUB_BRANCH, GITHUB_TEST_ACCOUNT,
79-
None, self.github_token)
80+
username, token = GITHUB_TEST_ACCOUNT, self.github_token
81+
82+
self.ghfs = gh.Githubfs(GITHUB_USER, GITHUB_REPO, GITHUB_BRANCH, username, None, token)
8083

8184
self.skip_github_tests = self.github_token is None and os.getenv('FORCE_EB_GITHUB_TESTS') is None
8285

@@ -452,7 +455,7 @@ def test_download_repo(self):
452455

453456
# default: download tarball for master branch of easybuilders/easybuild-easyconfigs repo
454457
path = gh.download_repo(path=self.test_prefix, github_user=GITHUB_TEST_ACCOUNT)
455-
repodir = os.path.join(self.test_prefix, 'easybuilders', 'easybuild-easyconfigs-master')
458+
repodir = os.path.join(self.test_prefix, 'easybuilders', 'easybuild-easyconfigs-main')
456459
self.assertTrue(os.path.samefile(path, repodir))
457460
self.assertTrue(os.path.exists(repodir))
458461
shafile = os.path.join(repodir, 'latest-sha')
@@ -634,7 +637,7 @@ def run_check(expected_result=False):
634637

635638
pr_data = {
636639
'base': {
637-
'ref': 'master',
640+
'ref': 'main',
638641
'repo': {
639642
'name': 'easybuild-easyconfigs',
640643
'owner': {'login': 'easybuilders'},
@@ -652,7 +655,7 @@ def run_check(expected_result=False):
652655
expected_stdout = "Checking eligibility of easybuilders/easybuild-easyconfigs PR #1234 for merging...\n"
653656

654657
# target branch for PR must be develop
655-
expected_warning = "* targets develop branch: FAILED; found 'master' => not eligible for merging!\n"
658+
expected_warning = "* targets develop branch: FAILED; found 'main' => not eligible for merging!\n"
656659
run_check()
657660

658661
pr_data['base']['ref'] = 'develop'
@@ -937,7 +940,7 @@ def test_push_branch_to_github(self):
937940

938941
self.mock_stderr(True)
939942
self.mock_stdout(True)
940-
gh.setup_repo(git_repo, GITHUB_USER, GITHUB_REPO, 'master')
943+
gh.setup_repo(git_repo, GITHUB_USER, GITHUB_REPO, 'main')
941944
git_repo.create_head(branch, force=True)
942945
gh.push_branch_to_github(git_repo, GITHUB_USER, GITHUB_REPO, branch)
943946
stderr = self.get_stderr()
@@ -949,7 +952,7 @@ def test_push_branch_to_github(self):
949952

950953
github_path = '%s/%s.git' % (GITHUB_USER, GITHUB_REPO)
951954
pattern = r'^' + '\n'.join([
952-
r"== fetching branch 'master' from https://github.com/%s\.\.\." % github_path,
955+
r"== fetching branch 'main' from https://github.com/%s\.\.\." % github_path,
953956
r"== pushing branch 'test123' to remote 'github_.*' \([email protected]:%s\) \[DRY RUN\]" % github_path,
954957
]) + r'$'
955958
regex = re.compile(pattern)

test/framework/options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,17 +4103,17 @@ def test_new_update_pr(self):
41034103
'--pr-branch-name=branch_name_for_new_pr_test',
41044104
'--pr-commit-msg="this is a commit message. really!"',
41054105
'--pr-descr="moar letters foar teh lettre box"',
4106-
'--pr-target-branch=master',
4106+
'--pr-target-branch=main',
41074107
'--github-org=%s' % GITHUB_TEST_ORG,
41084108
'--pr-target-account=boegel', # we need to be able to 'clone' from here (via https)
41094109
'--pr-title=test-1-2-3',
41104110
])
41114111
txt, _ = self._run_mock_eb(args, do_build=True, raise_error=True, testing=False)
41124112

41134113
regexs = [
4114-
r"^== fetching branch 'master' from https://github.com/boegel/easybuild-easyconfigs.git...",
4114+
r"^== fetching branch 'main' from https://github.com/boegel/easybuild-easyconfigs.git...",
41154115
r"^Opening pull request \[DRY RUN\]",
4116-
r"^\* target: boegel/easybuild-easyconfigs:master",
4116+
r"^\* target: boegel/easybuild-easyconfigs:main",
41174117
r"^\* from: %s/easybuild-easyconfigs:branch_name_for_new_pr_test" % GITHUB_TEST_ORG,
41184118
r"\(created using `eb --new-pr`\)", # description
41194119
r"moar letters foar teh lettre box", # also description (see --pr-descr)

test/framework/toy_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ def test_toy_extension_sources_git_config(self):
13411341
' "git_config": {',
13421342
' "repo_name": "testrepository",',
13431343
' "url": "https://github.com/easybuilders",',
1344-
' "tag": "master",',
1344+
' "tag": "main",',
13451345
' },',
13461346
' },',
13471347
' }),',

0 commit comments

Comments
 (0)