From 774f1c6c9446a81b46626efbaf794511ee12e456 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Thu, 8 Feb 2018 11:15:33 +0000 Subject: [PATCH 1/8] Add --config option to set base branch for submodules --- requirements.txt | 2 ++ scc/git.py | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9c9e5936..7eaa6b11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ yaclifw>=0.1.2 PyGithub +PyYAML +six diff --git a/scc/git.py b/scc/git.py index d899af7d..3e17d9b6 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", config=None): """ Register the git repository path, return the current status and register the GitHub origin remote. @@ -1027,6 +1029,14 @@ def __init__(self, gh, path, remote="origin"): # Register the remote [user_name, repo_name] = self.get_remote_info(remote) self.remote = remote + self.config = config + if self.config is not None and \ + isinstance(self.config, six.string_types): + self.dbg("Reading repository configuration from %s" % (config)) + self.config = yaml.load(file(self.config, 'rb').read()) + if self.config is not None: + self.dbg("Repository configuration:\n%s" % + (yaml.dump(self.config))) self.submodules = [] if gh: self.origin = gh.gh_repo(repo_name, user_name) @@ -1034,8 +1044,13 @@ def __init__(self, gh, path, remote="origin"): def register_submodules(self): if len(self.submodules) == 0: for directory in self.get_submodule_paths(): + config = None + if self.config is not None and \ + "submodules" in self.config and \ + directory in self.config["submodules"]: + config = self.config["submodules"][directory] try: - submodule_repo = self.gh.git_repo(directory) + submodule_repo = self.gh.git_repo(directory, config=config) self.submodules.append(submodule_repo) submodule_repo.register_submodules() finally: @@ -1736,8 +1751,14 @@ 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 "base-branch" in self.config: + self.log.info("Overriding base-branch from %s to %s" % + (filters["base"], + self.config["base-branch"])) + basebranch = self.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 +2065,8 @@ 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) + self.main_repo = self.gh.git_repo( + self.cwd, remote=args.remote, config=args.config) if not args.shallow: self.main_repo.register_submodules() if args.reset: @@ -3019,6 +3041,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( + '--config', + help='Configuration file (YAML)') self.add_new_commit_args() def get_action(self): From f2b43e989d51a42a1184e3f23e805b811a824b55 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Fri, 9 Feb 2018 12:37:02 +0000 Subject: [PATCH 2/8] Rename --config to --branch-config --- scc/git.py | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/scc/git.py b/scc/git.py index 3e17d9b6..cf8793cf 100755 --- a/scc/git.py +++ b/scc/git.py @@ -1007,7 +1007,7 @@ def find_candidate_branches(self, filters, class GitRepository(object): - def __init__(self, gh, path, remote="origin", config=None): + 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. @@ -1029,14 +1029,16 @@ def __init__(self, gh, path, remote="origin", config=None): # Register the remote [user_name, repo_name] = self.get_remote_info(remote) self.remote = remote - self.config = config - if self.config is not None and \ - isinstance(self.config, six.string_types): - self.dbg("Reading repository configuration from %s" % (config)) - self.config = yaml.load(file(self.config, 'rb').read()) - if self.config is not None: + 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.config))) + (yaml.dump(self.repository_config))) self.submodules = [] if gh: self.origin = gh.gh_repo(repo_name, user_name) @@ -1044,13 +1046,16 @@ def __init__(self, gh, path, remote="origin", config=None): def register_submodules(self): if len(self.submodules) == 0: for directory in self.get_submodule_paths(): - config = None - if self.config is not None and \ - "submodules" in self.config and \ - directory in self.config["submodules"]: - config = self.config["submodules"][directory] + 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, config=config) + submodule_repo = \ + self.gh.git_repo(directory, + repository_config=repository_config) self.submodules.append(submodule_repo) submodule_repo.register_submodules() finally: @@ -1752,11 +1757,11 @@ def rmerge(self, filters, info=False, comment=False, commit_id="merge", self.write_directories() presha1 = self.get_current_sha1() basebranch = filters["base"] - if "base-branch" in self.config: + if "base-branch" in self.repository_config: self.log.info("Overriding base-branch from %s to %s" % (filters["base"], - self.config["base-branch"])) - basebranch = self.config["base-branch"] + 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) @@ -2066,7 +2071,8 @@ def __init__(self, sub_parsers, **kwargs): def init_main_repo(self, args): self.main_repo = self.gh.git_repo( - self.cwd, remote=args.remote, config=args.config) + self.cwd, remote=args.remote, + repository_config=args.repository_config) if not args.shallow: self.main_repo.register_submodules() if args.reset: @@ -3042,8 +3048,8 @@ def __init__(self, sub_parsers): help='Set success/failure status on latest commits in all PRs ' 'in the merge.') self.parser.add_argument( - '--config', - help='Configuration file (YAML)') + '--repository-config', + help='Repository configuration file (YAML)') self.add_new_commit_args() def get_action(self): From bdf36571cbd87dac9188676af6f091365c519652 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Fri, 9 Feb 2018 14:45:17 +0000 Subject: [PATCH 3/8] Add PyYAML and six to setup.py dependencies --- setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 508706f8..7bb72524 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', + 'six'], entry_points={'console_scripts': ['scc = scc.main:entry_point']}, zip_safe=ZIP_SAFE, From b930f9d480948923a775a9f6a41900dbf7975cfc Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Fri, 9 Feb 2018 15:17:53 +0000 Subject: [PATCH 4/8] Pin PyYAML version for Python 2.6 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7eaa6b11..b5d6401a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ yaclifw>=0.1.2 PyGithub -PyYAML +PyYAML==3.11 six diff --git a/setup.py b/setup.py index 7bb72524..b7a9cedb 100755 --- a/setup.py +++ b/setup.py @@ -119,7 +119,7 @@ def run_tests(self): install_requires=['yaclifw>=0.1.2', 'PyGithub', 'argparse', - 'PyYAML', + 'PyYAML==3.11', 'six'], entry_points={'console_scripts': ['scc = scc.main:entry_point']}, zip_safe=ZIP_SAFE, From f06a5aa5e6875f1c297b7fb8d8c5919e534a59ef Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Mon, 12 Feb 2018 09:44:27 +0000 Subject: [PATCH 5/8] Require PyYAML 3.10 for Python 2.6 compatibility --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index b5d6401a..2dc6cb19 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ yaclifw>=0.1.2 PyGithub -PyYAML==3.11 +PyYAML==3.10 six diff --git a/setup.py b/setup.py index b7a9cedb..bee7c26e 100755 --- a/setup.py +++ b/setup.py @@ -119,7 +119,7 @@ def run_tests(self): install_requires=['yaclifw>=0.1.2', 'PyGithub', 'argparse', - 'PyYAML==3.11', + 'PyYAML==3.10', 'six'], entry_points={'console_scripts': ['scc = scc.main:entry_point']}, zip_safe=ZIP_SAFE, From 32ad886959ac1a95e7bcf972fc5350b48ca765e3 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Mon, 12 Feb 2018 10:39:52 +0000 Subject: [PATCH 6/8] Cope with null repository config --- scc/git.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scc/git.py b/scc/git.py index cf8793cf..2d8061fa 100755 --- a/scc/git.py +++ b/scc/git.py @@ -1757,7 +1757,8 @@ def rmerge(self, filters, info=False, comment=False, commit_id="merge", self.write_directories() presha1 = self.get_current_sha1() basebranch = filters["base"] - if "base-branch" in self.repository_config: + 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"])) From d637f1367f55c89de61ac06505b2ad25f4ca0551 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Mon, 12 Feb 2018 11:21:59 +0000 Subject: [PATCH 7/8] Handle non-existing argument --- scc/git.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scc/git.py b/scc/git.py index 2d8061fa..c492845a 100755 --- a/scc/git.py +++ b/scc/git.py @@ -2071,9 +2071,12 @@ def __init__(self, sub_parsers, **kwargs): self.add_remote_arg() def init_main_repo(self, args): + 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=args.repository_config) + repository_config=repository_config) if not args.shallow: self.main_repo.register_submodules() if args.reset: From 7e03c86783d60643fafefabd8e017424e941e56a Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Mon, 12 Feb 2018 12:09:18 +0000 Subject: [PATCH 8/8] Revert "Require PyYAML 3.10 for Python 2.6 compatibility" This reverts commit f06a5aa5e6875f1c297b7fb8d8c5919e534a59ef. --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2dc6cb19..b5d6401a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ yaclifw>=0.1.2 PyGithub -PyYAML==3.10 +PyYAML==3.11 six diff --git a/setup.py b/setup.py index bee7c26e..b7a9cedb 100755 --- a/setup.py +++ b/setup.py @@ -119,7 +119,7 @@ def run_tests(self): install_requires=['yaclifw>=0.1.2', 'PyGithub', 'argparse', - 'PyYAML==3.10', + 'PyYAML==3.11', 'six'], entry_points={'console_scripts': ['scc = scc.main:entry_point']}, zip_safe=ZIP_SAFE,