Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use 'main' rather than 'master' branch in GitHub integration functionality #3589

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
21 changes: 12 additions & 9 deletions test/framework/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
GITHUB_USER = "easybuilders"
GITHUB_REPO = "testrepository"
# branch to test
GITHUB_BRANCH = 'master'
GITHUB_BRANCH = 'main'


class GithubTest(EnhancedTestCase):
Expand All @@ -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

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -634,7 +637,7 @@ def run_check(expected_result=False):

pr_data = {
'base': {
'ref': 'master',
'ref': 'main',
'repo': {
'name': 'easybuild-easyconfigs',
'owner': {'login': 'easybuilders'},
Expand All @@ -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'
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4103,17 +4103,17 @@ 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',
])
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)
Expand Down
2 changes: 1 addition & 1 deletion test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",',
' },',
' },',
' }),',
Expand Down