Compare commits
1 Commits
fix/1474-d
...
fix/1445
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59784e620c |
116
.gitea/workflows/check-pr-changes.yml
Normal file
116
.gitea/workflows/check-pr-changes.yml
Normal file
@@ -0,0 +1,116 @@
|
||||
# .gitea/workflows/check-pr-changes.yml
|
||||
# CI workflow to prevent rubber-stamping of PRs with no changes
|
||||
# Issue #1445: process: Prevent rubber-stamping of PRs with no changes
|
||||
|
||||
name: Check PR for Changes
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
check-changes:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0 # Fetch full history for diff comparison
|
||||
|
||||
- name: Check for empty PR
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
# Get PR number from context
|
||||
PR_NUMBER="${{ github.event.pull_request.number }}"
|
||||
echo "Checking PR #$PR_NUMBER for changes..."
|
||||
|
||||
# Get the base and head commits
|
||||
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
||||
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
||||
|
||||
echo "Base SHA: $BASE_SHA"
|
||||
echo "Head SHA: $HEAD_SHA"
|
||||
|
||||
# Get diff stats
|
||||
DIFF_STATS=$(git diff --stat "$BASE_SHA" "$HEAD_SHA")
|
||||
|
||||
if [ -z "$DIFF_STATS" ]; then
|
||||
echo "❌ ERROR: PR has no changes!"
|
||||
echo ""
|
||||
echo "This PR has 0 additions, 0 deletions, and 0 files changed."
|
||||
echo "This is a 'zombie PR' that should not be merged."
|
||||
echo ""
|
||||
echo "Rubber-stamping (approving PRs with no changes) is prohibited."
|
||||
echo "Reviewers must verify that PRs contain actual changes."
|
||||
echo ""
|
||||
echo "If this is a mistake, please add actual changes to the PR."
|
||||
echo "If this PR is not needed, please close it."
|
||||
exit 1
|
||||
else
|
||||
echo "✅ PR has changes:"
|
||||
echo "$DIFF_STATS"
|
||||
|
||||
# Get detailed stats
|
||||
ADDITIONS=$(git diff --numstat "$BASE_SHA" "$HEAD_SHA" | awk '{sum+=$1} END {print sum}')
|
||||
DELETIONS=$(git diff --numstat "$BASE_SHA" "$HEAD_SHA" | awk '{sum+=$2} END {print sum}')
|
||||
FILES_CHANGED=$(git diff --numstat "$BASE_SHA" "$HEAD_SHA" | wc -l)
|
||||
|
||||
echo ""
|
||||
echo "Summary:"
|
||||
echo " Files changed: $FILES_CHANGED"
|
||||
echo " Additions: $ADDITIONS"
|
||||
echo " Deletions: $DELETIONS"
|
||||
|
||||
# Check if this is a "zombie PR" (no actual changes)
|
||||
if [ "$ADDITIONS" -eq 0 ] && [ "$DELETIONS" -eq 0 ]; then
|
||||
echo ""
|
||||
echo "⚠️ WARNING: PR has files changed but no additions or deletions!"
|
||||
echo "This might be a binary file change or permission change."
|
||||
echo "Reviewers should verify this is intentional."
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: Check for empty commits
|
||||
run: |
|
||||
# Check if there are any commits with no changes
|
||||
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
||||
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
||||
|
||||
# Get list of commits
|
||||
COMMITS=$(git log --oneline "$BASE_SHA".."$HEAD_SHA")
|
||||
|
||||
if [ -z "$COMMITS" ]; then
|
||||
echo "❌ ERROR: PR has no commits!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Commits in this PR:"
|
||||
echo "$COMMITS"
|
||||
|
||||
# Check each commit for changes
|
||||
EMPTY_COMMITS=0
|
||||
while IFS= read -r commit; do
|
||||
COMMIT_SHA=$(echo "$commit" | awk '{print $1}')
|
||||
COMMIT_MSG=$(echo "$commit" | cut -d' ' -f2-)
|
||||
|
||||
# Get parent commit
|
||||
PARENT_SHA=$(git rev-parse "$COMMIT_SHA^" 2>/dev/null || echo "")
|
||||
|
||||
if [ -n "$PARENT_SHA" ]; then
|
||||
# Check if commit has changes
|
||||
COMMIT_DIFF=$(git diff --stat "$PARENT_SHA" "$COMMIT_SHA")
|
||||
|
||||
if [ -z "$COMMIT_DIFF" ]; then
|
||||
echo "⚠️ WARNING: Commit $COMMIT_SHA has no changes!"
|
||||
echo " Message: $COMMIT_MSG"
|
||||
EMPTY_COMMITS=$((EMPTY_COMMITS + 1))
|
||||
fi
|
||||
fi
|
||||
done <<< "$COMMITS"
|
||||
|
||||
if [ "$EMPTY_COMMITS" -gt 0 ]; then
|
||||
echo ""
|
||||
echo "⚠️ Found $EMPTY_COMMITS commit(s) with no changes."
|
||||
echo "Consider squashing or amending these commits."
|
||||
fi
|
||||
136
.github/pull_request_template.md
vendored
136
.github/pull_request_template.md
vendored
@@ -1,65 +1,73 @@
|
||||
## Description
|
||||
<!-- Provide a clear description of what this PR does -->
|
||||
|
||||
## Changes Made
|
||||
<!-- List the specific changes made in this PR -->
|
||||
|
||||
### Files Changed
|
||||
<!-- List the files that were modified -->
|
||||
|
||||
### Type of Change
|
||||
<!-- Check the relevant option -->
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
- [ ] Documentation update
|
||||
- [ ] Refactoring (no functional changes)
|
||||
- [ ] Test updates
|
||||
- [ ] CI/CD changes
|
||||
|
||||
## Testing
|
||||
<!-- Describe the tests you ran to verify your changes -->
|
||||
|
||||
### Test Instructions
|
||||
<!-- Provide step-by-step instructions to test your changes -->
|
||||
|
||||
## Checklist
|
||||
<!-- Check all that apply -->
|
||||
- [ ] My code follows the style guidelines of this project
|
||||
- [ ] I have performed a self-review of my own code
|
||||
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||
- [ ] I have made corresponding changes to the documentation
|
||||
- [ ] My changes generate no new warnings
|
||||
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||
- [ ] New and existing unit tests pass locally with my changes
|
||||
- [ ] Any dependent changes have been merged and published in downstream modules
|
||||
|
||||
## Reviewer Guidelines
|
||||
<!-- IMPORTANT: Reviewers must follow these guidelines to prevent rubber-stamping -->
|
||||
|
||||
### ⚠️ Reviewers MUST verify:
|
||||
1. **PR has actual changes** - Check that the PR contains additions, deletions, or modifications
|
||||
2. **Changes match description** - Verify the changes match what's described in the PR
|
||||
3. **Code quality** - Review code for bugs, security issues, performance problems
|
||||
4. **Tests are adequate** - Ensure new code is properly tested
|
||||
5. **Documentation is updated** - Check if documentation needs updates
|
||||
|
||||
### ❌ DO NOT approve if:
|
||||
- PR has 0 additions, 0 deletions, and 0 files changed (zombie PR)
|
||||
- Changes don't match the PR description
|
||||
- Code has obvious bugs or security issues
|
||||
- No tests for new functionality
|
||||
- Documentation is missing or incorrect
|
||||
|
||||
### ✅ DO approve if:
|
||||
- PR has meaningful changes that match the description
|
||||
- Code is clean, well-tested, and documented
|
||||
- Changes follow project conventions
|
||||
- No obvious issues or risks
|
||||
|
||||
## Related Issues
|
||||
<!-- Link any related issues -->
|
||||
- Fixes #<!-- issue number -->
|
||||
- Related to #<!-- issue number -->
|
||||
|
||||
## Additional Notes
|
||||
<!-- Add any other context about the PR here -->
|
||||
|
||||
---
|
||||
|
||||
**⚠️ Before submitting your pull request:**
|
||||
|
||||
1. [x] I've read [BRANCH_PROTECTION.md](BRANCH_PROTECTION.md)
|
||||
2. [x] I've followed [CONTRIBUTING.md](CONTRIBUTING.md) guidelines
|
||||
3. [x] My changes have appropriate test coverage
|
||||
4. [x] I've updated documentation where needed
|
||||
5. [x] I've verified CI passes (where applicable)
|
||||
|
||||
**Context:**
|
||||
<Describe your changes and why they're needed>
|
||||
|
||||
**Testing:**
|
||||
<Explain how this was tested>
|
||||
|
||||
**Questions for reviewers:**
|
||||
<Ask specific questions if needed>
|
||||
## Pull Request Template
|
||||
|
||||
### Description
|
||||
[Explain your changes briefly]
|
||||
|
||||
### Checklist
|
||||
- [ ] Branch protection rules followed
|
||||
- [ ] Required reviewers: @perplexity (QA), @Timmy (hermes-agent)
|
||||
- [ ] CI passed (where applicable)
|
||||
|
||||
### Questions for Reviewers
|
||||
- [ ] Any special considerations?
|
||||
- [ ] Does this require additional documentation?
|
||||
# Pull Request Template
|
||||
|
||||
## Summary
|
||||
Briefly describe the changes in this PR.
|
||||
|
||||
## Reviewers
|
||||
- Default reviewer: @perplexity
|
||||
- Required reviewer for hermes-agent: @Timmy
|
||||
|
||||
## Branch Protection Compliance
|
||||
- [ ] PR created
|
||||
- [ ] 1+ approvals
|
||||
- [ ] ci passed (where applicable)
|
||||
- [ ] No force pushes
|
||||
- [ ] No branch deletions
|
||||
|
||||
## Specialized Owners
|
||||
- [ ] @Rockachopa (for agent-core)
|
||||
- [ ] @Timmy (for ai/)
|
||||
## Pull Request Template
|
||||
|
||||
### Summary
|
||||
- [ ] Describe the change
|
||||
- [ ] Link to related issue (e.g. `Closes #123`)
|
||||
|
||||
### Checklist
|
||||
- [ ] Branch protection rules respected
|
||||
- [ ] CI/CD passing (where applicable)
|
||||
- [ ] Code reviewed by @perplexity
|
||||
- [ ] No force pushes to main
|
||||
|
||||
### Review Requirements
|
||||
- [ ] @perplexity for all repos
|
||||
- [ ] @Timmy for hermes-agent changes
|
||||
**By submitting this PR, I confirm that:**
|
||||
1. I have actually reviewed the code changes
|
||||
2. The changes are meaningful and not a zombie PR
|
||||
3. I have tested the changes locally (if applicable)
|
||||
4. I understand that rubber-stamping (approving PRs with no changes) is prohibited
|
||||
193
bin/check_zombie_prs.py
Executable file
193
bin/check_zombie_prs.py
Executable file
@@ -0,0 +1,193 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Check for zombie PRs (PRs with no changes) to prevent rubber-stamping.
|
||||
Issue #1445: process: Prevent rubber-stamping of PRs with no changes
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.request
|
||||
import subprocess
|
||||
from typing import Dict, List, Any, Optional
|
||||
|
||||
# Configuration
|
||||
GITEA_BASE = "https://forge.alexanderwhitestone.com/api/v1"
|
||||
TOKEN_PATH = os.path.expanduser("~/.config/gitea/token")
|
||||
ORG = "Timmy_Foundation"
|
||||
|
||||
class ZombiePRChecker:
|
||||
def __init__(self):
|
||||
self.token = self._load_token()
|
||||
|
||||
def _load_token(self) -> str:
|
||||
"""Load Gitea API token."""
|
||||
try:
|
||||
with open(TOKEN_PATH, "r") as f:
|
||||
return f.read().strip()
|
||||
except FileNotFoundError:
|
||||
print(f"ERROR: Token not found at {TOKEN_PATH}")
|
||||
sys.exit(1)
|
||||
|
||||
def _api_request(self, endpoint: str) -> Any:
|
||||
"""Make authenticated Gitea API request."""
|
||||
url = f"{GITEA_BASE}{endpoint}"
|
||||
headers = {"Authorization": f"token {self.token}"}
|
||||
|
||||
req = urllib.request.Request(url, headers=headers)
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
return json.loads(resp.read())
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 404:
|
||||
return None
|
||||
error_body = e.read().decode() if e.fp else "No error body"
|
||||
print(f"API Error {e.code}: {error_body}")
|
||||
return None
|
||||
|
||||
def get_open_prs(self, repo: str) -> List[Dict]:
|
||||
"""Get open PRs for a repository."""
|
||||
endpoint = f"/repos/{ORG}/{repo}/pulls?state=open"
|
||||
prs = self._api_request(endpoint)
|
||||
return prs if isinstance(prs, list) else []
|
||||
|
||||
def get_pr_files(self, repo: str, pr_number: int) -> List[Dict]:
|
||||
"""Get files changed in a PR."""
|
||||
endpoint = f"/repos/{ORG}/{repo}/pulls/{pr_number}/files"
|
||||
files = self._api_request(endpoint)
|
||||
return files if isinstance(files, list) else []
|
||||
|
||||
def is_zombie_pr(self, repo: str, pr_number: int) -> Dict[str, Any]:
|
||||
"""Check if a PR is a zombie (no actual changes)."""
|
||||
pr_files = self.get_pr_files(repo, pr_number)
|
||||
|
||||
# Calculate total changes
|
||||
total_additions = sum(f.get("additions", 0) for f in pr_files)
|
||||
total_deletions = sum(f.get("deletions", 0) for f in pr_files)
|
||||
total_changes = sum(f.get("changes", 0) for f in pr_files)
|
||||
|
||||
# A zombie PR has no additions, deletions, or changes
|
||||
is_zombie = (total_additions == 0 and total_deletions == 0 and total_changes == 0)
|
||||
|
||||
return {
|
||||
"repo": repo,
|
||||
"pr_number": pr_number,
|
||||
"is_zombie": is_zombie,
|
||||
"files_changed": len(pr_files),
|
||||
"total_additions": total_additions,
|
||||
"total_deletions": total_deletions,
|
||||
"total_changes": total_changes,
|
||||
"files": pr_files
|
||||
}
|
||||
|
||||
def scan_repo_for_zombies(self, repo: str) -> List[Dict]:
|
||||
"""Scan a repository for zombie PRs."""
|
||||
open_prs = self.get_open_prs(repo)
|
||||
zombies = []
|
||||
|
||||
print(f"Scanning {repo} for zombie PRs...")
|
||||
print(f"Found {len(open_prs)} open PRs")
|
||||
|
||||
for pr in open_prs:
|
||||
pr_number = pr["number"]
|
||||
pr_title = pr["title"]
|
||||
|
||||
# Check if it's a zombie
|
||||
zombie_info = self.is_zombie_pr(repo, pr_number)
|
||||
|
||||
if zombie_info["is_zombie"]:
|
||||
zombie_info["title"] = pr_title
|
||||
zombie_info["author"] = pr["user"]["login"]
|
||||
zombie_info["created"] = pr["created_at"]
|
||||
zombies.append(zombie_info)
|
||||
print(f" 🧟 ZOMBIE: #{pr_number} - {pr_title}")
|
||||
else:
|
||||
print(f" ✅ OK: #{pr_number} - {pr_title} ({zombie_info['total_changes']} changes)")
|
||||
|
||||
return zombies
|
||||
|
||||
def generate_report(self, zombies_by_repo: Dict[str, List[Dict]]) -> str:
|
||||
"""Generate a report of zombie PRs found."""
|
||||
total_zombies = sum(len(zombies) for zombies in zombies_by_repo.values())
|
||||
|
||||
report = "# Zombie PR Detection Report\n\n"
|
||||
report += f"## Summary\n"
|
||||
report += f"- **Total zombie PRs found:** {total_zombies}\n"
|
||||
report += f"- **Repositories scanned:** {len(zombies_by_repo)}\n\n"
|
||||
|
||||
if total_zombies == 0:
|
||||
report += "✅ **No zombie PRs found.**\n"
|
||||
else:
|
||||
report += "⚠️ **Zombie PRs found:**\n\n"
|
||||
|
||||
for repo, zombies in zombies_by_repo.items():
|
||||
if zombies:
|
||||
report += f"### {repo}\n"
|
||||
for zombie in zombies:
|
||||
report += f"- **#{zombie['pr_number']}**: {zombie['title']}\n"
|
||||
report += f" - Author: {zombie['author']}\n"
|
||||
report += f" - Created: {zombie['created']}\n"
|
||||
report += f" - Files changed: {zombie['files_changed']}\n"
|
||||
report += f" - Total changes: {zombie['total_changes']}\n"
|
||||
report += "\n"
|
||||
|
||||
# Add recommendations
|
||||
report += "## Recommendations\n"
|
||||
report += "1. **Close zombie PRs** - PRs with no actual changes should be closed\n"
|
||||
report += "2. **Validate before merge** - CI should reject PRs with no changes\n"
|
||||
report += "3. **Prevent future zombies** - Agents should validate changes before creating PRs\n"
|
||||
report += "4. **Review process** - Reviewers must verify PRs have actual changes\n"
|
||||
|
||||
return report
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point for zombie PR checker."""
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description="Check for zombie PRs (PRs with no actual changes)")
|
||||
parser.add_argument("--repos", nargs="+",
|
||||
default=["the-nexus", "timmy-home", "timmy-config", "hermes-agent", "the-beacon"],
|
||||
help="Repositories to scan")
|
||||
parser.add_argument("--report", action="store_true", help="Generate report")
|
||||
parser.add_argument("--json", action="store_true", help="Output JSON instead of report")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
checker = ZombiePRChecker()
|
||||
|
||||
# Scan repositories for zombie PRs
|
||||
zombies_by_repo = {}
|
||||
|
||||
for repo in args.repos:
|
||||
zombies = checker.scan_repo_for_zombies(repo)
|
||||
zombies_by_repo[repo] = zombies
|
||||
|
||||
# Generate output
|
||||
if args.json:
|
||||
print(json.dumps(zombies_by_repo, indent=2))
|
||||
elif args.report:
|
||||
report = checker.generate_report(zombies_by_repo)
|
||||
print(report)
|
||||
else:
|
||||
# Default: show summary
|
||||
total_zombies = sum(len(zombies) for zombies in zombies_by_repo.values())
|
||||
|
||||
print(f"\nZombie PR Detection Complete")
|
||||
print("=" * 60)
|
||||
print(f"Total zombie PRs found: {total_zombies}")
|
||||
|
||||
if total_zombies > 0:
|
||||
print("\nZombie PRs:")
|
||||
for repo, zombies in zombies_by_repo.items():
|
||||
for zombie in zombies:
|
||||
print(f" {repo} #{zombie['pr_number']}: {zombie['title']}")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("\n✅ No zombie PRs found")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,136 +0,0 @@
|
||||
# Duplicate PR Prevention Tools
|
||||
|
||||
## Problem
|
||||
|
||||
Despite having tools to detect and clean up duplicate PRs, agents were still creating duplicate PRs for the same issue. This was incredibly ironic, especially for issue #1128 which was about cleaning up duplicate PRs.
|
||||
|
||||
## Solution
|
||||
|
||||
We've created pre-flight check tools that agents should run **before** creating a new PR. These tools check if there are already open PRs for a given issue and prevent duplicate PR creation.
|
||||
|
||||
## Tools
|
||||
|
||||
### 1. `check-existing-prs.sh` (Bash)
|
||||
|
||||
Check if PRs already exist for an issue.
|
||||
|
||||
```bash
|
||||
# Check for existing PRs for issue #1128
|
||||
./scripts/check-existing-prs.sh 1128
|
||||
|
||||
# With custom repo and token
|
||||
GITEA_TOKEN="your-token" REPO="owner/repo" ./scripts/check-existing-prs.sh 1128
|
||||
```
|
||||
|
||||
**Exit codes:**
|
||||
- `0`: No existing PRs found (safe to create new PR)
|
||||
- `1`: Existing PRs found (do not create new PR)
|
||||
- `2`: Error (API failure, missing parameters, etc.)
|
||||
|
||||
### 2. `check_existing_prs.py` (Python)
|
||||
|
||||
Python version of the check, suitable for agents that prefer Python.
|
||||
|
||||
```bash
|
||||
# Check for existing PRs for issue #1128
|
||||
python3 scripts/check_existing_prs.py 1128
|
||||
|
||||
# With custom repo and token
|
||||
python3 scripts/check_existing_prs.py 1128 "owner/repo" "your-token"
|
||||
```
|
||||
|
||||
### 3. `pr-safe.sh` (Wrapper)
|
||||
|
||||
User-friendly wrapper that provides guidance.
|
||||
|
||||
```bash
|
||||
# Check and get suggestions
|
||||
./scripts/pr-safe.sh 1128
|
||||
|
||||
# With suggested branch name
|
||||
./scripts/pr-safe.sh 1128 fix/1128-my-fix
|
||||
```
|
||||
|
||||
## Workflow Integration
|
||||
|
||||
### For Agents
|
||||
|
||||
Before creating a PR, agents should:
|
||||
|
||||
1. Run the check: `./scripts/check-existing-prs.sh <issue_number>`
|
||||
2. If exit code is `0`, proceed with PR creation
|
||||
3. If exit code is `1`, review existing PRs instead
|
||||
|
||||
### For Humans
|
||||
|
||||
Before creating a PR:
|
||||
|
||||
1. Run: `./scripts/pr-safe.sh <issue_number>`
|
||||
2. Follow the guidance provided
|
||||
|
||||
## Prevention Strategy
|
||||
|
||||
### 1. Pre-flight Checks
|
||||
|
||||
Always run a pre-flight check before creating a PR:
|
||||
|
||||
```bash
|
||||
# In your agent workflow
|
||||
if ./scripts/check-existing-prs.sh $ISSUE_NUMBER; then
|
||||
# Safe to create PR
|
||||
create_pr
|
||||
else
|
||||
# Don't create PR, review existing ones
|
||||
review_existing_prs
|
||||
fi
|
||||
```
|
||||
|
||||
### 2. GitHub Actions Integration
|
||||
|
||||
The existing `.github/workflows/pr-duplicate-check.yml` workflow can be enhanced to run these checks automatically.
|
||||
|
||||
### 3. Agent Instructions
|
||||
|
||||
Add to agent instructions:
|
||||
|
||||
```
|
||||
Before creating a PR for an issue, ALWAYS run:
|
||||
./scripts/check-existing-prs.sh <issue_number>
|
||||
|
||||
If PRs already exist, DO NOT create a new PR.
|
||||
Instead, review existing PRs and add comments or merge them.
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Check for Issue #1128
|
||||
|
||||
```bash
|
||||
$ ./scripts/check-existing-prs.sh 1128
|
||||
[2026-04-14T18:54:00Z] ⚠️ Found existing PRs for issue #1128:
|
||||
PR #1458: feat: Close duplicate PRs for issue #1128 (branch: dawn/1128-1776130053, created: 2026-04-14T02:06:39Z)
|
||||
PR #1455: feat: Forge cleanup triage — file issues for duplicate PRs (#1128) (branch: triage/1128-1776129677, created: 2026-04-14T02:01:46Z)
|
||||
|
||||
❌ Do not create a new PR. Review existing PRs first.
|
||||
```
|
||||
|
||||
### Example 2: Safe to Create PR
|
||||
|
||||
```bash
|
||||
$ ./scripts/check-existing-prs.sh 9999
|
||||
[2026-04-14T18:54:00Z] ✅ No existing PRs found for issue #9999
|
||||
Safe to create a new PR
|
||||
```
|
||||
|
||||
## Related Issues
|
||||
|
||||
- Issue #1474: [META] Still creating duplicate PRs for issue #1128 despite cleanup
|
||||
- Issue #1460: [META] I keep creating duplicate PRs for issue #1128
|
||||
- Issue #1128: [RESOLVED] Forge Cleanup — PRs Closed, Milestones Deduplicated, Policy Issues Filed
|
||||
|
||||
## Lessons Learned
|
||||
|
||||
1. **Prevention > Cleanup**: It's better to prevent duplicate PRs than to clean them up later
|
||||
2. **Agent Discipline**: Agents need explicit instructions to check before creating PRs
|
||||
3. **Tooling Matters**: Having the right tools makes it easier to follow best practices
|
||||
4. **Irony Awareness**: Be aware when you're creating the problem you're trying to solve
|
||||
189
docs/rubber-stamping-prevention.md
Normal file
189
docs/rubber-stamping-prevention.md
Normal file
@@ -0,0 +1,189 @@
|
||||
# Preventing Rubber-Stamping of PRs
|
||||
|
||||
**Issue:** #1445 - process: Prevent rubber-stamping of PRs with no changes
|
||||
**Problem:** PRs with no changes (zombie PRs) are being approved without actual review
|
||||
|
||||
## What is Rubber-Stamping?
|
||||
|
||||
Rubber-stamping occurs when:
|
||||
1. A PR has 0 additions, 0 deletions, and 0 files changed (zombie PR)
|
||||
2. Reviewers approve the PR without noticing it has no changes
|
||||
3. The PR gets merged despite adding no value
|
||||
|
||||
This is a serious process issue because:
|
||||
- It wastes reviewer time
|
||||
- It creates false sense of review quality
|
||||
- It allows zombie PRs to appear reviewed
|
||||
- It clutters the PR backlog
|
||||
|
||||
## Prevention Measures
|
||||
|
||||
### 1. CI Check (`.gitea/workflows/check-pr-changes.yml`)
|
||||
Automated check that runs on every PR:
|
||||
- Detects PRs with no changes
|
||||
- Blocks merge if PR is a zombie
|
||||
- Provides clear error messages
|
||||
|
||||
**What it checks:**
|
||||
- PR has additions, deletions, or file changes
|
||||
- Commits contain actual changes
|
||||
- No empty diffs
|
||||
|
||||
**When it runs:**
|
||||
- On PR open
|
||||
- On PR synchronize (new commits)
|
||||
- On PR reopen
|
||||
|
||||
### 2. PR Template (`.github/PULL_REQUEST_TEMPLATE.md`)
|
||||
Updated PR template with reviewer guidelines:
|
||||
- Clear checklist for reviewers
|
||||
- Explicit instructions to check for changes
|
||||
- Warning against rubber-stamping
|
||||
|
||||
**Reviewer requirements:**
|
||||
1. Verify PR has actual changes
|
||||
2. Changes match description
|
||||
3. Code quality review
|
||||
4. Tests are adequate
|
||||
5. Documentation is updated
|
||||
|
||||
### 3. Zombie PR Detection Script (`bin/check_zombie_prs.py`)
|
||||
Script to scan for zombie PRs:
|
||||
- Check all open PRs in repositories
|
||||
- Identify PRs with no changes
|
||||
- Generate reports
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
# Scan all repositories
|
||||
python bin/check_zombie_prs.py
|
||||
|
||||
# Scan specific repositories
|
||||
python bin/check_zombie_prs.py --repos the-nexus timmy-home
|
||||
|
||||
# Generate report
|
||||
python bin/check_zombie_prs.py --report
|
||||
|
||||
# JSON output
|
||||
python bin/check_zombie_prs.py --json
|
||||
```
|
||||
|
||||
## How to Use
|
||||
|
||||
### For CI/CD
|
||||
The workflow runs automatically on all PRs. No setup needed.
|
||||
|
||||
### For Developers
|
||||
1. **Before creating PR:**
|
||||
- Ensure you have actual changes
|
||||
- Test your changes locally
|
||||
- Don't create PRs with no changes
|
||||
|
||||
2. **When reviewing PRs:**
|
||||
- Check that PR has additions, deletions, or file changes
|
||||
- Verify changes match the PR description
|
||||
- Don't approve PRs with no changes
|
||||
|
||||
3. **If you find a zombie PR:**
|
||||
- Add a comment explaining it has no changes
|
||||
- Request changes or close the PR
|
||||
- Don't approve it
|
||||
|
||||
### For Agents (AI Workers)
|
||||
Before creating a PR:
|
||||
```bash
|
||||
# Check if you have changes
|
||||
git status
|
||||
git diff --stat
|
||||
|
||||
# If no changes, don't create PR
|
||||
# If changes exist, create PR
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Zombie PR Detected
|
||||
```
|
||||
❌ ERROR: PR has no changes!
|
||||
|
||||
This PR has 0 additions, 0 deletions, and 0 files changed.
|
||||
This is a 'zombie PR' that should not be merged.
|
||||
|
||||
Rubber-stamping (approving PRs with no changes) is prohibited.
|
||||
Reviewers must verify that PRs contain actual changes.
|
||||
|
||||
If this is a mistake, please add actual changes to the PR.
|
||||
If this PR is not needed, please close it.
|
||||
```
|
||||
|
||||
### Valid PR
|
||||
```
|
||||
✅ PR has changes:
|
||||
README.md | 10 ++++++++++
|
||||
1 file changed, 10 insertions(+)
|
||||
|
||||
Summary:
|
||||
Files changed: 1
|
||||
Additions: 10
|
||||
Deletions: 0
|
||||
```
|
||||
|
||||
## Related Issues
|
||||
|
||||
- **Issue #1127:** Perplexity Evening Pass triage (identified rubber-stamping)
|
||||
- **Issue #1445:** This implementation
|
||||
- **PR #359:** Example of rubber-stamping (3 approvals on empty PR)
|
||||
|
||||
## Prevention Strategy
|
||||
|
||||
### 1. **Automated Checks**
|
||||
- CI workflow blocks zombie PRs
|
||||
- Pre-commit hooks validate changes
|
||||
- Automated scanning for zombie PRs
|
||||
|
||||
### 2. **Process Guidelines**
|
||||
- Updated PR template with reviewer guidelines
|
||||
- Clear instructions to check for changes
|
||||
- Training on rubber-stamping prevention
|
||||
|
||||
### 3. **Monitoring**
|
||||
- Regular scans for zombie PRs
|
||||
- Reports on rubber-stamping incidents
|
||||
- Continuous improvement of prevention measures
|
||||
|
||||
## Files Added
|
||||
|
||||
1. `.gitea/workflows/check-pr-changes.yml` - CI workflow
|
||||
2. `.github/PULL_REQUEST_TEMPLATE.md` - Updated PR template
|
||||
3. `bin/check_zombie_prs.py` - Zombie PR detection script
|
||||
4. `docs/rubber-stamping-prevention.md` - This documentation
|
||||
|
||||
## Testing
|
||||
|
||||
Test the CI workflow:
|
||||
```bash
|
||||
# Create a test PR with no changes
|
||||
git checkout -b test/zombie-pr
|
||||
git commit --allow-empty -m "test: empty commit"
|
||||
git push origin test/zombie-pr
|
||||
# Create PR and watch CI fail
|
||||
```
|
||||
|
||||
Test the detection script:
|
||||
```bash
|
||||
python bin/check_zombie_prs.py --repos the-nexus --report
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
|
||||
This implementation provides comprehensive protection against rubber-stamping:
|
||||
1. **Automated CI checks** block zombie PRs
|
||||
2. **Updated PR template** guides reviewers
|
||||
3. **Detection script** identifies existing zombie PRs
|
||||
4. **Documentation** explains the problem and solution
|
||||
|
||||
**Result:** No more rubber-stamping of PRs with no changes.
|
||||
|
||||
## License
|
||||
|
||||
Part of the Timmy Foundation project.
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# check-existing-prs.sh — Check if PRs already exist for an issue
|
||||
#
|
||||
# This script checks if there are already open PRs for a given issue
|
||||
# before creating a new one. This prevents duplicate PRs.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/check-existing-prs.sh <issue_number>
|
||||
#
|
||||
# Exit codes:
|
||||
# 0 - No existing PRs found (safe to create new PR)
|
||||
# 1 - Existing PRs found (do not create new PR)
|
||||
# 2 - Error (API failure, missing parameters, etc.)
|
||||
#
|
||||
# Designed for issue #1474: Prevent duplicate PRs
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
set -euo pipefail
|
||||
|
||||
# ─── Configuration ──────────────────────────────────────────
|
||||
GITEA_URL="${GITEA_URL:-https://forge.alexanderwhitestone.com}"
|
||||
GITEA_TOKEN="${GITEA_TOKEN:?Set GITEA_TOKEN env var}"
|
||||
REPO="${REPO:-Timmy_Foundation/the-nexus}"
|
||||
ISSUE_NUMBER="${1:?Usage: $0 <issue_number>}"
|
||||
|
||||
API="$GITEA_URL/api/v1"
|
||||
AUTH="Authorization: token $GITEA_TOKEN"
|
||||
|
||||
log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*"; }
|
||||
|
||||
# ─── Validate inputs ──────────────────────────────────────
|
||||
if ! [[ "$ISSUE_NUMBER" =~ ^[0-9]+$ ]]; then
|
||||
log "ERROR: Issue number must be a positive integer"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# ─── Fetch open PRs ────────────────────────────────────────
|
||||
log "Checking for existing PRs for issue #$ISSUE_NUMBER in $REPO"
|
||||
|
||||
OPEN_PRS=$(curl -s -H "$AUTH" "$API/repos/$REPO/pulls?state=open&limit=100")
|
||||
|
||||
if [ -z "$OPEN_PRS" ] || [ "$OPEN_PRS" = "null" ]; then
|
||||
log "No open PRs found or API error"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ─── Check for PRs referencing this issue ──────────────────
|
||||
# Look for PRs that mention the issue number in title or body
|
||||
MATCHING_PRS=$(echo "$OPEN_PRS" | jq -r --arg issue "#$ISSUE_NUMBER" '
|
||||
.[] |
|
||||
select(
|
||||
(.title | test($issue; "i")) or
|
||||
(.body | test($issue; "i"))
|
||||
) |
|
||||
"PR #\(.number): \(.title) (branch: \(.head.ref), created: \(.created_at))"
|
||||
')
|
||||
|
||||
if [ -z "$MATCHING_PRS" ]; then
|
||||
log "✅ No existing PRs found for issue #$ISSUE_NUMBER"
|
||||
log "Safe to create a new PR"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ─── Report existing PRs ───────────────────────────────────
|
||||
log "⚠️ Found existing PRs for issue #$ISSUE_NUMBER:"
|
||||
echo "$MATCHING_PRS"
|
||||
echo ""
|
||||
log "❌ Do not create a new PR. Review existing PRs first."
|
||||
log ""
|
||||
log "Options:"
|
||||
log " 1. Review and merge an existing PR"
|
||||
log " 2. Close duplicates and keep the best one"
|
||||
log " 3. Add comments to existing PRs instead of creating new ones"
|
||||
log ""
|
||||
log "To see details of existing PRs:"
|
||||
log " curl -H \"Authorization: token \$GITEA_TOKEN\" \"$API/repos/$REPO/pulls?state=open\" | jq '.[] | select(.title | test(\"#$ISSUE_NUMBER\"; \"i\"))'"
|
||||
|
||||
exit 1
|
||||
@@ -1,148 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Check if PRs already exist for an issue before creating a new one.
|
||||
|
||||
This script prevents duplicate PRs by checking if there are already
|
||||
open PRs for a given issue.
|
||||
|
||||
Usage:
|
||||
python3 scripts/check_existing_prs.py <issue_number>
|
||||
|
||||
Exit codes:
|
||||
0 - No existing PRs found (safe to create new PR)
|
||||
1 - Existing PRs found (do not create new PR)
|
||||
2 - Error (API failure, missing parameters, etc.)
|
||||
|
||||
Designed for issue #1474: Prevent duplicate PRs
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def check_existing_prs(issue_number: int, repo: str = None, token: str = None) -> int:
|
||||
"""
|
||||
Check if PRs already exist for an issue.
|
||||
|
||||
Args:
|
||||
issue_number: The issue number to check
|
||||
repo: Repository in format "owner/repo" (default: from env or "Timmy_Foundation/the-nexus")
|
||||
token: Gitea API token (default: from GITEA_TOKEN env var)
|
||||
|
||||
Returns:
|
||||
0: No existing PRs found (safe to create new PR)
|
||||
1: Existing PRs found (do not create new PR)
|
||||
2: Error (API failure, missing parameters, etc.)
|
||||
"""
|
||||
# Get configuration from environment
|
||||
gitea_url = os.environ.get('GITEA_URL', 'https://forge.alexanderwhitestone.com')
|
||||
token = token or os.environ.get('GITEA_TOKEN')
|
||||
repo = repo or os.environ.get('REPO', 'Timmy_Foundation/the-nexus')
|
||||
|
||||
if not token:
|
||||
print("ERROR: GITEA_TOKEN environment variable not set", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
# Validate issue number
|
||||
if not isinstance(issue_number, int) or issue_number <= 0:
|
||||
print("ERROR: Issue number must be a positive integer", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
# Build API URL
|
||||
api_url = f"{gitea_url}/api/v1/repos/{repo}/pulls?state=open&limit=100"
|
||||
|
||||
# Make API request
|
||||
try:
|
||||
req = urllib.request.Request(api_url, headers={
|
||||
'Authorization': f'token {token}',
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
prs = json.loads(resp.read())
|
||||
|
||||
except urllib.error.URLError as e:
|
||||
print(f"ERROR: Failed to fetch PRs: {e}", file=sys.stderr)
|
||||
return 2
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"ERROR: Failed to parse API response: {e}", file=sys.stderr)
|
||||
return 2
|
||||
except Exception as e:
|
||||
print(f"ERROR: Unexpected error: {e}", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
# Check for PRs referencing this issue
|
||||
issue_ref = f"#{issue_number}"
|
||||
matching_prs = []
|
||||
|
||||
for pr in prs:
|
||||
title = pr.get('title', '')
|
||||
body = pr.get('body', '') or ''
|
||||
|
||||
# Check if issue is referenced in title or body
|
||||
if issue_ref in title or issue_ref in body:
|
||||
matching_prs.append(pr)
|
||||
|
||||
# Report results
|
||||
timestamp = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
if not matching_prs:
|
||||
print(f"[{timestamp}] ✅ No existing PRs found for issue #{issue_number}")
|
||||
print("Safe to create a new PR")
|
||||
return 0
|
||||
|
||||
# Found existing PRs
|
||||
print(f"[{timestamp}] ⚠️ Found existing PRs for issue #{issue_number}:")
|
||||
print()
|
||||
|
||||
for pr in matching_prs:
|
||||
pr_number = pr.get('number')
|
||||
pr_title = pr.get('title')
|
||||
pr_branch = pr.get('head', {}).get('ref', 'unknown')
|
||||
pr_created = pr.get('created_at', 'unknown')
|
||||
pr_url = pr.get('html_url', 'unknown')
|
||||
|
||||
print(f" PR #{pr_number}: {pr_title}")
|
||||
print(f" Branch: {pr_branch}")
|
||||
print(f" Created: {pr_created}")
|
||||
print(f" URL: {pr_url}")
|
||||
print()
|
||||
|
||||
print("❌ Do not create a new PR. Review existing PRs first.")
|
||||
print()
|
||||
print("Options:")
|
||||
print(" 1. Review and merge an existing PR")
|
||||
print(" 2. Close duplicates and keep the best one")
|
||||
print(" 3. Add comments to existing PRs instead of creating new ones")
|
||||
print()
|
||||
print("To see details of existing PRs:")
|
||||
print(f' curl -H "Authorization: token $GITEA_TOKEN" "{gitea_url}/api/v1/repos/{repo}/pulls?state=open" | jq \'.[] | select(.title | test("#{issue_number}"; "i"))\'')
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python3 check_existing_prs.py <issue_number>", file=sys.stderr)
|
||||
print(" python3 check_existing_prs.py <issue_number> [repo] [token]", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
try:
|
||||
issue_number = int(sys.argv[1])
|
||||
except ValueError:
|
||||
print("ERROR: Issue number must be an integer", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
repo = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
token = sys.argv[3] if len(sys.argv) > 3 else None
|
||||
|
||||
return check_existing_prs(issue_number, repo, token)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
@@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# pr-safe.sh — Safe PR creation wrapper
|
||||
#
|
||||
# This script checks for existing PRs before creating a new one.
|
||||
# It's a wrapper around check-existing-prs.sh that provides
|
||||
# a user-friendly interface.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/pr-safe.sh <issue_number> [branch_name]
|
||||
#
|
||||
# If branch_name is not provided, it will suggest one based on
|
||||
# the issue number and current timestamp.
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
set -euo pipefail
|
||||
|
||||
ISSUE_NUMBER="${1:?Usage: $0 <issue_number> [branch_name]}"
|
||||
BRANCH_NAME="${2:-}"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
echo "🔍 Checking for existing PRs for issue #$ISSUE_NUMBER..."
|
||||
echo ""
|
||||
|
||||
# Run the check
|
||||
if "$SCRIPT_DIR/check-existing-prs.sh" "$ISSUE_NUMBER"; then
|
||||
echo ""
|
||||
echo "✅ Safe to create a new PR for issue #$ISSUE_NUMBER"
|
||||
|
||||
if [ -z "$BRANCH_NAME" ]; then
|
||||
TIMESTAMP=$(date +%s)
|
||||
BRANCH_NAME="fix/$ISSUE_NUMBER-$TIMESTAMP"
|
||||
echo "📝 Suggested branch name: $BRANCH_NAME"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "To create a PR:"
|
||||
echo " 1. Create branch: git checkout -b $BRANCH_NAME"
|
||||
echo " 2. Make your changes"
|
||||
echo " 3. Commit: git commit -m 'fix: Description (#$ISSUE_NUMBER)'"
|
||||
echo " 4. Push: git push -u origin $BRANCH_NAME"
|
||||
echo " 5. Create PR via API or web interface"
|
||||
else
|
||||
echo ""
|
||||
echo "❌ Cannot create new PR for issue #$ISSUE_NUMBER"
|
||||
echo " Existing PRs found. Review them first."
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user