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 .cmd import run_cmd
|
||||||
|
|
||||||
|
from nvchecker.api import RichResult
|
||||||
|
|
||||||
async def get_version(
|
async def get_version(
|
||||||
name, conf, *, cache, keymanager=None
|
name, conf, *, cache, keymanager=None
|
||||||
):
|
):
|
||||||
|
@ -13,13 +15,27 @@ async def get_version(
|
||||||
ref = conf.get('branch')
|
ref = conf.get('branch')
|
||||||
if ref is None:
|
if ref is None:
|
||||||
ref = 'HEAD'
|
ref = 'HEAD'
|
||||||
|
gitref = None
|
||||||
else:
|
else:
|
||||||
ref = 'refs/heads/' + ref
|
ref = 'refs/heads/' + ref
|
||||||
|
gitref = ref
|
||||||
cmd = f"git ls-remote {git} {ref}"
|
cmd = f"git ls-remote {git} {ref}"
|
||||||
data = await cache.get(cmd, run_cmd)
|
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:
|
else:
|
||||||
cmd = f"git ls-remote --tags --refs {git}"
|
cmd = f"git ls-remote --tags --refs {git}"
|
||||||
data = await cache.get(cmd, run_cmd)
|
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
|
return versions
|
||||||
|
|
|
@ -45,11 +45,13 @@ async def get_version(
|
||||||
return [
|
return [
|
||||||
RichResult(
|
RichResult(
|
||||||
version = tag['name'],
|
version = tag['name'],
|
||||||
|
revision = tag['id'],
|
||||||
url = f'https://{host}/{conf["gitea"]}/releases/tag/{tag["name"]}',
|
url = f'https://{host}/{conf["gitea"]}/releases/tag/{tag["name"]}',
|
||||||
) for tag in data
|
) for tag in data
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
return RichResult(
|
return RichResult(
|
||||||
version = data[0]['commit']['committer']['date'].split('T', 1)[0].replace('-', ''),
|
version = data[0]['commit']['committer']['date'].split('T', 1)[0].replace('-', ''),
|
||||||
|
revision = data[0]['id'],
|
||||||
url = data[0]['html_url'],
|
url = data[0]['html_url'],
|
||||||
)
|
)
|
||||||
|
|
|
@ -56,6 +56,9 @@ QUERY_LATEST_TAG = '''
|
||||||
edges {{
|
edges {{
|
||||||
node {{
|
node {{
|
||||||
name
|
name
|
||||||
|
target {{
|
||||||
|
oid
|
||||||
|
}}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
|
@ -71,6 +74,12 @@ QUERY_LATEST_RELEASE_WITH_PRERELEASES = '''
|
||||||
node {{
|
node {{
|
||||||
name
|
name
|
||||||
url
|
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')
|
raise GetVersionError('no tag found')
|
||||||
|
|
||||||
version = refs[0]['node']['name']
|
version = refs[0]['node']['name']
|
||||||
|
revision = refs[0]['node']['target']['oid']
|
||||||
return RichResult(
|
return RichResult(
|
||||||
version = version,
|
version = version,
|
||||||
|
gitref = f"refs/tags/{name}",
|
||||||
|
revision = revision,
|
||||||
url = f'https://github.com/{repo}/releases/tag/{version}',
|
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(
|
return RichResult(
|
||||||
version = refs[0]['node']['name'],
|
version = refs[0]['node']['name'],
|
||||||
|
gitref = refs[0]['node']['tag']['name'],
|
||||||
|
revision = refs[0]['node']['tagCommit']['oid'],
|
||||||
url = refs[0]['node']['url'],
|
url = refs[0]['node']['url'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -193,6 +207,8 @@ async def get_version_real(
|
||||||
tags: List[Union[str, RichResult]] = [
|
tags: List[Union[str, RichResult]] = [
|
||||||
RichResult(
|
RichResult(
|
||||||
version = ref['ref'].split('/', 2)[-1],
|
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]}',
|
url = f'https://github.com/{repo}/releases/tag/{ref["ref"].split("/", 2)[-1]}',
|
||||||
) for ref in data
|
) for ref in data
|
||||||
]
|
]
|
||||||
|
@ -205,6 +221,7 @@ async def get_version_real(
|
||||||
raise GetVersionError('No release found in upstream repository.')
|
raise GetVersionError('No release found in upstream repository.')
|
||||||
return RichResult(
|
return RichResult(
|
||||||
version = data['tag_name'],
|
version = data['tag_name'],
|
||||||
|
ref = f"refs/tags/{data['tag_name']}",
|
||||||
url = data['html_url'],
|
url = data['html_url'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -212,6 +229,7 @@ async def get_version_real(
|
||||||
return RichResult(
|
return RichResult(
|
||||||
# YYYYMMDD.HHMMSS
|
# YYYYMMDD.HHMMSS
|
||||||
version = data[0]['commit']['committer']['date'].rstrip('Z').replace('-', '').replace(':', '').replace('T', '.'),
|
version = data[0]['commit']['committer']['date'].rstrip('Z').replace('-', '').replace(':', '').replace('T', '.'),
|
||||||
|
revision = data[0]['sha'],
|
||||||
url = data[0]['html_url'],
|
url = data[0]['html_url'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -54,12 +54,14 @@ async def get_version_real(
|
||||||
return [
|
return [
|
||||||
RichResult(
|
RichResult(
|
||||||
version = tag['name'],
|
version = tag['name'],
|
||||||
|
revision = tag['commit']['id'],
|
||||||
url = f'https://{host}/{conf["gitlab"]}/-/tags/{tag["name"]}',
|
url = f'https://{host}/{conf["gitlab"]}/-/tags/{tag["name"]}',
|
||||||
) for tag in data
|
) for tag in data
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
return RichResult(
|
return RichResult(
|
||||||
version = data[0]['created_at'].split('T', 1)[0].replace('-', ''),
|
version = data[0]['created_at'].split('T', 1)[0].replace('-', ''),
|
||||||
|
revision = data[0]['id'],
|
||||||
url = data[0]['web_url'],
|
url = data[0]['web_url'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue