Merge remote-tracking branch 'origin/pr/254'

This commit is contained in:
lilydjwg 2024-03-08 20:34:16 +08:00
commit 1d19082673
6 changed files with 53 additions and 3 deletions

View File

@ -331,6 +331,8 @@ def _process_result(r: RawResult) -> Union[Result, Exception]:
name = r.name
url = None
revision = None
gitref = None
if isinstance(version, GetVersionError):
kw = version.kwargs
kw['name'] = name
@ -344,10 +346,14 @@ def _process_result(r: RawResult) -> Union[Result, Exception]:
version_str = apply_list_options(version, conf)
if isinstance(version_str, RichResult):
url = version_str.url
gitref = version_str.gitref
revision = version_str.revision
version_str = version_str.version
elif isinstance(version, RichResult):
version_str = version.version
url = version.url
gitref = version.gitref
revision = version.revision
else:
version_str = version
@ -356,7 +362,7 @@ def _process_result(r: RawResult) -> Union[Result, Exception]:
try:
version_str = substitute_version(version_str, conf)
return Result(name, version_str, conf, url)
return Result(name, version_str, conf, url, gitref, revision)
except (ValueError, re.error) as e:
logger.exception('error occurred in version substitutions', name=name)
return e

View File

@ -45,6 +45,8 @@ if sys.version_info[:2] >= (3, 10):
@dataclass(kw_only=True)
class RichResult:
version: str
gitref: Optional[str] = None
revision: Optional[str] = None
url: Optional[str] = None
def __str__(self):
@ -53,6 +55,8 @@ else:
@dataclass
class RichResult:
version: str
gitref: Optional[str] = None
revision: Optional[str] = None
url: Optional[str] = None
def __str__(self):
@ -141,6 +145,8 @@ class Result(NamedTuple):
version: str
conf: Entry
url: Optional[str]
gitref: Optional[str]
revision: Optional[str]
class BaseWorker:
'''The base class for defining `Worker` classes for source plugins.

View File

@ -3,6 +3,8 @@
from .cmd import run_cmd
from nvchecker.api import RichResult
async def get_version(
name, conf, *, cache, keymanager=None
):
@ -13,13 +15,27 @@ async def get_version(
ref = conf.get('branch')
if ref is None:
ref = 'HEAD'
gitref = None
else:
ref = 'refs/heads/' + ref
gitref = ref
cmd = f"git ls-remote {git} {ref}"
data = await cache.get(cmd, run_cmd)
return data.split(None, 1)[0]
version = data.split(None, 1)[0]
return RichResult(
version = version,
revision = revision,
gitref = gitref
)
else:
cmd = f"git ls-remote --tags --refs {git}"
data = await cache.get(cmd, run_cmd)
versions = [line.split("refs/tags/")[1] for line in data.splitlines()]
versions = []
for line in line in data.splitlines():
revision, version = line.split("\trefs/tags/", 1)
versions.append(RichResult(
version = version,
revision = revision,
gitref = f"refs/tags/{version}"
))
return versions

View File

@ -45,11 +45,13 @@ async def get_version(
return [
RichResult(
version = tag['name'],
revision = tag['id'],
url = f'https://{host}/{conf["gitea"]}/releases/tag/{tag["name"]}',
) for tag in data
]
else:
return RichResult(
version = data[0]['commit']['committer']['date'].split('T', 1)[0].replace('-', ''),
revision = data[0]['id'],
url = data[0]['html_url'],
)

View File

@ -56,6 +56,9 @@ QUERY_LATEST_TAG = '''
edges {{
node {{
name
target {{
oid
}}
}}
}}
}}
@ -71,6 +74,12 @@ QUERY_LATEST_RELEASE_WITH_PRERELEASES = '''
node {{
name
url
tag {{
name
}}
tagCommit {{
oid
}}
}}
}}
}}
@ -103,8 +112,11 @@ async def get_latest_tag(key: Tuple[str, str, str, str]) -> RichResult:
raise GetVersionError('no tag found')
version = refs[0]['node']['name']
revision = refs[0]['node']['target']['oid']
return RichResult(
version = version,
gitref = f"refs/tags/{name}",
revision = revision,
url = f'https://github.com/{repo}/releases/tag/{version}',
)
@ -133,6 +145,8 @@ async def get_latest_release_with_prereleases(key: Tuple[str, str, str]) -> Rich
return RichResult(
version = refs[0]['node']['name'],
gitref = refs[0]['node']['tag']['name'],
revision = refs[0]['node']['tagCommit']['oid'],
url = refs[0]['node']['url'],
)
@ -193,6 +207,8 @@ async def get_version_real(
tags: List[Union[str, RichResult]] = [
RichResult(
version = ref['ref'].split('/', 2)[-1],
gitref = ref['ref'],
revision = ref['object']['sha'],
url = f'https://github.com/{repo}/releases/tag/{ref["ref"].split("/", 2)[-1]}',
) for ref in data
]
@ -205,6 +221,7 @@ async def get_version_real(
raise GetVersionError('No release found in upstream repository.')
return RichResult(
version = data['tag_name'],
ref = f"refs/tags/{data['tag_name']}",
url = data['html_url'],
)
@ -212,6 +229,7 @@ async def get_version_real(
return RichResult(
# YYYYMMDD.HHMMSS
version = data[0]['commit']['committer']['date'].rstrip('Z').replace('-', '').replace(':', '').replace('T', '.'),
revision = data[0]['sha'],
url = data[0]['html_url'],
)

View File

@ -54,12 +54,14 @@ async def get_version_real(
return [
RichResult(
version = tag['name'],
revision = tag['commit']['id'],
url = f'https://{host}/{conf["gitlab"]}/-/tags/{tag["name"]}',
) for tag in data
]
else:
return RichResult(
version = data[0]['created_at'].split('T', 1)[0].replace('-', ''),
revision = data[0]['id'],
url = data[0]['web_url'],
)