mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
feat: implement more metadata for git{,ea,hub,lab}
This commit is contained in:
parent
3691fa9a51
commit
03c2e25bbd
4 changed files with 40 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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'],
|
||||
)
|
||||
|
|
|
@ -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'],
|
||||
)
|
||||
|
||||
|
|
|
@ -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'],
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue