From 3c44f824cb2f99cee35391b6160c1aadf176a5be Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sat, 30 Nov 2024 13:59:05 -0800 Subject: [PATCH] refactor: optimize HISTORY.md processing to work with relevant portion only --- scripts/update-history.py | 41 +++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/scripts/update-history.py b/scripts/update-history.py index a43620eb0..3b25971fb 100755 --- a/scripts/update-history.py +++ b/scripts/update-history.py @@ -37,10 +37,27 @@ def main(): # Get the git log output diff_content = run_git_log() - # Save to temporary file - with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".diff") as tmp: - tmp.write(diff_content) - tmp_path = tmp.name + # Extract relevant portion of HISTORY.md + base_ver = get_base_version() + with open("HISTORY.md", "r") as f: + history_content = f.read() + + # Find the section for this version + version_header = f"### Aider v{base_ver}" + start_idx = history_content.find("# Release history") + if start_idx == -1: + raise ValueError("Could not find start of release history") + + relevant_history = history_content[start_idx:] + + # Save relevant portions to temporary files + with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".diff") as tmp_diff: + tmp_diff.write(diff_content) + diff_path = tmp_diff.name + + with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".md") as tmp_hist: + tmp_hist.write(relevant_history) + hist_path = tmp_hist.name # Run blame to get aider percentage blame_result = subprocess.run(["python3", "scripts/blame.py"], capture_output=True, text=True) @@ -58,14 +75,26 @@ Also, add this as the last bullet under the "### main branch" section: {aider_line} """ # noqa - cmd = ["aider", "HISTORY.md", "--read", tmp_path, "--msg", message, "--no-auto-commit"] + cmd = ["aider", hist_path, "--read", diff_path, "--msg", message, "--no-auto-commit"] subprocess.run(cmd) + # Read back the updated history + with open(hist_path, "r") as f: + updated_history = f.read() + + # Splice the updated portion back into the full history + full_history = history_content[:start_idx] + updated_history + + # Write back the full history + with open("HISTORY.md", "w") as f: + f.write(full_history) + # Run update-docs.sh after aider subprocess.run(["scripts/update-docs.sh"]) # Cleanup - os.unlink(tmp_path) + os.unlink(diff_path) + os.unlink(hist_path) # Show git diff of HISTORY.md subprocess.run(["git", "diff", "HISTORY.md"])