1- from __future__ import annotations
2-
3- from voluptuous .error import Invalid
4- from voluptuous .humanize import humanize_error
5-
6- from ..enums import HacsCategory , RepositoryFile
7- from ..repositories .base import HacsManifest , HacsRepository
8- from ..utils .validate import HACS_MANIFEST_JSON_SCHEMA
9- from .base import ActionValidationBase , ValidationException
10-
11-
12- async def async_setup_validator (repository : HacsRepository ) -> Validator :
13- """Set up this validator."""
14- return Validator (repository = repository )
15-
16-
17- class Validator (ActionValidationBase ):
18- """Validate the repository."""
19-
20- more_info = "https://hacs.xyz/docs/publish/include#check-hacs-manifest"
21-
22- async def async_validate (self ) -> None :
23- """Validate the repository."""
24- if RepositoryFile .HACS_JSON not in [x .filename for x in self .repository .tree ]:
25- raise ValidationException (f"The repository has no '{ RepositoryFile .HACS_JSON } ' file" )
26-
27- rawhacsjson = await self .repository .get_hacs_json_raw (version = self .repository .ref )
28- if rawhacsjson is None :
29- raise ValidationException (
30- f"The repository has an invalid '{ RepositoryFile .HACS_JSON } ' file"
31- )
32-
33- try :
34- hacsjson = HacsManifest .from_dict (HACS_MANIFEST_JSON_SCHEMA (rawhacsjson ))
35- except Invalid as exception :
36- self .repository .logger .warning (
37- "HACS JSON validation failed for: %s" ,
38- rawhacsjson ,
39- )
40- raise ValidationException (humanize_error (rawhacsjson , exception )) from exception
41-
42- if self .repository .data .category == HacsCategory .INTEGRATION :
43- if hacsjson .zip_release and not hacsjson .filename :
44- raise ValidationException ("zip_release is True, but filename is not set" )
1+ from __future__ import annotations
2+
3+ from voluptuous .error import Invalid
4+ from voluptuous .humanize import humanize_error
5+
6+ from ..enums import HacsCategory , RepositoryFile
7+ from ..repositories .base import HacsManifest , HacsRepository
8+ from ..utils .validate import HACS_MANIFEST_JSON_SCHEMA
9+ from .base import ActionValidationBase , ValidationException
10+
11+
12+ async def async_setup_validator (repository : HacsRepository ) -> Validator :
13+ """Set up this validator."""
14+ return Validator (repository = repository )
15+
16+
17+ class Validator (ActionValidationBase ):
18+ """Validate the repository."""
19+
20+ more_info = "https://hacs.xyz/docs/publish/include#check-hacs-manifest"
21+
22+ async def async_validate (self ) -> None :
23+ """Validate the repository."""
24+ if RepositoryFile .HACS_JSON not in [x .filename for x in self .repository .tree ]:
25+ raise ValidationException (f"The repository has no '{ RepositoryFile .HACS_JSON } ' file" )
26+
27+ rawhacsjson = await self .repository .get_hacs_json_raw (version = self .repository .ref )
28+ if rawhacsjson is None :
29+ raise ValidationException (
30+ f"The repository has an invalid '{ RepositoryFile .HACS_JSON } ' file"
31+ )
32+
33+ try :
34+ hacsjson = HacsManifest .from_dict (HACS_MANIFEST_JSON_SCHEMA (rawhacsjson ))
35+ except Invalid as exception :
36+ self .repository .logger .warning (
37+ "HACS JSON validation failed for: %s" ,
38+ rawhacsjson ,
39+ )
40+ raise ValidationException (humanize_error (rawhacsjson , exception )) from exception
41+
42+ if self .repository .data .category == HacsCategory .INTEGRATION :
43+ if hacsjson .zip_release and not hacsjson .filename :
44+ raise ValidationException ("zip_release is True, but filename is not set" )
45+
46+ # Validate supported_languages if provided
47+ if hacsjson .supported_languages :
48+ # Check if README files for declared languages exist
49+ tree_files = [x .filename for x in self .repository .tree ]
50+ missing_readmes = []
51+ for lang in hacsjson .supported_languages :
52+ readme_path = f"README.{ lang } .md"
53+ # Check various case combinations
54+ found = False
55+ for possible_path in [
56+ readme_path ,
57+ f"README.{ lang .upper ()} .md" ,
58+ f"readme.{ lang } .md" ,
59+ f"readme.{ lang .upper ()} .md" ,
60+ ]:
61+ if possible_path in tree_files :
62+ found = True
63+ break
64+ if not found :
65+ missing_readmes .append (lang )
66+
67+ if missing_readmes :
68+ raise ValidationException (
69+ f"supported_languages declares languages { missing_readmes } , "
70+ f"but corresponding README files (README.{{lang}}.md) were not found in the repository."
71+ )
0 commit comments