refactor(contributors): update contributors script to handle prompt removals

This commit is contained in:
Fatih Kadir Akın
2025-12-14 00:08:40 +03:00
parent 11315c04b7
commit c79e945801
2 changed files with 60 additions and 23 deletions

View File

@@ -71,10 +71,19 @@ print(f"Found {len(remote_prompts)} remote prompts")
if not fieldnames:
fieldnames = remote_fieldnames
# Find new and updated prompts
# Build set of remote prompt acts for quick lookup
remote_acts = set()
for row in remote_prompts:
act = row.get('act', '').strip()
if act:
remote_acts.add(act)
# Find new, updated, and deleted prompts
new_prompts = []
updated_prompts = []
deleted_prompts = []
# Check for new and updated
for row in remote_prompts:
act = row.get('act', '').strip()
if not act:
@@ -90,10 +99,16 @@ for row in remote_prompts:
if content_changed or contributors_changed:
updated_prompts.append((row, local_row))
# Check for deleted (in local but not in remote)
for act, local_row in local_prompts.items():
if act not in remote_acts:
deleted_prompts.append(local_row)
print(f"Found {len(new_prompts)} new prompts to add")
print(f"Found {len(updated_prompts)} updated prompts to modify")
print(f"Found {len(deleted_prompts)} prompts to remove (unlisted/deleted)")
if not new_prompts and not updated_prompts:
if not new_prompts and not updated_prompts and not deleted_prompts:
print("\nNo changes detected. Already up to date!")
import sys
sys.exit(2) # Exit code 2 = no changes
@@ -208,7 +223,49 @@ else:
co_authors_str = f" (+ {', '.join(co_authors)})" if co_authors else ""
print(f"[NEW {i}/{len(new_prompts)}] {primary_author}{co_authors_str}: {act}")
print(f"\nDone! Created {len(new_prompts)} new commits, {len(updated_prompts)} update commits.")
# Process deleted prompts (remove from CSV, commit with original author)
if deleted_prompts:
print("\nRemoving unlisted/deleted prompts...")
for i, row in enumerate(deleted_prompts, 1):
contributor_field = row.get('contributor', '').strip()
act = row.get('act', 'Unknown')
primary_author, co_authors = parse_contributors(contributor_field)
email = f"{primary_author}@users.noreply.github.com"
# Remove this prompt from local_prompts
if act in local_prompts:
del local_prompts[act]
# Rewrite CSV without the deleted prompt
with open(csv_file, 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for remaining_act, remaining_row in local_prompts.items():
writer.writerow(remaining_row)
# Stage and commit
subprocess.run(['git', 'add', csv_file], check=True)
env = os.environ.copy()
env['GIT_AUTHOR_NAME'] = primary_author
env['GIT_AUTHOR_EMAIL'] = email
env['GIT_COMMITTER_NAME'] = primary_author
env['GIT_COMMITTER_EMAIL'] = email
commit_msg = build_commit_message('Remove', act, co_authors)
subprocess.run([
'git', 'commit',
'-m', commit_msg,
f'--author={primary_author} <{email}>'
], env=env, check=True)
co_authors_str = f" (+ {', '.join(co_authors)})" if co_authors else ""
print(f"[REMOVE {i}/{len(deleted_prompts)}] {primary_author}{co_authors_str}: {act}")
print(f"\nDone! Created {len(new_prompts)} new, {len(updated_prompts)} update, {len(deleted_prompts)} remove commits.")
PYTHON_SCRIPT
PYTHON_EXIT=$?