Skip to content

Commit

Permalink
Add a linear_fake_merge option (defaulting to True)
Browse files Browse the repository at this point in the history
One of my projects (projectatomic/rpm-ostree) has a protected master
branch.  I was rather horrified to realize that homu force-pushes to
master by default.  Admittedly, I understand this is the only way to
make github think the PR was merged (as opposed to just closed).

But in my mind, that's a deficiency of github - it should have an API
to allow us to "close merged with this commit".

Anyways, add an option so that those who prefer closed over force
pushing can do that today.

We at least retitle the commit so that it's more clear it was merged.
  • Loading branch information
cgwalters committed Mar 16, 2016
1 parent 2104e4b commit 93067ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cfg.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ try_users = []
# Auto-squash commits. Requires the local Git command
#autosquash = true

# Whether homu should push a temporary merge commit that causes
# github to think the PR was merged. You need to disable this if
# you have branch protection enabled. Also, leaving this enabled
# means that other people pulling master might transiently see
# the merge commit.
#linear_fake_merge = true

## branch names (these settings here are the defaults)
#[repo.NAME.branch]
#
Expand Down
17 changes: 16 additions & 1 deletion homu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ def refresh(self):
self.body = issue.body

def fake_merge(self, repo_cfg):
if repo_cfg.get('linear', False) or repo_cfg.get('autosquash', False):
is_linear_or_autosquash = repo_cfg.get('linear', False) or repo_cfg.get('autosquash', False)
# Backwards compat, though I think this is a terrible default.
fake_merge = repo_cfg.get('linear_fake_merge', True)
if not is_linear_or_autosquash:
return
if fake_merge:
msg = '''!!! Temporary commit !!!
This commit is artifically made up to mark PR {} as merged.
Expand All @@ -238,6 +243,16 @@ def fail(err):
self.get_issue().close()

utils.retry_until(inner, fail, self)
else:
issue = self.get_issue()
title = issue.title
# So unfortunately, we can't yet tell github this PR was
# merged. We need to rework things so that our last
# comment at least includes a link to the master commit.
merged_prefix = '[merged] '
if not title.startswith(merged_prefix):
title = merged_prefix + title
issue.edit(title=title, state='closed')

def sha_cmp(short, full):
return len(short) >= 4 and short == full[:len(short)]
Expand Down

0 comments on commit 93067ad

Please sign in to comment.