feature: include author email in report, generate report filename
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import csv
|
import csv
|
||||||
|
import datetime
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ from git_flow import GitFlowError
|
|||||||
from git_flow.command import base
|
from git_flow.command import base
|
||||||
from git_flow.git import Git
|
from git_flow.git import Git
|
||||||
|
|
||||||
REPORT_FORMAT = "%(refname:short)\t%(objectname)\t%(authorname)\t%(authordate:iso-strict)"
|
REPORT_FORMAT = "%(refname:short)\t%(objectname)\t%(author)\t%(authordate:iso-strict)"
|
||||||
REPORT_FILENAME = "branch-clean-report.csv"
|
REPORT_FILENAME = "branch-clean-report.csv"
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
@@ -48,12 +49,12 @@ def clean(
|
|||||||
if not base.io_confirm(f"¿Eliminar {len(branches)} rama(s)?", False):
|
if not base.io_confirm(f"¿Eliminar {len(branches)} rama(s)?", False):
|
||||||
raise GitFlowError("Ejecución abortada")
|
raise GitFlowError("Ejecución abortada")
|
||||||
|
|
||||||
write_report(branches)
|
report = write_report(branches)
|
||||||
|
|
||||||
for branch in branches:
|
for branch in branches:
|
||||||
delete_branch(branch, remote)
|
delete_branch(branch, remote)
|
||||||
|
|
||||||
base.io_success(f"Se eliminaron {len(branches)} rama(s). Reporte generado en {REPORT_FILENAME}")
|
base.io_success(f"Se eliminaron {len(branches)} rama(s). Reporte generado en {report}")
|
||||||
|
|
||||||
|
|
||||||
def get_local_branches() -> list[BranchInfo]:
|
def get_local_branches() -> list[BranchInfo]:
|
||||||
@@ -97,14 +98,19 @@ def parse_branch(line: str) -> BranchInfo:
|
|||||||
return BranchInfo(name, sha, author, date)
|
return BranchInfo(name, sha, author, date)
|
||||||
|
|
||||||
|
|
||||||
def write_report(branches: list[BranchInfo]):
|
def write_report(branches: list[BranchInfo]) -> str:
|
||||||
with open(REPORT_FILENAME, "w", newline="") as f:
|
now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||||
|
report = "branch-clean-report-" + now + ".csv"
|
||||||
|
|
||||||
|
with open(report, "w", newline="") as f:
|
||||||
writer = csv.writer(f)
|
writer = csv.writer(f)
|
||||||
writer.writerow(["name", "commit sha", "author", "date"])
|
writer.writerow(["name", "commit", "author", "date"])
|
||||||
|
|
||||||
for branch in branches:
|
for branch in branches:
|
||||||
writer.writerow([branch.name, branch.sha, branch.author, branch.date])
|
writer.writerow([branch.name, branch.sha, branch.author, branch.date])
|
||||||
|
|
||||||
|
return report
|
||||||
|
|
||||||
|
|
||||||
def delete_branch(branch: BranchInfo, remote: bool):
|
def delete_branch(branch: BranchInfo, remote: bool):
|
||||||
if remote:
|
if remote:
|
||||||
|
|||||||
Reference in New Issue
Block a user