diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml index 8a8045b5..64072958 100644 --- a/.github/workflows/update-contributors.yml +++ b/.github/workflows/update-contributors.yml @@ -34,26 +34,6 @@ jobs: chmod +x scripts/generate-contributors.sh ./scripts/generate-contributors.sh - - name: Sync prompts.csv from API (removes unlisted prompts) - env: - PROMPTS_API_URL: "https://prompts.chat" - run: | - if [ -n "$PROMPTS_API_URL" ]; then - echo "Fetching prompts.csv from API..." - curl -s "${PROMPTS_API_URL}/prompts.csv" -o prompts.csv.new - if [ -s prompts.csv.new ]; then - mv prompts.csv.new prompts.csv - git add prompts.csv - git diff --cached --quiet || git commit -m "Update prompts.csv (sync from API)" - echo "prompts.csv updated from API" - else - echo "Warning: Empty response from API, keeping existing prompts.csv" - rm -f prompts.csv.new - fi - else - echo "PROMPTS_API_URL not set, skipping prompts.csv sync" - fi - - name: Push changes run: | git push origin main --force-with-lease diff --git a/scripts/generate-contributors.sh b/scripts/generate-contributors.sh index 60306362..a8b9c37d 100755 --- a/scripts/generate-contributors.sh +++ b/scripts/generate-contributors.sh @@ -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=$?