Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use REST API in fetch releases for consistency #3962

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,23 +1434,11 @@ async def async_download_repository(self, *, ref: str | None = None, **_) -> Non
{"repository": self.data.full_name, "progress": False},
)

async def async_get_releases(self, *, first: int = 30) -> list[dict[str, Any]]:
async def async_get_releases(self, *, first: int = 30) -> list[GitHubReleaseModel]:
"""Get the last x releases of a repository."""
owner, name = self.data.full_name.split("/")
response = await self.hacs.async_github_api_method(
method=self.hacs.githubapi.graphql,
query=GET_REPOSITORY_RELEASES,
variables={
"owner": owner,
"name": name,
"first": first,
},
)
return (
[]
if response is None
else response.data.get("data", {})
.get("repository", {})
.get("releases", {})
.get("nodes", [])
method=self.hacs.githubapi.repos.releases.list,
repository=self.data.full_name,
kwargs={"per_page": 30},
)
return response.data
8 changes: 4 additions & 4 deletions custom_components/hacs/websocket/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ async def hacs_repository_releases(
msg["id"],
[
{
"name": release["name"],
"tag": release["tagName"],
"published_at": release["publishedAt"],
"prerelease": release["isPrerelease"],
"name": release.name,
"tag": release.tag_name,
"published_at": release.published_at,
"prerelease": release.prerelease,
}
for release in releases
],
Expand Down
25 changes: 9 additions & 16 deletions tests/repositories/test_get_reposiotry_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,17 @@ async def test_get_reposiotry_releases(
assert repo is not None

response_mocker.add(
"https://api.github.com/graphql",
f"https://api.github.com/repos/{
category_test_data['repository']}/releases",
response=MockedResponse(
content={
"data": {
"repository": {
"releases": {
"nodes": [
{
"name": category_test_data["version_update"],
"publishedAt": "2019-02-26T15:02:39Z",
"tagName": category_test_data["version_update"],
"isPrerelease": False,
}
]
}
}
content=[
{
"name": category_test_data["version_update"],
"tag_name": category_test_data["version_update"],
"published_at": "2019-02-26T15:02:39Z",
"prerelease": False,
}
}
]
),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/repositories/test_get_reposiotry_releases.py::test_get_reposiotry_releases[hacs-test-org/appdaemon-basic]": {
"https://api.github.com/graphql": 1,
"https://api.github.com/repos/hacs-test-org/appdaemon-basic/releases": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/repositories/test_get_reposiotry_releases.py::test_get_reposiotry_releases[hacs-test-org/integration-basic]": {
"https://api.github.com/graphql": 1,
"https://api.github.com/repos/hacs-test-org/integration-basic/releases": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/repositories/test_get_reposiotry_releases.py::test_get_reposiotry_releases[hacs-test-org/plugin-basic]": {
"https://api.github.com/graphql": 1,
"https://api.github.com/repos/hacs-test-org/plugin-basic/releases": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/repositories/test_get_reposiotry_releases.py::test_get_reposiotry_releases[hacs-test-org/python_script-basic]": {
"https://api.github.com/graphql": 1,
"https://api.github.com/repos/hacs-test-org/python_script-basic/releases": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/repositories/test_get_reposiotry_releases.py::test_get_reposiotry_releases[hacs-test-org/template-basic]": {
"https://api.github.com/graphql": 1,
"https://api.github.com/repos/hacs-test-org/template-basic/releases": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/repositories/test_get_reposiotry_releases.py::test_get_reposiotry_releases[hacs-test-org/theme-basic]": {
"https://api.github.com/graphql": 1,
"https://api.github.com/repos/hacs-test-org/theme-basic/releases": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
Expand Down