Change read_recipe_commit to use the recipe name
Callers really shouldn't need to know the details of the filenames, so change it to convert it internally.
This commit is contained in:
parent
ab6decec0b
commit
639d325a0c
@ -292,15 +292,15 @@ def read_commit(repo, branch, filename, commit=None):
|
||||
"""
|
||||
return read_commit_spec(repo, "%s:%s" % (commit or branch, filename))
|
||||
|
||||
def read_recipe_commit(repo, branch, filename, commit=None):
|
||||
def read_recipe_commit(repo, branch, recipe_name, commit=None):
|
||||
"""Read a recipe commit from git and return a Recipe object
|
||||
|
||||
:param repo: Open repository
|
||||
:type repo: Git.Repository
|
||||
:param branch: Branch name
|
||||
:type branch: str
|
||||
:param filename: filename to read
|
||||
:type filename: str
|
||||
:param recipe_name: Recipe name to read
|
||||
:type recipe_name: str
|
||||
:param commit: Optional commit hash
|
||||
:type commit: str
|
||||
:returns: A Recipe object
|
||||
@ -310,7 +310,7 @@ def read_recipe_commit(repo, branch, filename, commit=None):
|
||||
If no commit is passed the master:filename is returned, otherwise it will be
|
||||
commit:filename
|
||||
"""
|
||||
recipe_toml = read_commit(repo, branch, filename, commit)
|
||||
recipe_toml = read_commit(repo, branch, recipe_filename(recipe_name), commit)
|
||||
return recipe_from_toml(recipe_toml)
|
||||
|
||||
def list_branch_files(repo, branch):
|
||||
@ -441,7 +441,7 @@ def commit_recipe(repo, branch, recipe):
|
||||
:raises: Can raise errors from Ggit
|
||||
"""
|
||||
try:
|
||||
old_recipe = read_recipe_commit(repo, branch, recipe.filename)
|
||||
old_recipe = read_recipe_commit(repo, branch, recipe["name"])
|
||||
old_version = old_recipe["version"]
|
||||
except Exception:
|
||||
old_version = None
|
||||
|
@ -75,7 +75,6 @@ def v0_api(api):
|
||||
errors = []
|
||||
for recipe_name in [n.strip() for n in recipe_names.split(",")]:
|
||||
exceptions = []
|
||||
filename = recipe_filename(recipe_name)
|
||||
# Get the workspace version (if it exists)
|
||||
try:
|
||||
with api.config["GITLOCK"].lock:
|
||||
@ -87,7 +86,7 @@ def v0_api(api):
|
||||
# Get the git version (if it exists)
|
||||
try:
|
||||
with api.config["GITLOCK"].lock:
|
||||
git_recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", filename)
|
||||
git_recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe_name)
|
||||
except Exception as e:
|
||||
git_recipe = None
|
||||
exceptions.append(str(e))
|
||||
@ -157,7 +156,7 @@ def v0_api(api):
|
||||
commit_recipe(api.config["GITLOCK"].repo, "master", recipe)
|
||||
|
||||
# Read the recipe with new version and write it to the workspace
|
||||
recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe.filename)
|
||||
recipe = read_recipe_commit(api.config["GITLOCK"].repo, "master", recipe["name"])
|
||||
workspace_write(api.config["GITLOCK"].repo, "master", recipe)
|
||||
except Exception as e:
|
||||
return jsonify(status=False, error={"msg":str(e)}), 400
|
||||
|
@ -151,12 +151,12 @@ class GitRecipesTest(unittest.TestCase):
|
||||
commits = recipes.list_commits(self.repo, "master", "http-server.toml")
|
||||
self.assertEqual(len(commits), 1, "Wrong number of commits: %s" % commits)
|
||||
|
||||
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml")
|
||||
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server")
|
||||
self.assertNotEqual(recipe, None)
|
||||
self.assertEqual(recipe["name"], "http-server")
|
||||
|
||||
# Read by commit id
|
||||
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml", commits[0].commit)
|
||||
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server", commits[0].commit)
|
||||
self.assertNotEqual(recipe, None)
|
||||
self.assertEqual(recipe["name"], "http-server")
|
||||
|
||||
@ -193,7 +193,7 @@ class GitRecipesTest(unittest.TestCase):
|
||||
|
||||
def test_10_tag_new_commit(self):
|
||||
"""Test tagging a newer commit of a recipe"""
|
||||
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server.toml")
|
||||
recipe = recipes.read_recipe_commit(self.repo, "master", "http-server")
|
||||
recipe["description"] = "A modified description"
|
||||
oid = recipes.commit_recipe(self.repo, "master", recipe)
|
||||
self.assertNotEqual(oid, None)
|
||||
|
Loading…
Reference in New Issue
Block a user