Skip to content

Commit c5763f7

Browse files
committed
feat: add YAML and traditional checksum file support
- Implemented YAML checksum file parsing with Base64 to hex conversion. - Enhanced traditional checksum file parsing with improved format detection. - Added priority handling for YAML files over traditional checksum files. - Updated VerificationService to auto-detect checksum files from assets. - Improved test coverage for checksum file detection and parsing. - Maintained backward compatibility with existing verification logic.
1 parent 5a98bd6 commit c5763f7

14 files changed

+2311
-575
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## v1.3.0-alpha
45
## v1.2.0-alpha
56
### CHANGES
67
This release implement new icon extraction feature and implement new verfication service.

my_unicorn/github_client.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
information, extract AppImage assets, and manage GitHub-specific operations.
55
"""
66

7+
import re
8+
from dataclasses import dataclass
79
from typing import Any, TypedDict, cast
810
from urllib.parse import urlparse
911

@@ -28,9 +30,36 @@ class GitHubReleaseDetails(TypedDict):
2830
assets: list[GitHubAsset]
2931

3032

33+
@dataclass(slots=True, frozen=True)
34+
class ChecksumFileInfo:
35+
"""Information about detected checksum file."""
36+
37+
filename: str
38+
url: str
39+
format_type: str # 'yaml' or 'traditional'
40+
41+
3142
class GitHubReleaseFetcher:
3243
"""Fetches GitHub release information and extracts AppImage assets."""
3344

45+
# Common checksum file patterns to look for in GitHub releases
46+
CHECKSUM_FILE_PATTERNS = [
47+
r"latest-.*\.yml$",
48+
r"latest-.*\.yaml$",
49+
r".*checksums?\.txt$",
50+
r".*checksums?\.yml$",
51+
r".*checksums?\.yaml$",
52+
r".*checksums?\.md5$",
53+
r".*checksums?\.sha1$",
54+
r".*checksums?\.sha256$",
55+
r".*checksums?\.sha512$",
56+
r"SHA\d+SUMS?(\.txt)?$",
57+
r"MD5SUMS?(\.txt)?$",
58+
r".*\.sum$",
59+
r".*\.hash$",
60+
r".*\.digest$",
61+
]
62+
3463
def __init__(self, owner: str, repo: str, session: aiohttp.ClientSession) -> None:
3564
"""Initialize the GitHub release fetcher.
3665
@@ -70,6 +99,48 @@ def _normalize_version(self, tag_name: str) -> str:
7099

71100
return normalized
72101

102+
@staticmethod
103+
def detect_checksum_files(
104+
assets: list[GitHubAsset],
105+
tag_name: str,
106+
) -> list[ChecksumFileInfo]:
107+
"""Detect checksum files in GitHub release assets.
108+
109+
Args:
110+
assets: List of GitHub release assets
111+
tag_name: Release tag name
112+
113+
Returns:
114+
List of detected checksum files with their info
115+
116+
"""
117+
checksum_files = []
118+
119+
for asset in assets:
120+
asset_name = asset["name"]
121+
122+
# Check if asset matches any checksum file pattern
123+
for pattern in GitHubReleaseFetcher.CHECKSUM_FILE_PATTERNS:
124+
if re.search(pattern, asset_name, re.IGNORECASE):
125+
url = asset["browser_download_url"]
126+
127+
# Determine format type
128+
format_type = (
129+
"yaml"
130+
if asset_name.lower().endswith((".yml", ".yaml"))
131+
else "traditional"
132+
)
133+
134+
checksum_files.append(
135+
ChecksumFileInfo(filename=asset_name, url=url, format_type=format_type)
136+
)
137+
break
138+
139+
# Prioritize YAML files (like latest-linux.yml) first as they're often more reliable
140+
checksum_files.sort(key=lambda x: (x.format_type != "yaml", x.filename))
141+
142+
return checksum_files
143+
73144
async def fetch_latest_release(self) -> GitHubReleaseDetails:
74145
"""Fetch the latest release information from GitHub API.
75146

my_unicorn/services/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Shared services package for eliminating code duplication."""
22

3+
from my_unicorn.github_client import ChecksumFileInfo
34
from .icon_service import IconConfig, IconResult, IconService
45
from .verification_service import VerificationConfig, VerificationResult, VerificationService
56

67
__all__ = [
8+
"ChecksumFileInfo",
79
"IconConfig",
810
"IconResult",
911
"IconService",

0 commit comments

Comments
 (0)