feature: tag from ci fetches commits from remote api
This commit is contained in:
+23
-17
@@ -27,12 +27,23 @@ def tag(token: Optional[str] = None):
|
||||
if target not in base.environments:
|
||||
raise GitFlowError("Solo se pueden taggear commits en ramas principales.")
|
||||
|
||||
branch = Git(
|
||||
"show", get_last_merge_commit() + "^2", patch=False, format="%h"
|
||||
).firstline()
|
||||
fork_point = Git.get_first_fork_point(branch, target)
|
||||
commits = Git("log", fork_point + ".." + branch, format="%s").lines()
|
||||
next_tag = get_next_tag_from_commits(commits, target)
|
||||
token, ci = get_token_and_ci(token)
|
||||
|
||||
if ci and not token:
|
||||
raise GitFlowError("No hay token disponible")
|
||||
|
||||
merge_commit = get_last_merge_commit()
|
||||
|
||||
if ci:
|
||||
# Pipeline: no asumimos historial completo, los commits del PR se piden a la API
|
||||
commits = base.get_remote_api(token).get_merge_commits(merge_commit)
|
||||
commits = [c for c in commits if not c.is_merge]
|
||||
else:
|
||||
branch = Git("show", merge_commit + "^2", patch=False, format="%h").firstline()
|
||||
fork_point = Git.get_first_fork_point(branch, target)
|
||||
commits = Git.get_commits(fork_point, branch)
|
||||
|
||||
next_tag = get_next_tag_from_commits([c.subject for c in commits], target)
|
||||
|
||||
if not next_tag:
|
||||
base.io_info(
|
||||
@@ -40,14 +51,9 @@ def tag(token: Optional[str] = None):
|
||||
)
|
||||
return
|
||||
|
||||
token, ci = get_token_and_ci(token)
|
||||
|
||||
if not token:
|
||||
raise GitFlowError("No hay token disponible")
|
||||
|
||||
changelog = Changelog()
|
||||
|
||||
changelog.update(next_tag, fork_point, branch)
|
||||
changelog.update(next_tag, commits)
|
||||
Git("add", Changelog.FILENAME).exec(print="Agregando nuevo CHANGELOG.md")
|
||||
Git("commit", message=Changelog.COMMIT_MESSAGE).exec(print="Creando commit")
|
||||
tag_commit = Git("show", "HEAD", patch=False, format="%h").firstline()
|
||||
@@ -60,15 +66,15 @@ def tag(token: Optional[str] = None):
|
||||
|
||||
|
||||
def get_token_and_ci(token: Optional[str]):
|
||||
try:
|
||||
return (base.ensure_repository_token(), False)
|
||||
except GitFlowError:
|
||||
if token:
|
||||
return (token, True)
|
||||
else:
|
||||
return (base.ensure_repository_token(), False)
|
||||
|
||||
|
||||
def get_last_merge_commit():
|
||||
commit = Git(
|
||||
"log", first_parent=True, merges=True, max_count=1, format="%h"
|
||||
"log", first_parent=True, merges=True, max_count=1, format="%H"
|
||||
).firstline()
|
||||
|
||||
if not commit:
|
||||
@@ -87,7 +93,7 @@ def check_not_tagged(commit: str):
|
||||
def get_next_tag_from_commits(commits: list[str], branch: str) -> str | None:
|
||||
increment = SEMVER_SKIP
|
||||
for commit in commits:
|
||||
commit_type = commit[: commit.index(":")]
|
||||
commit_type = commit.partition(":")[0]
|
||||
increment = max(increment, COMMIT_TYPE_INCREMENT.get(commit_type, SEMVER_SKIP))
|
||||
|
||||
tag = Git.get_current_tag() or f"v0.0.0-{branch}"
|
||||
|
||||
Reference in New Issue
Block a user