mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-03-23 18:03:39 +00:00
fix: handle errors on pkgbuild reading
This commit is contained in:
@@ -416,7 +416,7 @@ class Sources(LazyLogging):
|
||||
else:
|
||||
patch.write(sources_dir / "PKGBUILD")
|
||||
|
||||
def read(self, sources_dir: Path, commit_sha: str, path: Path) -> str:
|
||||
def read(self, sources_dir: Path, commit_sha: str, path: Path) -> str | None:
|
||||
"""
|
||||
read file content from the specified commit
|
||||
|
||||
@@ -426,6 +426,10 @@ class Sources(LazyLogging):
|
||||
path(Path): path to file inside the repository
|
||||
|
||||
Returns:
|
||||
str: file content at specified commit
|
||||
str | None: file content at specified commit if available
|
||||
"""
|
||||
return check_output(*self.git(), "show", f"{commit_sha}:{path}", cwd=sources_dir, logger=self.logger)
|
||||
try:
|
||||
return check_output(*self.git(), "show", f"{commit_sha}:{path}", cwd=sources_dir, logger=self.logger)
|
||||
except CalledProcessError:
|
||||
self.logger.exception("failed to read file %s at %s", path, commit_sha)
|
||||
return None
|
||||
|
||||
@@ -81,7 +81,7 @@ class ChangesOperations(Operations):
|
||||
values
|
||||
(:package_base, :last_commit_sha, :changes, :pkgbuild, :repository)
|
||||
on conflict (package_base, repository) do update set
|
||||
last_commit_sha = :last_commit_sha, changes = :changes, pkgbuild = :pkgbuild
|
||||
last_commit_sha = :last_commit_sha, changes = :changes, pkgbuild = coalesce(:pkgbuild, pkgbuild)
|
||||
""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
|
||||
@@ -605,3 +605,12 @@ def test_read(sources: Sources, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="content")
|
||||
assert sources.read(Path("local"), "sha", Path("PKGBUILD")) == "content"
|
||||
check_output_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_read_failed(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return None in case if file cannot be read from commit
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.check_output",
|
||||
side_effect=CalledProcessError(1, ["command"], "error"))
|
||||
assert sources.read(Path("local"), "sha", Path("PKGBUILD")) is None
|
||||
|
||||
@@ -53,3 +53,12 @@ def test_changes_insert_remove_full(database: SQLite, package_ahriman: Package,
|
||||
assert database.changes_get(package_ahriman.base).changes is None
|
||||
assert database.changes_get(package_python_schedule.base).changes is None
|
||||
assert database.changes_get(package_ahriman.base, RepositoryId("i686", database._repository_id.name)) == changes2
|
||||
|
||||
|
||||
def test_changes_insert_pkgbuild_preserve(database: SQLite, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must preserve existing pkgbuild when inserting changes without pkgbuild
|
||||
"""
|
||||
database.changes_insert(package_ahriman.base, Changes("sha1", "change1", "pkgbuild1"))
|
||||
database.changes_insert(package_ahriman.base, Changes("sha2", "change2", None))
|
||||
assert database.changes_get(package_ahriman.base) == Changes("sha2", "change2", "pkgbuild1")
|
||||
|
||||
Reference in New Issue
Block a user