Skip to content

Commit

Permalink
flathub_json: Implement for builddir
Browse files Browse the repository at this point in the history
  • Loading branch information
barthalion committed Sep 27, 2023
1 parent 2bd2360 commit c1d76dd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
37 changes: 35 additions & 2 deletions flatpak_builder_lint/checks/flathub_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import json
import os
from typing import Set

from .. import builddir
from . import Check


Expand All @@ -18,7 +21,7 @@ def _check_if_extra_data(self, modules: list) -> bool:

return False

def validate(
def _validate(
self, appid: str, flathub_json: dict, is_extra_data: bool, is_extension: bool
) -> None:
if flathub_json.get("skip-appstream-check"):
Expand Down Expand Up @@ -76,4 +79,34 @@ def check_manifest(self, manifest: dict) -> None:

is_extension = manifest.get("build-extension", False)

self.validate(appid, flathub_json, is_extra_data, is_extension)
self._validate(appid, flathub_json, is_extra_data, is_extension)

def _check_metadata(self, metadata: dict, flathub_json: dict) -> None:
appid = metadata.get("name")
if not appid:
return

is_extra_data = bool(metadata.get("extra-data", False))
is_extension = metadata.get("type", False) != "application"
print(is_extra_data, is_extension)

self._validate(appid, flathub_json, is_extra_data, is_extension)

def check_build(self, path: str) -> None:
metadata = builddir.get_metadata(path)
if not metadata:
return

flathub_json_path = f"{path}/files/manifest.json"
if not os.path.exists(flathub_json_path):
return

with open(flathub_json_path, "r") as f:
flathub_json = json.load(f)
flathub_json = flathub_json.get("x-flathub")

flathub_json_path = f"{path}/files/manifest.json"
if not os.path.exists(flathub_json_path):
return

self._check_metadata(metadata, flathub_json)
9 changes: 9 additions & 0 deletions tests/builddir/flathub_json/files/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"x-flathub": {
"skip-appstream-check": "true",
"end-of-life": "message",
"end-of-life-rebase": "foo",
"publish-delay-hours": 2,
"only-arches": ["x86_64", "i386"]
}
}
2 changes: 2 additions & 0 deletions tests/builddir/flathub_json/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Application]
name=org.flathub.flathub_json
17 changes: 17 additions & 0 deletions tests/test_builddir.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,20 @@ def test_builddir_finish_args_missing() -> None:
ret = run_checks("tests/builddir/finish_args_missing")
found_errors = set(ret["errors"])
assert "finish-args-not-defined" in found_errors


def test_builddir_flathub_json() -> None:
errors = {
"flathub-json-skip-appstream-check",
"flathub-json-eol-rebase-misses-new-id",
"flathub-json-modified-publish-delay",
}

warnings = {"flathub-json-deprecated-i386-arch-included"}

ret = run_checks("tests/builddir/flathub_json")
found_errors = set(ret["errors"])
found_warnings = set(ret["warnings"])

assert errors.issubset(found_errors)
assert warnings.issubset(found_warnings)

0 comments on commit c1d76dd

Please sign in to comment.