-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix(worker): Update local and remote defaults to main branch #2738
Conversation
ses = Github(DATALAD_GITHUB_TOKEN) | ||
org = ses.get_organization(DATALAD_GITHUB_ORG) | ||
repo = org.get_repo(dataset_id) | ||
repo.edit(default_branch="main", description="OpenNeuro dataset", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it reasonably un-clunky to put the dataset name here? That would make the listing in https://github.com/OpenNeuroDatasets much more informative.
repo.edit(default_branch="main", description="OpenNeuro dataset", | |
repo.edit(default_branch="main", description=f"OpenNeuro dataset {dataset_id}: {description['Name']}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As part of the changes for metadata tagging on GitHub I was planning on loading some information from OpenNeuro's API service and updating it here.
That said, we could just read the dataset_description.json inline here and use the name from that if it exists, not sure how soon we'll get back to those GitHub metadata changes with other priorities.
41e412c
to
6949383
Compare
# Make sure the main branch is used, update if needed | ||
master_branch = repo.branches.get('master') | ||
if master_branch: | ||
main_branch = master_branch.rename('main', True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance there's a dataset with both master
and main
? It looks like Branch.rename(force=True)
will clobber, but if both are present, are we confident that master
is authoritative and not main
? I could imagine a situation where someone with git access pushes a stale master
branch to a dataset that's had master
renamed to main
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now there are no main branch datasets and OpenNeuro cannot edit them without these fixes. Maybe instead we block master for new pushes? I could add that here.
# Make sure the main branch is used, update if needed | ||
master_branch = repo.branches.get('master') | ||
if master_branch: | ||
main_branch = master_branch.rename('main', True) | ||
# Abort the commit if this didn't work | ||
if not main_branch.is_head(): | ||
raise Exception('Unable to rename master branch to main') | ||
# Always update the symbolic reference for HEAD | ||
repo.references['HEAD'].set_target('refs/heads/main') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of this?
# Make sure the main branch is used, update if needed | |
master_branch = repo.branches.get('master') | |
if master_branch: | |
main_branch = master_branch.rename('main', True) | |
# Abort the commit if this didn't work | |
if not main_branch.is_head(): | |
raise Exception('Unable to rename master branch to main') | |
# Always update the symbolic reference for HEAD | |
repo.references['HEAD'].set_target('refs/heads/main') | |
HEAD = repo.references["HEAD"] | |
# Make sure the main branch is used, update if needed | |
if HEAD.target == "refs/heads/master": | |
main_branch = repo.branches.get('master').rename('main', True) | |
# Abort the commit if this didn't work | |
if not main_branch.is_head(): | |
raise Exception('Unable to rename master branch to main') | |
# Always update the symbolic reference for HEAD | |
HEAD.set_target('refs/heads/main') | |
# Remove master if it's still around | |
if "master" in repo.branches: | |
repo.branches["master"].delete() |
Okay, adding two more test cases:
One more fix:
|
…invalid symbolic HEAD ref
8f02133
to
db19a45
Compare
Codecov Report
@@ Coverage Diff @@
## master #2738 +/- ##
==========================================
- Coverage 75.89% 75.88% -0.01%
==========================================
Files 411 411
Lines 67157 67193 +36
Branches 2041 2041
==========================================
+ Hits 50967 50991 +24
- Misses 16139 16151 +12
Partials 51 51
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This updates some mismatched master branch usage to always use main.