Skip to content

Commit b118883

Browse files
julienldclaude
andauthored
fix: fetch Core release notes from GitHub releases API (#228)
When ha_get_release_notes fails to get release notes via WebSocket and the release_url is not a GitHub URL (like for Core which uses blog URLs), this change: 1. For Core update entities, fetches release notes directly from GitHub API: https://api.github.com/repos/home-assistant/core/releases/tags/{version} 2. When release notes are unavailable, includes the release_url in the error message so users can view them manually Closes #187 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9eabf46 commit b118883

2 files changed

Lines changed: 76 additions & 3 deletions

File tree

src/ha_mcp/tools/tools_updates.py

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,32 @@ async def ha_get_release_notes(
226226
"title": attributes.get("title", entity_id),
227227
}
228228

229-
# No release notes available
229+
# Special handling for Home Assistant Core updates
230+
# Core uses blog URLs for release_url, so we need to fetch from GitHub directly
231+
if "core" in entity_id.lower():
232+
core_result = await _fetch_core_release_notes(latest_version)
233+
if core_result:
234+
return {
235+
"success": True,
236+
"entity_id": entity_id,
237+
"version": latest_version,
238+
"release_notes": core_result["notes"],
239+
"source": core_result["source"],
240+
"release_url": release_url,
241+
"title": attributes.get("title", entity_id),
242+
}
243+
244+
# No release notes available - include helpful message with release_url
245+
message = "No release notes available for this update"
246+
if release_url:
247+
message = f"Release notes could not be fetched automatically. You can view them at: {release_url}"
248+
230249
return {
231250
"success": True,
232251
"entity_id": entity_id,
233252
"version": latest_version,
234253
"release_notes": None,
235-
"message": "No release notes available for this update",
254+
"message": message,
236255
"release_url": release_url,
237256
"title": attributes.get("title", entity_id),
238257
}
@@ -482,3 +501,57 @@ async def _fetch_github_release_notes(release_url: str) -> dict[str, str] | None
482501
except Exception as e:
483502
logger.debug(f"Failed to fetch GitHub release notes: {e}")
484503
return None
504+
505+
506+
async def _fetch_core_release_notes(version: str) -> dict[str, str] | None:
507+
"""
508+
Fetch release notes for Home Assistant Core from GitHub releases API.
509+
510+
Home Assistant Core uses blog URLs for release_url which don't contain
511+
the actual release notes. This function fetches directly from GitHub
512+
releases using the version tag.
513+
514+
Args:
515+
version: The version string (e.g., "2025.11.3")
516+
517+
Returns:
518+
Dictionary with 'notes' and 'source' keys, or None if fetch fails
519+
"""
520+
try:
521+
async with httpx.AsyncClient(timeout=15.0) as http_client:
522+
# GitHub API URL for Home Assistant Core releases
523+
api_url = f"https://api.github.com/repos/home-assistant/core/releases/tags/{version}"
524+
525+
response = await http_client.get(
526+
api_url,
527+
headers={
528+
"Accept": "application/vnd.github+json",
529+
"User-Agent": "HomeAssistant-MCP-Server",
530+
},
531+
)
532+
533+
if response.status_code == 200:
534+
release_data = response.json()
535+
body = release_data.get("body", "")
536+
if body:
537+
logger.debug(
538+
f"Successfully fetched Core release notes from GitHub for version {version}"
539+
)
540+
return {"notes": str(body), "source": "github_api"}
541+
elif response.status_code == 403:
542+
# Check if rate limited
543+
remaining = response.headers.get("X-RateLimit-Remaining", "0")
544+
if remaining == "0":
545+
logger.warning(
546+
f"GitHub API rate limit exceeded for {api_url}"
547+
)
548+
else:
549+
logger.debug(
550+
f"GitHub API returned status {response.status_code} for Core release {version}"
551+
)
552+
553+
return None
554+
555+
except Exception as e:
556+
logger.debug(f"Failed to fetch Core release notes from GitHub: {e}")
557+
return None

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)