mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 11:47:28 +01:00
Make Git Update Detection use release notes from annotated tag
Part of #545
This commit is contained in:
parent
4ad8e3605b
commit
e43a7827c2
@ -409,8 +409,9 @@ def check_update_config_impl(package):
|
|||||||
if config.trigger == PackageUpdateTrigger.COMMIT:
|
if config.trigger == PackageUpdateTrigger.COMMIT:
|
||||||
tag = None
|
tag = None
|
||||||
commit = get_latest_commit(package.repo, package.update_config.ref)
|
commit = get_latest_commit(package.repo, package.update_config.ref)
|
||||||
|
release_notes = None
|
||||||
elif config.trigger == PackageUpdateTrigger.TAG:
|
elif config.trigger == PackageUpdateTrigger.TAG:
|
||||||
tag, commit = get_latest_tag(package.repo)
|
tag, commit, release_notes = get_latest_tag(package.repo)
|
||||||
else:
|
else:
|
||||||
raise TaskError("Unknown update trigger")
|
raise TaskError("Unknown update trigger")
|
||||||
|
|
||||||
@ -437,6 +438,7 @@ def check_update_config_impl(package):
|
|||||||
rel.package = package
|
rel.package = package
|
||||||
rel.name = tag if tag else datetime.datetime.utcnow().strftime("%Y-%m-%d")
|
rel.name = tag if tag else datetime.datetime.utcnow().strftime("%Y-%m-%d")
|
||||||
rel.title = rel.name
|
rel.title = rel.name
|
||||||
|
rel.release_notes = release_notes
|
||||||
rel.url = ""
|
rel.url = ""
|
||||||
rel.task_id = uuid()
|
rel.task_id = uuid()
|
||||||
db.session.add(rel)
|
db.session.add(rel)
|
||||||
|
@ -22,13 +22,21 @@ test_repo = "https://gitlab.com/rubenwardy/testmod"
|
|||||||
master_head = "23d12265ff6de84548b2e3e90dc7351a54f63f00"
|
master_head = "23d12265ff6de84548b2e3e90dc7351a54f63f00"
|
||||||
test_branch_head = "51b54f00c3b3d712417a1cc4bfaa6cbdc7aac3fc"
|
test_branch_head = "51b54f00c3b3d712417a1cc4bfaa6cbdc7aac3fc"
|
||||||
v4_commit = "c07d27c3a466d2102d1ba5473d172c74e6b3e0d7"
|
v4_commit = "c07d27c3a466d2102d1ba5473d172c74e6b3e0d7"
|
||||||
|
latest_tag_name = "v5"
|
||||||
|
latest_tag_commit = "23d12265ff6de84548b2e3e90dc7351a54f63f00"
|
||||||
|
latest_tag_message = """
|
||||||
|
* One thing
|
||||||
|
* Second
|
||||||
|
* Third
|
||||||
|
""".strip()
|
||||||
random_commit = "84a2e53ff046eacbdbb80f3a00c58510885fefca"
|
random_commit = "84a2e53ff046eacbdbb80f3a00c58510885fefca"
|
||||||
|
|
||||||
|
|
||||||
def test_get_latest_tag():
|
def test_get_latest_tag():
|
||||||
tag, commit = get_latest_tag(test_repo)
|
tag, commit, message = get_latest_tag(test_repo)
|
||||||
assert tag == "v4"
|
assert tag == latest_tag_name
|
||||||
assert commit == v4_commit
|
assert commit == latest_tag_commit
|
||||||
|
assert message == latest_tag_message
|
||||||
|
|
||||||
|
|
||||||
def test_get_latest_commit():
|
def test_get_latest_commit():
|
||||||
@ -68,6 +76,8 @@ def test_git_clone_branch():
|
|||||||
def test_git_clone_tag():
|
def test_git_clone_tag():
|
||||||
with clone_repo(test_repo, "v4", recursive=True) as repo:
|
with clone_repo(test_repo, "v4", recursive=True) as repo:
|
||||||
assert repo.head.commit.hexsha == v4_commit
|
assert repo.head.commit.hexsha == v4_commit
|
||||||
|
|
||||||
|
# v4 isn't on the master branch, let's check there's no master branch files
|
||||||
assert os.path.isfile(os.path.join(repo.working_tree_dir, "init.lua"))
|
assert os.path.isfile(os.path.join(repo.working_tree_dir, "init.lua"))
|
||||||
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "chatcmdbuilder", "init.lua"))
|
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "chatcmdbuilder", "init.lua"))
|
||||||
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "test-branch.txt"))
|
assert not os.path.isfile(os.path.join(repo.working_tree_dir, "test-branch.txt"))
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Tuple
|
||||||
|
|
||||||
import git
|
import git
|
||||||
import gitdb
|
import gitdb
|
||||||
@ -107,7 +107,8 @@ def get_latest_commit(git_url, ref_name=None):
|
|||||||
return remote_refs.get(ref_name)
|
return remote_refs.get(ref_name)
|
||||||
|
|
||||||
|
|
||||||
def get_latest_tag(git_url):
|
# @returns (tag_name, commit_hash, tag_message)
|
||||||
|
def get_latest_tag(git_url) -> Tuple[Optional[str], Optional[str], Optional[str]]:
|
||||||
with get_temp_dir() as git_dir:
|
with get_temp_dir() as git_dir:
|
||||||
repo = git.Repo.init(git_dir)
|
repo = git.Repo.init(git_dir)
|
||||||
origin = repo.create_remote("origin", url=git_url)
|
origin = repo.create_remote("origin", url=git_url)
|
||||||
@ -116,14 +117,26 @@ def get_latest_tag(git_url):
|
|||||||
refs = repo.git.for_each_ref(sort="creatordate", format="%(objectname)\t%(refname)").split("\n")
|
refs = repo.git.for_each_ref(sort="creatordate", format="%(objectname)\t%(refname)").split("\n")
|
||||||
refs = [ref for ref in refs if "refs/tags/" in ref]
|
refs = [ref for ref in refs if "refs/tags/" in ref]
|
||||||
if len(refs) == 0:
|
if len(refs) == 0:
|
||||||
return None, None
|
return None, None, None
|
||||||
|
|
||||||
last_ref = refs[-1]
|
last_ref = refs[-1]
|
||||||
hash_ref_list = last_ref.split('\t')
|
hash_ref_list = last_ref.split('\t')
|
||||||
|
|
||||||
tag = hash_ref_list[1].replace("refs/tags/", "")
|
tag = hash_ref_list[1].replace("refs/tags/", "")
|
||||||
|
# "^{}" means dereference the tag until an actual commit is found
|
||||||
commit_hash = repo.git.rev_parse(tag + "^{}")
|
commit_hash = repo.git.rev_parse(tag + "^{}")
|
||||||
return tag, commit_hash
|
|
||||||
|
# Get summary message of annotated tag from GitPython
|
||||||
|
annotated_tag = repo.tag(tag).tag
|
||||||
|
if annotated_tag:
|
||||||
|
message = annotated_tag.message
|
||||||
|
message = normalize_line_endings(message)
|
||||||
|
if message == "":
|
||||||
|
message = None
|
||||||
|
else:
|
||||||
|
message = None
|
||||||
|
|
||||||
|
return tag, commit_hash, message
|
||||||
|
|
||||||
|
|
||||||
def get_commit_list(git_url: str, start: str, end: str) -> List[str]:
|
def get_commit_list(git_url: str, start: str, end: str) -> List[str]:
|
||||||
|
Loading…
Reference in New Issue
Block a user