Files
the-nexus/scripts
Alexander Whitestone 1fc0141708
Some checks failed
Review Approval Gate / verify-review (pull_request) Failing after 8s
CI / test (pull_request) Failing after 53s
CI / validate (pull_request) Failing after 27s
feat: Add duplicate PR prevention tools (#1128)
## Summary
Created tools to prevent duplicate PRs in the-nexus repository.

## Problem
The repository has a problem with duplicate PRs. Multiple agents create PRs
for the same issue, resulting in confusion, wasted resources, and cluttered
PR board.

## Solution
Created scripts and documentation to prevent duplicate PRs:

### Scripts
1. **scripts/check-existing-prs.sh**: Checks for existing PRs before creating new ones
   - Usage: ./scripts/check-existing-prs.sh <issue_number>
   - Exits with code 0 if no PRs exist (safe to create new PR)
   - Exits with code 1 if PRs exist (warning to check first)

### Documentation
1. **docs/duplicate-pr-prevention.md**: Comprehensive guide to prevent duplicate PRs
2. **docs/cleanup-summary.md**: Summary of cleanup efforts for issue #1128

## Usage

### Before Creating a PR
```bash
# Check for existing PRs before creating new ones
./scripts/check-existing-prs.sh 1128
```

### If PRs Exist
1. Review existing PRs to see if they address your issue
2. If yes, consider contributing to the existing PR instead
3. If no, create a new PR but be aware of potential conflicts

### To Close Duplicate PRs
```bash
# Close duplicate PRs (dry run)
./scripts/close-duplicate-prs.sh --dry-run

# Close duplicate PRs (actually close)
./scripts/close-duplicate-prs.sh --close
```

## Current State
- 2 PRs for issue #1128 (#1458, #1455)
- Most duplicate PRs have been closed
- Issues filed for remaining cleanup (#1463, #1454, #1453)

## Prevention Workflow
1. **Before creating a PR**: Run `check-existing-prs.sh`
2. **If PRs exist**: Review them first
3. **Use cleanup scripts**: Regularly close duplicates
4. **Document**: When creating a PR, document why it's different

Issue: #1128
2026-04-14 07:42:44 -04:00
..
2026-04-12 12:17:42 +00:00
2026-04-12 12:17:43 +00:00

Scripts

cleanup-duplicate-prs.sh

Automated detection and cleanup of duplicate open PRs.

Purpose

This script identifies PRs that are duplicates (same issue number or very similar titles) and closes the older ones. It's designed to help maintain a clean PR board and prevent confusion from duplicate work.

Features

  • Issue-based grouping: Groups PRs by issue number extracted from titles
  • Date-based selection: Keeps the newest PR, closes older duplicates
  • Dry-run mode: Shows what would be done without making changes
  • Stale PR detection: Identifies PRs older than 30 days with no activity
  • Explanatory comments: Adds comments when closing PRs to explain why

Usage

# Dry run (default) - shows what would be done
./scripts/cleanup-duplicate-prs.sh

# Actually close duplicates
./scripts/cleanup-duplicate-prs.sh --close

# Set environment variables
export GITEA_TOKEN="your_token_here"
export REPO="Timmy_Foundation/the-nexus"
export GITEA_URL="https://forge.alexanderwhitestone.com"

Configuration

The script uses the following environment variables:

Variable Default Description
GITEA_TOKEN (required) Gitea API token with repo access
GITEA_URL https://forge.alexanderwhitestone.com Gitea instance URL
REPO Timmy_Foundation/the-nexus Repository in owner/repo format
DRY_RUN true Set to false to actually close PRs

How It Works

  1. Fetch open PRs: Gets all open PRs from the repository
  2. Extract issue numbers: Parses issue numbers from PR titles (e.g., #123)
  3. Group by issue: Groups PRs that address the same issue
  4. Identify duplicates: Finds issues with multiple open PRs
  5. Select newest: For each duplicate group, keeps the newest PR
  6. Close older PRs: Closes older duplicates with explanatory comments
  7. Check for stale PRs: Identifies PRs older than 30 days

Example Output

[2026-04-14T00:57:05Z] Checking open PRs for Timmy_Foundation/the-nexus (dry_run: true)
[2026-04-14T00:57:17Z] Found 14 open PRs
[2026-04-14T00:57:17Z] Issue #1338 has 2 open PRs
[2026-04-14T00:57:17Z] Keeping PR #1392 (newest)
[2026-04-14T00:57:17Z] DRY RUN: Would close PR #1388
[2026-04-14T00:57:17Z] Issue #1354 has 2 open PRs
[2026-04-14T00:57:17Z] Keeping PR #1391 (newest)
[2026-04-14T00:57:17Z] DRY RUN: Would close PR #1384
[2026-04-14T00:57:17Z] Cleanup complete:
[2026-04-14T00:57:17Z]   Duplicate issue groups found: 4
[2026-04-14T00:57:17Z]   PRs closed: 0
[2026-04-14T00:57:17Z]   Dry run: true

Safety Features

  • Dry-run by default: Won't close PRs unless explicitly told to
  • Explanatory comments: Adds comments before closing to explain why
  • Newest PR preserved: Always keeps the most recent PR for each issue
  • No force deletion: Only closes PRs, doesn't delete branches

Integration

This script can be integrated into CI/CD pipelines or run manually as part of regular maintenance. It's designed to be run weekly to keep the PR board clean.

  • Issue #1128: Forge Cleanup — PRs Closed, Milestones Deduplicated, Policy Issues Filed
  • Issue #1127: Evening triage pass (predecessor to #1128)