Skip to content

Commit

Permalink
Use the .mergify.yml from PR
Browse files Browse the repository at this point in the history
When a PR on the default branch change .mergify.yml, we must
use that one instead. So configuration and testing will report
useful information.

Closes #24
  • Loading branch information
sileht committed May 5, 2018
1 parent d2ac1e7 commit 74c6856
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions mergify_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def handle(self, event_type, data):
# BRANCH CONFIGURATION CHECKING
branch_rule = None
try:
branch_rule = rules.get_branch_rule(
self._r, incoming_pull.base.ref)
branch_rule = rules.get_branch_rule(self._r, incoming_pull)
except rules.NoRules as e:
# Not configured, post status check with the error message
incoming_pull.mergify_engine_github_post_check_status(
Expand Down
15 changes: 12 additions & 3 deletions mergify_engine/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,21 @@ def dict_merge(dct, merge_dct):
dct[k] = merge_dct[k]


def get_branch_rule(g_repo, branch):
# TODO(sileht): Ensure the file is valid
def get_branch_rule(g_repo, incoming_pull):
rule = copy.deepcopy(DEFAULT_RULE)

branch = incoming_pull.base.ref

ref = github.GithubObject.NotSet
if g_repo.default_branch == branch:
# NOTE(sileht): If the PR on the default branch change the .mergify.yml
# we use it, otherwise we the file on the default branch
for f in incoming_pull.get_files():
if f.filename == ".mergify.yml":
ref = f.contents_url.split("?ref=")[1]

try:
content = g_repo.get_contents(".mergify.yml").decoded_content
content = g_repo.get_contents(".mergify.yml", ref=ref).decoded_content
LOG.info("found mergify.yml")
except github.UnknownObjectException:
raise NoRules(".mergify.yml is missing")
Expand Down

0 comments on commit 74c6856

Please sign in to comment.