diff --git a/requirements.txt b/requirements.txt index 9c9e5936..b5d6401a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ yaclifw>=0.1.2 PyGithub +PyYAML==3.11 +six diff --git a/scc/git.py b/scc/git.py index d899af7d..c492845a 100755 --- a/scc/git.py +++ b/scc/git.py @@ -32,6 +32,8 @@ import datetime import difflib import socket +import yaml +import six from ssl import SSLError from yaclifw.framework import Command, Stop @@ -1005,7 +1007,7 @@ def find_candidate_branches(self, filters, class GitRepository(object): - def __init__(self, gh, path, remote="origin"): + def __init__(self, gh, path, remote="origin", repository_config=None): """ Register the git repository path, return the current status and register the GitHub origin remote. @@ -1027,6 +1029,16 @@ def __init__(self, gh, path, remote="origin"): # Register the remote [user_name, repo_name] = self.get_remote_info(remote) self.remote = remote + self.repository_config = repository_config + if self.repository_config is not None and \ + isinstance(self.repository_config, six.string_types): + self.dbg("Reading repository configuration from %s" % + (repository_config)) + self.repository_config = yaml.load(file(self.repository_config, + 'rb').read()) + if self.repository_config is not None: + self.dbg("Repository configuration:\n%s" % + (yaml.dump(self.repository_config))) self.submodules = [] if gh: self.origin = gh.gh_repo(repo_name, user_name) @@ -1034,8 +1046,16 @@ def __init__(self, gh, path, remote="origin"): def register_submodules(self): if len(self.submodules) == 0: for directory in self.get_submodule_paths(): + repository_config = None + if self.repository_config is not None and \ + "submodules" in self.repository_config and \ + directory in self.repository_config["submodules"]: + repository_config = \ + self.repository_config["submodules"][directory] try: - submodule_repo = self.gh.git_repo(directory) + submodule_repo = \ + self.gh.git_repo(directory, + repository_config=repository_config) self.submodules.append(submodule_repo) submodule_repo.register_submodules() finally: @@ -1736,8 +1756,15 @@ def rmerge(self, filters, info=False, comment=False, commit_id="merge", self.cd(self.path) self.write_directories() presha1 = self.get_current_sha1() - if self.has_remote_branch(filters["base"], self.remote): - ff_msg, ff_log = self.fast_forward(filters["base"], + basebranch = filters["base"] + if self.repository_config is not None and \ + "base-branch" in self.repository_config: + self.log.info("Overriding base-branch from %s to %s" % + (filters["base"], + self.repository_config["base-branch"])) + basebranch = self.repository_config["base-branch"] + if self.has_remote_branch(basebranch, self.remote): + ff_msg, ff_log = self.fast_forward(basebranch, remote=self.remote) merge_msg += ff_msg # Scan the ff log to produce a digest of the merged PRs @@ -2044,7 +2071,12 @@ def __init__(self, sub_parsers, **kwargs): self.add_remote_arg() def init_main_repo(self, args): - self.main_repo = self.gh.git_repo(self.cwd, remote=args.remote) + repository_config = None + if hasattr(self, "repository_config"): + repository_config = self.repository_config + self.main_repo = self.gh.git_repo( + self.cwd, remote=args.remote, + repository_config=repository_config) if not args.shallow: self.main_repo.register_submodules() if args.reset: @@ -3019,6 +3051,9 @@ def __init__(self, sub_parsers): '--set-commit-status', action='store_true', help='Set success/failure status on latest commits in all PRs ' 'in the merge.') + self.parser.add_argument( + '--repository-config', + help='Repository configuration file (YAML)') self.add_new_commit_args() def get_action(self): diff --git a/setup.py b/setup.py index 508706f8..b7a9cedb 100755 --- a/setup.py +++ b/setup.py @@ -116,7 +116,11 @@ def run_tests(self): # More complex variables packages=['scc'], include_package_data=True, - install_requires=['yaclifw>=0.1.2', 'PyGithub', 'argparse'], + install_requires=['yaclifw>=0.1.2', + 'PyGithub', + 'argparse', + 'PyYAML==3.11', + 'six'], entry_points={'console_scripts': ['scc = scc.main:entry_point']}, zip_safe=ZIP_SAFE,