Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --repository-config option to set base branch for submodules #225

Merged
merged 8 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
yaclifw>=0.1.2
PyGithub
PyYAML==3.11
six
45 changes: 40 additions & 5 deletions scc/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import datetime
import difflib
import socket
import yaml
import six
from ssl import SSLError
from yaclifw.framework import Command, Stop

Expand Down Expand Up @@ -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.
Expand All @@ -1027,15 +1029,33 @@ 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)

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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down