feat: implement version url support for go
This commit is contained in:
parent
f1ff604b4c
commit
62fdca8fbf
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue