From 62fdca8fbf8239f77bd143ced44d98ed3f99256c Mon Sep 17 00:00:00 2001 From: Daniel Peukert Date: Tue, 23 Apr 2024 23:27:06 +0200 Subject: [PATCH] feat: implement version url support for go --- nvchecker_source/go.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nvchecker_source/go.py b/nvchecker_source/go.py index 7ddfa5c..61391e0 100644 --- a/nvchecker_source/go.py +++ b/nvchecker_source/go.py @@ -4,23 +4,24 @@ from lxml import html from nvchecker.api import ( - VersionResult, Entry, AsyncCache, KeyManager, + RichResult, Entry, AsyncCache, KeyManager, session, GetVersionError, ) GO_PKG_URL = 'https://pkg.go.dev/{pkg}?tab=versions' +GO_PKG_VERSION_URL = 'https://pkg.go.dev/{pkg}@{version}' async def get_version( name: str, conf: Entry, *, cache: AsyncCache, keymanager: KeyManager, **kwargs, -) -> VersionResult: +) -> RichResult: key = tuple(sorted(conf.items())) return await cache.get(key, get_version_impl) -async def get_version_impl(info) -> VersionResult: +async def get_version_impl(info) -> RichResult: conf = dict(info) pkg_name = conf.get('go') @@ -31,6 +32,9 @@ async def get_version_impl(info) -> VersionResult: elements = doc.xpath("//div[@class='Version-tag']/a/text()") try: version = elements[0] - return version + return RichResult( + version = version, + url = GO_PKG_VERSION_URL.format(pkg=pkg_name, version=version), + ) except IndexError: raise GetVersionError("parse error", pkg_name=pkg_name)