Bladeren bron

Preserve manual Reference column edits on script rerun

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 maand geleden
bovenliggende
commit
018543d62d
3 gewijzigde bestanden met toevoegingen van 38 en 7 verwijderingen
  1. 1 1
      CONTRIBUTORS.md
  2. 1 1
      scripts/README.md
  3. 36 5
      scripts/update_contributors.py

+ 1 - 1
CONTRIBUTORS.md

@@ -6,4 +6,4 @@ Do not edit manually — run `python scripts/update_contributors.py` to refresh.
 | Name | Email | Contributions | First Commit | Last Commit | Reference |
 |------|--------|----------------|---------------|--------------|-----------|
 | Adam Djellouli | [email protected] | 1 commit | 2025-10-29 | 2025-10-29 |  |
-| copilot-swe-agent[bot] | [email protected] | 7 commits | 2025-10-29 | 2025-10-29 |  |
+| copilot-swe-agent[bot] | [email protected] | 8 commits | 2025-10-29 | 2025-10-29 |  |

+ 1 - 1
scripts/README.md

@@ -102,7 +102,7 @@ python scripts/update_contributors.py
 | Bob Writer | [email protected] | 9 commits | 2025-03-15 | 2025-10-20 |  |
 ```
 
-**Note:** The Reference column is left empty by default and can be manually edited to add links to GitHub profiles, websites, or other references. However, manual edits will be preserved only if the contributor's row remains unchanged in subsequent updates.
+**Note:** The Reference column is left empty by default and can be manually edited to add links to GitHub profiles, websites, or other references. The script automatically preserves any manually-added Reference values when it regenerates the file, so your edits will not be lost on subsequent runs.
 
 ---
 

+ 36 - 5
scripts/update_contributors.py

@@ -22,6 +22,36 @@ def run_git(command):
         print("❌ Error: Git is not installed or not found in PATH.")
         raise SystemExit(1)
 
+def parse_existing_references():
+    """Parse existing CONTRIBUTORS.md to extract manual Reference values."""
+    references = {}
+    if not contributors_file.exists():
+        return references
+    
+    try:
+        content = contributors_file.read_text(encoding="utf-8")
+        lines = content.split("\n")
+        
+        for line in lines:
+            # Skip header, separator, and empty lines
+            if not line.strip() or line.startswith("#") or "---" in line or line.startswith("This file"):
+                continue
+            # Check if it's a table row (starts with |)
+            if line.startswith("|") and line.count("|") >= 6:
+                parts = [p.strip() for p in line.split("|")]
+                # parts[0] is empty (before first |), parts[1] is Name, parts[6] is Reference
+                if len(parts) >= 7:
+                    name = parts[1]
+                    reference = parts[6]
+                    # Only store non-empty references
+                    if name and reference:
+                        references[name] = reference
+    except Exception:
+        # If parsing fails, just return empty dict
+        pass
+    
+    return references
+
 def get_contributors():
     """Extract contributors from git log."""
     log_lines = run_git(["log", "--format=%aN|%aE|%ad", "--date=short"])
@@ -43,8 +73,8 @@ def get_contributors():
 
     return contributors
 
-def generate_table(contributors):
-    """Generate markdown table."""
+def generate_table(contributors, existing_references):
+    """Generate markdown table, preserving manual Reference values."""
     header = [
         "# 🌍 Project Contributors",
         "",
@@ -57,16 +87,17 @@ def generate_table(contributors):
     rows = []
     for name, info in sorted(contributors.items(), key=lambda x: x[0].lower()):
         emails = ", ".join(sorted(info["emails"]))
-        # Default empty reference link
-        reference = ""
+        # Preserve existing reference if it exists, otherwise leave empty
+        reference = existing_references.get(name, "")
         # Use proper pluralization for commits
         commit_text = f"{info['count']} commit" if info['count'] == 1 else f"{info['count']} commits"
         rows.append(f"| {name} | {emails} | {commit_text} | {info['first']} | {info['last']} | {reference} |")
     return "\n".join(header + rows) + "\n"
 
 def main():
+    existing_references = parse_existing_references()
     contributors = get_contributors()
-    md = generate_table(contributors)
+    md = generate_table(contributors, existing_references)
     contributors_file.write_text(md, encoding="utf-8")
     print(f"✅ Updated {contributors_file} with {len(contributors)} contributors.")