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 default branch instead of master #325

Merged
merged 1 commit into from
Oct 13, 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
8 changes: 6 additions & 2 deletions marge/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(self, *, api, user, project, repo, options):
def repo(self):
return self._repo

@property
def project(self):
return self._project

@property
def opts(self):
return self._options
Expand Down Expand Up @@ -345,8 +349,8 @@ def update_from_target_branch_and_push(
# A failure to clean up probably means something is fucked with the git repo
# and likely explains any previous failure, so it will better to just
# raise a GitError
if source_branch != 'master':
repo.checkout_branch('master')
if source_branch != self.project.default_branch:
repo.checkout_branch(self.project.default_branch)
repo.remove_branch(source_branch)

if not branch_update_done:
Expand Down
4 changes: 4 additions & 0 deletions marge/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def project_seems_ok(project_info):

return projects

@property
def default_branch(self):
return self.info['default_branch']

@property
def path_with_namespace(self):
return self.info['path_with_namespace']
Expand Down
1 change: 1 addition & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'path_with_namespace': 'cool/project',
'ssh_url_to_repo': 'ssh://blah.com/cool/project.git',
'merge_requests_enabled': True,
'default_branch': 'master',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use here the env variable CI_DEFAULT_BRANCH which is already provided by gitlab?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's provided both by the env var and by the API so potentially we could do either, but the existing code seems to prefer the API over env vars, so I stuck with that

'only_allow_merge_if_pipeline_succeeds': True,
'only_allow_merge_if_all_discussions_are_resolved': False,
'permissions': {
Expand Down