mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-02 02:11:19 +08:00
Resolve the commit in the SCM.commit property method instead of the constructor
This will prevent the need to call `SCM.get_latest` in the constructor, since not all SCM objects need the commit to the branch. It also fixes the situation where a component's git repo doesn't have a "master" branch. See https://pagure.io/fm-orchestrator/issue/1224
This commit is contained in:
@@ -98,8 +98,6 @@ class SCM(object):
|
||||
self.name = self.name[:-4]
|
||||
self.commit = match.group("commit")
|
||||
self.branch = branch if branch else "master"
|
||||
if not self.commit:
|
||||
self.commit = self.get_latest(self.branch)
|
||||
self.version = None
|
||||
else:
|
||||
raise ValidationError("Unhandled SCM scheme: %s" % self.scheme)
|
||||
@@ -351,6 +349,9 @@ class SCM(object):
|
||||
@property
|
||||
def commit(self):
|
||||
"""The commit ID, for example the git hash, or None."""
|
||||
if not self._commit:
|
||||
self._commit = self.get_latest(self.branch)
|
||||
|
||||
return self._commit
|
||||
|
||||
@commit.setter
|
||||
|
||||
@@ -93,7 +93,10 @@ class TestSCMModule:
|
||||
|
||||
def test_verify_unknown_branch(self):
|
||||
with pytest.raises(UnprocessableEntity):
|
||||
module_build_service.scm.SCM(repo_url, "unknown")
|
||||
scm = module_build_service.scm.SCM(repo_url, "unknown")
|
||||
# Accessing the commit property will cause the commit to be resolved, causing an
|
||||
# exception
|
||||
scm.commit
|
||||
|
||||
def test_verify_commit_in_branch(self):
|
||||
target = "7035bd33614972ac66559ac1fdd019ff6027ad21"
|
||||
|
||||
Reference in New Issue
Block a user