diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index f3ff4629e5..71f4718e5c 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -123,15 +123,21 @@ class Githubfs(object): """This class implements some higher level functionality on top of the Github api""" - def __init__(self, githubuser, reponame, branchname="master", username=None, password=None, token=None): + def __init__(self, githubuser, reponame, branchname=None, username=None, password=None, token=None): """Construct a new githubfs object :param githubuser: the github user's repo we want to use. :param reponame: The name of the repository we want to use. - :param branchname: Then name of the branch to use (defaults to master) + :param branchname: Then name of the branch to use (defaults to 'main' for easybuilders org, 'master' otherwise) :param username: (optional) your github username. :param password: (optional) your github password. :param token: (optional) a github api token. """ + if branchname is None: + if githubuser == GITHUB_EB_MAIN: + branchname = 'main' + else: + branchname = 'master' + if token is None: token = fetch_github_token(username) self.log = fancylogger.getLogger(self.__class__.__name__, fname=False) @@ -218,7 +224,7 @@ def read(self, path, api=True): """Read the contents of a file and return it Or, if api=False it will download the file and return the location of the downloaded file""" # we don't need use the api for this, but can also use raw.github.com - # https://raw.github.com/easybuilders/easybuild/master/README.rst + # https://raw.github.com/easybuilders/easybuild/main/README.rst if not api: outfile = tempfile.mkstemp()[1] 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): return (status, data) -def fetch_latest_commit_sha(repo, account, branch='master', github_user=None, token=None): +def fetch_latest_commit_sha(repo, account, branch=None, github_user=None, token=None): """ Fetch latest SHA1 for a specified repository and branch. :param repo: GitHub repository @@ -311,6 +317,14 @@ def fetch_latest_commit_sha(repo, account, branch='master', github_user=None, to :param token: GitHub token to use :return: latest SHA1 """ + if branch is None: + # use 'main' as default branch for 'easybuilders' organisation, + # otherwise use 'master' + if account == GITHUB_EB_MAIN: + branch = 'main' + else: + branch = 'master' + status, data = github_api_get_request(lambda x: x.repos[account][repo].branches, github_user=github_user, token=token, per_page=GITHUB_MAX_PER_PAGE) if status != HTTP_STATUS_OK: @@ -332,7 +346,7 @@ def fetch_latest_commit_sha(repo, account, branch='master', github_user=None, to return res -def download_repo(repo=GITHUB_EASYCONFIGS_REPO, branch='master', account=GITHUB_EB_MAIN, path=None, github_user=None): +def download_repo(repo=GITHUB_EASYCONFIGS_REPO, branch=None, account=GITHUB_EB_MAIN, path=None, github_user=None): """ Download entire GitHub repo as a tar.gz archive, and extract it into specified path. :param repo: repo to download @@ -341,6 +355,14 @@ def download_repo(repo=GITHUB_EASYCONFIGS_REPO, branch='master', account=GITHUB_ :param path: path to extract to :param github_user: name of GitHub user to use """ + if branch is None: + # use 'main' as default branch for 'easybuilders' organisation, + # otherwise use 'master' + if account == GITHUB_EB_MAIN: + branch = 'main' + else: + branch = 'master' + # make sure path exists, create it if necessary if path is None: path = tempfile.mkdtemp() @@ -1940,7 +1962,7 @@ def check_github(): branch_name = 'test_branch_%s' % ''.join(random.choice(ascii_letters) for _ in range(5)) try: git_repo = init_repo(git_working_dir, GITHUB_EASYCONFIGS_REPO, silent=not debug) - remote_name = setup_repo(git_repo, github_account, GITHUB_EASYCONFIGS_REPO, 'master', + remote_name = setup_repo(git_repo, github_account, GITHUB_EASYCONFIGS_REPO, 'main', silent=not debug, git_only=True) git_repo.create_head(branch_name) res = getattr(git_repo.remotes, remote_name).push(branch_name) diff --git a/test/framework/filetools.py b/test/framework/filetools.py index b195ae58a5..c948477aae 100644 --- a/test/framework/filetools.py +++ b/test/framework/filetools.py @@ -2394,7 +2394,7 @@ def test_get_source_tarball_from_git(self): git_config = { 'repo_name': 'testrepository', 'url': 'https://github.com/easybuilders', - 'tag': 'master', + 'tag': 'main', } target_dir = os.path.join(self.test_prefix, 'target') diff --git a/test/framework/github.py b/test/framework/github.py index f83088c4b2..8a11ef4dc2 100644 --- a/test/framework/github.py +++ b/test/framework/github.py @@ -60,7 +60,7 @@ GITHUB_USER = "easybuilders" GITHUB_REPO = "testrepository" # branch to test -GITHUB_BRANCH = 'master' +GITHUB_BRANCH = 'main' class GithubTest(EnhancedTestCase): @@ -71,12 +71,15 @@ class GithubTest(EnhancedTestCase): def setUp(self): """setup""" super(GithubTest, self).setUp() + self.github_token = gh.fetch_github_token(GITHUB_TEST_ACCOUNT) + if self.github_token is None: - self.ghfs = gh.Githubfs(GITHUB_USER, GITHUB_REPO, GITHUB_BRANCH, None, None, None) + username, token = None, None else: - self.ghfs = gh.Githubfs(GITHUB_USER, GITHUB_REPO, GITHUB_BRANCH, GITHUB_TEST_ACCOUNT, - None, self.github_token) + username, token = GITHUB_TEST_ACCOUNT, self.github_token + + self.ghfs = gh.Githubfs(GITHUB_USER, GITHUB_REPO, GITHUB_BRANCH, username, None, token) self.skip_github_tests = self.github_token is None and os.getenv('FORCE_EB_GITHUB_TESTS') is None @@ -452,7 +455,7 @@ def test_download_repo(self): # default: download tarball for master branch of easybuilders/easybuild-easyconfigs repo path = gh.download_repo(path=self.test_prefix, github_user=GITHUB_TEST_ACCOUNT) - repodir = os.path.join(self.test_prefix, 'easybuilders', 'easybuild-easyconfigs-master') + repodir = os.path.join(self.test_prefix, 'easybuilders', 'easybuild-easyconfigs-main') self.assertTrue(os.path.samefile(path, repodir)) self.assertTrue(os.path.exists(repodir)) shafile = os.path.join(repodir, 'latest-sha') @@ -634,7 +637,7 @@ def run_check(expected_result=False): pr_data = { 'base': { - 'ref': 'master', + 'ref': 'main', 'repo': { 'name': 'easybuild-easyconfigs', 'owner': {'login': 'easybuilders'}, @@ -652,7 +655,7 @@ def run_check(expected_result=False): expected_stdout = "Checking eligibility of easybuilders/easybuild-easyconfigs PR #1234 for merging...\n" # target branch for PR must be develop - expected_warning = "* targets develop branch: FAILED; found 'master' => not eligible for merging!\n" + expected_warning = "* targets develop branch: FAILED; found 'main' => not eligible for merging!\n" run_check() pr_data['base']['ref'] = 'develop' @@ -937,7 +940,7 @@ def test_push_branch_to_github(self): self.mock_stderr(True) self.mock_stdout(True) - gh.setup_repo(git_repo, GITHUB_USER, GITHUB_REPO, 'master') + gh.setup_repo(git_repo, GITHUB_USER, GITHUB_REPO, 'main') git_repo.create_head(branch, force=True) gh.push_branch_to_github(git_repo, GITHUB_USER, GITHUB_REPO, branch) stderr = self.get_stderr() @@ -949,7 +952,7 @@ def test_push_branch_to_github(self): github_path = '%s/%s.git' % (GITHUB_USER, GITHUB_REPO) pattern = r'^' + '\n'.join([ - r"== fetching branch 'master' from https://github.com/%s\.\.\." % github_path, + r"== fetching branch 'main' from https://github.com/%s\.\.\." % github_path, r"== pushing branch 'test123' to remote 'github_.*' \(git@github.com:%s\) \[DRY RUN\]" % github_path, ]) + r'$' regex = re.compile(pattern) diff --git a/test/framework/options.py b/test/framework/options.py index dedd242068..3a8539014c 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -4103,7 +4103,7 @@ def test_new_update_pr(self): '--pr-branch-name=branch_name_for_new_pr_test', '--pr-commit-msg="this is a commit message. really!"', '--pr-descr="moar letters foar teh lettre box"', - '--pr-target-branch=master', + '--pr-target-branch=main', '--github-org=%s' % GITHUB_TEST_ORG, '--pr-target-account=boegel', # we need to be able to 'clone' from here (via https) '--pr-title=test-1-2-3', @@ -4111,9 +4111,9 @@ def test_new_update_pr(self): txt, _ = self._run_mock_eb(args, do_build=True, raise_error=True, testing=False) regexs = [ - r"^== fetching branch 'master' from https://github.com/boegel/easybuild-easyconfigs.git...", + r"^== fetching branch 'main' from https://github.com/boegel/easybuild-easyconfigs.git...", r"^Opening pull request \[DRY RUN\]", - r"^\* target: boegel/easybuild-easyconfigs:master", + r"^\* target: boegel/easybuild-easyconfigs:main", r"^\* from: %s/easybuild-easyconfigs:branch_name_for_new_pr_test" % GITHUB_TEST_ORG, r"\(created using `eb --new-pr`\)", # description r"moar letters foar teh lettre box", # also description (see --pr-descr) diff --git a/test/framework/toy_build.py b/test/framework/toy_build.py index 653238f4ee..9809e5b999 100644 --- a/test/framework/toy_build.py +++ b/test/framework/toy_build.py @@ -1341,7 +1341,7 @@ def test_toy_extension_sources_git_config(self): ' "git_config": {', ' "repo_name": "testrepository",', ' "url": "https://github.com/easybuilders",', - ' "tag": "master",', + ' "tag": "main",', ' },', ' },', ' }),',