Skip to content

Commit

Permalink
add stable_version as output in PackagesResource
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurzam authored and mergify[bot] committed Apr 13, 2023
1 parent b260304 commit 44e3dfa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion anitya/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def get(self):
"name": "python-requests"
"project": "requests",
"ecosystem": "pypi",
"version": "2.28.1"
"version": "2.28.1",
"stable_version": "2.28.1"
}
],
"items_per_page": 25,
Expand Down Expand Up @@ -168,6 +169,7 @@ def get(self):
"project": package.project.name,
"ecosystem": package.project.ecosystem_name,
"version": package.project.latest_version,
"stable_version": package.project.latest_stable_version,
}
for package in page.items
],
Expand Down
13 changes: 13 additions & 0 deletions anitya/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ def stable_versions(self):
sorted_versions = self.get_sorted_version_objects()
return [version for version in sorted_versions if not version.prerelease()]

@property
def latest_stable_version(self):
"""
Return latest stable version.
Returns:
`string`: Latest stable version if exists, otherwise None.
"""
stable_versions = self.stable_versions
if stable_versions:
return str(stable_versions[0])
return None

def get_last_created_version(self):
"""
Returns last obtained release by date.
Expand Down
16 changes: 15 additions & 1 deletion anitya/tests/test_flask_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def test_packages(self):
jcline_package = models.Packages(
distro_name="jcline linux", project=project, package_name="requests"
)
Session.add_all([project, fedora_package, debian_package, jcline_package])
version = models.ProjectVersion(project=project, version="1")
Session.add_all(
[project, fedora_package, debian_package, jcline_package, version]
)
Session.commit()

output = self.app.get("/api/v2/packages/")
Expand All @@ -119,20 +122,23 @@ def test_packages(self):
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": "1",
},
{
"distribution": "Debian",
"name": "python-requests",
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": "1",
},
{
"distribution": "jcline linux",
"name": "requests",
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": "1",
},
],
}
Expand Down Expand Up @@ -174,13 +180,15 @@ def test_filter_packages_by_name(self):
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
},
{
"distribution": "Debian",
"name": "python-requests",
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
},
],
}
Expand Down Expand Up @@ -222,13 +230,15 @@ def test_filter_packages_by_name_case_insensitive(self):
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
},
{
"distribution": "Debian",
"name": "python-requests",
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
},
],
}
Expand Down Expand Up @@ -277,6 +287,7 @@ def test_list_packages_items_per_page(self):
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
}
],
}
Expand Down Expand Up @@ -314,6 +325,7 @@ def test_list_packages_items_per_page_with_page(self):
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
}
],
}
Expand Down Expand Up @@ -354,6 +366,7 @@ def test_filter_distribution(self):
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
}
],
}
Expand All @@ -368,6 +381,7 @@ def test_filter_distribution(self):
"project": "requests",
"ecosystem": "pypi",
"version": "1",
"stable_version": None,
}
],
}
Expand Down
1 change: 1 addition & 0 deletions news/1033.api
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add stable_version as output in PackagesResource

0 comments on commit 44e3dfa

Please sign in to comment.