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 lxml import html
|
||||||
|
|
||||||
from nvchecker.api import (
|
from nvchecker.api import (
|
||||||
VersionResult, Entry, AsyncCache, KeyManager,
|
RichResult, Entry, AsyncCache, KeyManager,
|
||||||
session, GetVersionError,
|
session, GetVersionError,
|
||||||
)
|
)
|
||||||
|
|
||||||
GO_PKG_URL = 'https://pkg.go.dev/{pkg}?tab=versions'
|
GO_PKG_URL = 'https://pkg.go.dev/{pkg}?tab=versions'
|
||||||
|
GO_PKG_VERSION_URL = 'https://pkg.go.dev/{pkg}@{version}'
|
||||||
|
|
||||||
|
|
||||||
async def get_version(
|
async def get_version(
|
||||||
name: str, conf: Entry, *,
|
name: str, conf: Entry, *,
|
||||||
cache: AsyncCache, keymanager: KeyManager,
|
cache: AsyncCache, keymanager: KeyManager,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> VersionResult:
|
) -> RichResult:
|
||||||
key = tuple(sorted(conf.items()))
|
key = tuple(sorted(conf.items()))
|
||||||
return await cache.get(key, get_version_impl)
|
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)
|
conf = dict(info)
|
||||||
pkg_name = conf.get('go')
|
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()")
|
elements = doc.xpath("//div[@class='Version-tag']/a/text()")
|
||||||
try:
|
try:
|
||||||
version = elements[0]
|
version = elements[0]
|
||||||
return version
|
return RichResult(
|
||||||
|
version = version,
|
||||||
|
url = GO_PKG_VERSION_URL.format(pkg=pkg_name, version=version),
|
||||||
|
)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise GetVersionError("parse error", pkg_name=pkg_name)
|
raise GetVersionError("parse error", pkg_name=pkg_name)
|
||||||
|
|
Loading…
Reference in New Issue