developer(ET): auto-commit from developer run_id=355
This commit is contained in:
@@ -349,3 +349,66 @@ def write_deploy_log(repo: str, work_item_id: str, branch: str, exit_code, statu
|
||||
except (subprocess.SubprocessError, OSError) as e:
|
||||
logger.warning("write_deploy_log: git commit/push best-effort failed: %s", e)
|
||||
return True
|
||||
|
||||
|
||||
def record_merged_to_main(repo: str, work_item_id: str, branch: str, merged: bool) -> bool:
|
||||
"""Stamp ``merged_to_main: true|false`` into 14-deploy-log.md frontmatter (ORCH-071).
|
||||
|
||||
Machine-readable observability for the merge-verify under-gate. ONLY the
|
||||
``merged_to_main:`` line is added/updated inside the YAML frontmatter block; the
|
||||
``deploy_status:`` field is left untouched, so the ``check_deploy_status`` /
|
||||
``_parse_deploy_status`` parsing contract is unchanged (TRZ §6 / AC §5).
|
||||
|
||||
Best-effort and idempotent: a missing log or any I/O error is logged and
|
||||
swallowed. Never raises.
|
||||
"""
|
||||
from .git_worktree import get_worktree_path
|
||||
|
||||
rel = f"docs/work-items/{work_item_id}/14-deploy-log.md"
|
||||
try:
|
||||
wt = get_worktree_path(repo, branch)
|
||||
except Exception as e: # noqa: BLE001 - never-raise
|
||||
logger.warning("record_merged_to_main: worktree error for %s/%s: %s", repo, branch, e)
|
||||
return False
|
||||
path = os.path.join(wt, rel)
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
except FileNotFoundError:
|
||||
logger.info("record_merged_to_main: no deploy log at %s (skip)", path)
|
||||
return False
|
||||
except OSError as e:
|
||||
logger.warning("record_merged_to_main: read error at %s: %s", path, e)
|
||||
return False
|
||||
|
||||
value = "true" if merged else "false"
|
||||
if not content.startswith("---"):
|
||||
# No frontmatter to amend — do not fabricate one (keep the contract minimal).
|
||||
logger.info("record_merged_to_main: no frontmatter in %s (skip)", path)
|
||||
return False
|
||||
parts = content.split("---", 2)
|
||||
if len(parts) < 3:
|
||||
return False
|
||||
fm_lines = parts[1].splitlines()
|
||||
new_lines = []
|
||||
replaced = False
|
||||
for ln in fm_lines:
|
||||
if ln.strip().lower().startswith("merged_to_main:"):
|
||||
new_lines.append(f"merged_to_main: {value}")
|
||||
replaced = True
|
||||
else:
|
||||
new_lines.append(ln)
|
||||
if not replaced:
|
||||
# Insert before the closing of the frontmatter block (append to the body).
|
||||
if new_lines and new_lines[0] == "":
|
||||
new_lines = new_lines[1:]
|
||||
new_lines.append(f"merged_to_main: {value}")
|
||||
new_fm = "\n".join(new_lines)
|
||||
new_content = "---\n" + new_fm.strip("\n") + "\n---" + parts[2]
|
||||
try:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(new_content)
|
||||
except OSError as e:
|
||||
logger.warning("record_merged_to_main: write error at %s: %s", path, e)
|
||||
return False
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user