mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e19f033f15
3 changed files with 83 additions and 0 deletions
|
@ -946,6 +946,17 @@ Check `Visual Studio Code Marketplace <https://marketplace.visualstudio.com/vsco
|
||||||
vsmarketplace
|
vsmarketplace
|
||||||
The extension's Unique Identifier on marketplace.visualstudio.com/vscode, e.g. ``ritwickdey.LiveServer``.
|
The extension's Unique Identifier on marketplace.visualstudio.com/vscode, e.g. ``ritwickdey.LiveServer``.
|
||||||
|
|
||||||
|
Check Go packages and modules
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
::
|
||||||
|
|
||||||
|
source = "go"
|
||||||
|
|
||||||
|
Check `Go packages and modules <https://pkg.go.dev/>`_ for updates.
|
||||||
|
|
||||||
|
go
|
||||||
|
The name of Go package or module, e.g. ``github.com/caddyserver/caddy/v2/cmd``.
|
||||||
|
|
||||||
Combine others' results
|
Combine others' results
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
::
|
::
|
||||||
|
|
36
nvchecker_source/go.py
Normal file
36
nvchecker_source/go.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# MIT licensed
|
||||||
|
# Copyright (c) 2024 bgme <i@bgme.me>.
|
||||||
|
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
|
from nvchecker.api import (
|
||||||
|
VersionResult, Entry, AsyncCache, KeyManager,
|
||||||
|
session, GetVersionError, HTTPError
|
||||||
|
)
|
||||||
|
|
||||||
|
GO_PKG_URL = 'https://pkg.go.dev/{pkg}?tab=versions'
|
||||||
|
|
||||||
|
|
||||||
|
async def get_version(
|
||||||
|
name: str, conf: Entry, *,
|
||||||
|
cache: AsyncCache, keymanager: KeyManager,
|
||||||
|
**kwargs,
|
||||||
|
) -> VersionResult:
|
||||||
|
key = tuple(sorted(conf.items()))
|
||||||
|
return await cache.get(key, get_version_impl)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_version_impl(info) -> VersionResult:
|
||||||
|
conf = dict(info)
|
||||||
|
pkg_name = conf.get('go')
|
||||||
|
|
||||||
|
url = GO_PKG_URL.format(pkg=pkg_name)
|
||||||
|
res = await session.get(url)
|
||||||
|
doc = html.fromstring(res.body.decode())
|
||||||
|
|
||||||
|
elements = doc.xpath("//div[@class='Version-tag']/a/text()")
|
||||||
|
try:
|
||||||
|
version = elements[0]
|
||||||
|
return version
|
||||||
|
except IndexError:
|
||||||
|
raise GetVersionError("parse error", pkg_name=pkg_name)
|
36
tests/test_go.py
Normal file
36
tests/test_go.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# MIT licensed
|
||||||
|
# Copyright (c) 2024 bgme <i@bgme.me>.
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from nvchecker.api import HTTPError
|
||||||
|
|
||||||
|
lxml_available = True
|
||||||
|
try:
|
||||||
|
import lxml
|
||||||
|
except ImportError:
|
||||||
|
lxml_available = False
|
||||||
|
|
||||||
|
pytestmark = [
|
||||||
|
pytest.mark.asyncio(scope="session"),
|
||||||
|
pytest.mark.needs_net,
|
||||||
|
pytest.mark.skipif(not lxml_available, reason="needs lxml")
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_go(get_version):
|
||||||
|
assert await get_version("one version", {
|
||||||
|
"source": "go",
|
||||||
|
"go": "github.com/caddyserver/replace-response",
|
||||||
|
}) == "v0.0.0-20231221003037-a85d4ddc11d6"
|
||||||
|
|
||||||
|
assert await get_version("multiple version", {
|
||||||
|
"source": "go",
|
||||||
|
"go": "github.com/corazawaf/coraza-caddy",
|
||||||
|
}) == "v1.2.2"
|
||||||
|
|
||||||
|
with pytest.raises(HTTPError):
|
||||||
|
await get_version("not found", {
|
||||||
|
"source": "go",
|
||||||
|
"go": "github.com/asdas/sadfasdf",
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue