feature: show commits to merge/release in a table with relative date, type and message
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
import re
|
||||||
|
import time
|
||||||
from os.path import isfile
|
from os.path import isfile
|
||||||
|
|
||||||
import questionary
|
import questionary
|
||||||
import rich
|
import rich
|
||||||
import rich.panel
|
import rich.panel
|
||||||
|
from rich.table import Table
|
||||||
|
|
||||||
from git_flow import (
|
from git_flow import (
|
||||||
BRANCH_TYPES,
|
BRANCH_TYPES,
|
||||||
@@ -162,6 +165,54 @@ def get_commit_message(commit_types: list[str] = COMMIT_TYPES) -> str:
|
|||||||
return commit_type + ": " + commit_message
|
return commit_type + ": " + commit_message
|
||||||
|
|
||||||
|
|
||||||
|
# <tipo>[(alcance)][!]: <mensaje>, para no confundir "Merge pull request 'feature: ...'" con un tipo
|
||||||
|
COMMIT_SUBJECT_RE = re.compile(r"^(\w+)(?:\([^)]*\))?!?:\s*(.*)$")
|
||||||
|
|
||||||
|
|
||||||
|
def show_commits(title: str, revision_range: str):
|
||||||
|
"""Muestra en una tabla los commits del rango (fecha relativa, tipo y mensaje).
|
||||||
|
Si no hay commits aborta, ya que no hay nada para mergear."""
|
||||||
|
# fecha de autor: la de commit cambia al hacer rebase (por ejemplo, en release)
|
||||||
|
lines = Git("log", revision_range, format="%at%x09%s").lines()
|
||||||
|
|
||||||
|
if not lines:
|
||||||
|
raise GitFlowError("No hay cambios a mergear.")
|
||||||
|
|
||||||
|
table = Table(title=title, title_justify="left", title_style="bold")
|
||||||
|
table.add_column("Fecha", style="dim", no_wrap=True)
|
||||||
|
table.add_column("Tipo", style="cyan", no_wrap=True)
|
||||||
|
table.add_column("Mensaje")
|
||||||
|
|
||||||
|
now = time.time()
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
timestamp, subject = line.split("\t", 1)
|
||||||
|
match = COMMIT_SUBJECT_RE.match(subject)
|
||||||
|
commit_type, message = match.groups() if match else ("-", subject)
|
||||||
|
table.add_row(format_time_ago(now - int(timestamp)), commit_type, message)
|
||||||
|
|
||||||
|
console.print(table)
|
||||||
|
|
||||||
|
|
||||||
|
def format_time_ago(seconds: float) -> str:
|
||||||
|
units = [
|
||||||
|
(365 * 24 * 3600, "año", "años"),
|
||||||
|
(30 * 24 * 3600, "mes", "meses"),
|
||||||
|
(7 * 24 * 3600, "semana", "semanas"),
|
||||||
|
(24 * 3600, "día", "días"),
|
||||||
|
(3600, "hora", "horas"),
|
||||||
|
(60, "minuto", "minutos"),
|
||||||
|
]
|
||||||
|
|
||||||
|
for size, singular, plural in units:
|
||||||
|
amount = int(seconds // size)
|
||||||
|
|
||||||
|
if amount >= 1:
|
||||||
|
return f"hace {amount} {singular if amount == 1 else plural}"
|
||||||
|
|
||||||
|
return "hace un momento"
|
||||||
|
|
||||||
|
|
||||||
def io_error(message: str, title: str | None = None):
|
def io_error(message: str, title: str | None = None):
|
||||||
_io_status(message, "✖ Error: ", "red", title)
|
_io_status(message, "✖ Error: ", "red", title)
|
||||||
|
|
||||||
|
|||||||
@@ -71,15 +71,7 @@ def run_local(branch: str, target: str):
|
|||||||
|
|
||||||
|
|
||||||
def show_commits_to_merge(target):
|
def show_commits_to_merge(target):
|
||||||
commits = Git("log", target + "..", format="%s").lines()
|
base.show_commits("Cambios a mergear", target + "..")
|
||||||
|
|
||||||
if not commits:
|
|
||||||
raise GitFlowError("No hay cambios a mergear.")
|
|
||||||
|
|
||||||
print("Cambios a mergear:")
|
|
||||||
|
|
||||||
for commit in commits:
|
|
||||||
print("- " + commit)
|
|
||||||
|
|
||||||
|
|
||||||
def check_merge_conflicts(target: str):
|
def check_merge_conflicts(target: str):
|
||||||
|
|||||||
@@ -32,15 +32,7 @@ def release():
|
|||||||
)
|
)
|
||||||
|
|
||||||
fork_point = Git.get_first_fork_point(branch, env)
|
fork_point = Git.get_first_fork_point(branch, env)
|
||||||
commits = Git("log", fork_point + "..", format="%s").lines()
|
base.show_commits("Cambios a pasar al próximo entorno", fork_point + "..")
|
||||||
|
|
||||||
if not commits:
|
|
||||||
raise GitFlowError("No hay cambios a mergear.")
|
|
||||||
|
|
||||||
print("Cambios a pasar al proximo entorno:")
|
|
||||||
|
|
||||||
for commit in commits:
|
|
||||||
print("- " + commit)
|
|
||||||
|
|
||||||
if has_remote and Git.get_tracking_branch(next_env):
|
if has_remote and Git.get_tracking_branch(next_env):
|
||||||
Git("switch", next_env).exec(print="Cambiando a la rama objetivo")
|
Git("switch", next_env).exec(print="Cambiando a la rama objetivo")
|
||||||
|
|||||||
Reference in New Issue
Block a user