Skip to content

Commit

Permalink
Add a pre execution hook option
Browse files Browse the repository at this point in the history
Such a script will be launched before merge request processing.
Typically we want to refresh the config file with a up-to-date project list.

e.g: git -C /home/ubuntu/.config/pmr pull
  • Loading branch information
yphus committed Sep 28, 2016
1 parent fc7d807 commit cc2539d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions process-merge-requests
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def get_branch_merge_proposal_number(branch_merge_proposal):
return int(branch_merge_proposal.self_link.rsplit('/', 1)[-1])


def sh(*args):
def sh(*args, **kwargs):
"""Run an external command (without invoking the shell)."""
_logger.info("$ %s", ' '.join([shlex.quote(arg) for arg in args]))
return subprocess.check_call(args)
return subprocess.check_call(args, **kwargs)


def do_post_merge_tests(dirname):
Expand Down Expand Up @@ -322,6 +322,8 @@ def main():
help="Specify launchpad user id", metavar="USER")
parser.add_argument("--credentials",
help="Specify launchpad credentials", metavar="CRED")
parser.add_argument("--pre_exec",
help="Specify a pre-merge hook", metavar="FILE")
ns = parser.parse_args()
_logger.info(_("Logging into launchpad.net"))
lp = Launchpad.login_with(
Expand All @@ -331,6 +333,12 @@ def main():
try:
while True:
projects = []
if ns.pre_exec:
if not os.path.exists(ns.pre_exec):
_logger.warning(_("Pre-merge hook script not found"))
else:
with open(os.devnull, 'wb') as DEVNULL:
sh(ns.pre_exec, stdout=DEVNULL)
if ns.conf_file:
config = ConfigParser.ConfigParser()
config.read(ns.conf_file)
Expand Down

0 comments on commit cc2539d

Please sign in to comment.