mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 11:48:33 +08:00
Merge #262 Inherit the SCM repository from the parent module to included modules.
This commit is contained in:
@@ -79,6 +79,7 @@ class SCM(object):
|
||||
match = re.search(r"^(?P<repository>.*/(?P<name>[^?]*))(\?#(?P<commit>.*))?", url)
|
||||
self.repository = match.group("repository")
|
||||
self.name = match.group("name")
|
||||
self.repository_root = self.repository[:-len(self.name)]
|
||||
if self.name.endswith(".git"):
|
||||
self.name = self.name[:-4]
|
||||
self.commit = match.group("commit")
|
||||
@@ -87,6 +88,16 @@ class SCM(object):
|
||||
else:
|
||||
raise ValidationError("Unhandled SCM scheme: %s" % self.scheme)
|
||||
|
||||
def scm_url_from_name(self, name):
|
||||
"""
|
||||
Generates new SCM URL for another module defined by a name. The new URL
|
||||
is based on the root of current SCM URL.
|
||||
"""
|
||||
if self.scheme == "git":
|
||||
return self.repository_root + name + ".git"
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
@module_build_service.utils.retry(wait_on=RuntimeError)
|
||||
def _run(cmd, chdir=None):
|
||||
|
||||
@@ -260,9 +260,22 @@ def _fetch_mmd(url, allow_local_url = False):
|
||||
except Exception as e:
|
||||
log.error('Invalid modulemd: %s' % str(e))
|
||||
raise UnprocessableEntity('Invalid modulemd: %s' % str(e))
|
||||
|
||||
# If undefined, set the name field to VCS repo name.
|
||||
if not mmd.name and scm:
|
||||
mmd.name = scm.name
|
||||
|
||||
# If undefined, set the stream field to the VCS branch name.
|
||||
if not mmd.stream and scm:
|
||||
mmd.stream = scm.branch
|
||||
|
||||
# If undefined, set the version field to int represenation of VCS commit.
|
||||
if not mmd.version and scm:
|
||||
mmd.version = int(scm.version)
|
||||
|
||||
return mmd, scm, yaml
|
||||
|
||||
def record_component_builds(mmd, module, initial_batch = 1):
|
||||
def record_component_builds(scm, mmd, module, initial_batch = 1):
|
||||
# Import it here, because SCM uses utils methods
|
||||
# and fails to import them because of dep-chain.
|
||||
import module_build_service.scm
|
||||
@@ -333,9 +346,11 @@ def record_component_builds(mmd, module, initial_batch = 1):
|
||||
# set to our current batch, so the components of this module
|
||||
# are built in the right global order.
|
||||
if isinstance(pkg, modulemd.ModuleComponentModule):
|
||||
if not pkg.repository:
|
||||
pkg.repository = scm.scm_url_from_name(pkg.name)
|
||||
full_url = pkg.repository + "?#" + pkg.ref
|
||||
mmd = _fetch_mmd(full_url)[0]
|
||||
batch = record_component_builds(mmd, module, batch)
|
||||
batch = record_component_builds(scm, mmd, module, batch)
|
||||
continue
|
||||
|
||||
if previous_buildorder != pkg.buildorder:
|
||||
@@ -370,18 +385,6 @@ def submit_module_build(username, url, allow_local_url = False):
|
||||
|
||||
mmd, scm, yaml = _fetch_mmd(url, allow_local_url)
|
||||
|
||||
# If undefined, set the name field to VCS repo name.
|
||||
if not mmd.name and scm:
|
||||
mmd.name = scm.name
|
||||
|
||||
# If undefined, set the stream field to the VCS branch name.
|
||||
if not mmd.stream and scm:
|
||||
mmd.stream = scm.branch
|
||||
|
||||
# If undefined, set the version field to int represenation of VCS commit.
|
||||
if not mmd.version and scm:
|
||||
mmd.version = int(scm.version)
|
||||
|
||||
module = models.ModuleBuild.query.filter_by(name=mmd.name,
|
||||
stream=mmd.stream,
|
||||
version=mmd.version).first()
|
||||
@@ -414,7 +417,7 @@ def submit_module_build(username, url, allow_local_url = False):
|
||||
username=username
|
||||
)
|
||||
|
||||
record_component_builds(mmd, module)
|
||||
record_component_builds(scm, mmd, module)
|
||||
|
||||
module.modulemd = mmd.dumps()
|
||||
module.transition(conf, models.BUILD_STATES["wait"])
|
||||
|
||||
@@ -57,6 +57,7 @@ class MockedSCM(object):
|
||||
self.mocked_scm.return_value.checkout = self.checkout
|
||||
self.mocked_scm.return_value.name = self.name
|
||||
self.mocked_scm.return_value.get_latest = self.get_latest
|
||||
self.mocked_scm.return_value.repository_root = "git://pkgs.stg.fedoraproject.org/modules/"
|
||||
|
||||
def checkout(self, temp_dir):
|
||||
scm_dir = path.join(temp_dir, self.name)
|
||||
|
||||
@@ -31,6 +31,7 @@ import modulemd as _modulemd
|
||||
|
||||
from tests import app, init_data
|
||||
from module_build_service.models import ComponentBuild
|
||||
import module_build_service.scm
|
||||
|
||||
class MockedSCM(object):
|
||||
def __init__(self, mocked_scm, name, mmd_filenames):
|
||||
@@ -52,6 +53,7 @@ class MockedSCM(object):
|
||||
self.mocked_scm.return_value.checkout = self.checkout
|
||||
self.mocked_scm.return_value.name = self.name
|
||||
self.mocked_scm.return_value.get_latest = self.get_latest
|
||||
self.mocked_scm.return_value.repository_root = "git://pkgs.stg.fedoraproject.org/modules/"
|
||||
|
||||
def checkout(self, temp_dir):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user