Compare commits
1 Commits
fix/1542
...
fix/1474-d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1ebfe00cf |
9
app.js
9
app.js
@@ -714,11 +714,6 @@ async function init() {
|
||||
camera = new THREE.PerspectiveCamera(65, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||
camera.position.copy(playerPos);
|
||||
|
||||
// Initialize avatar customization
|
||||
if (window.AvatarCustomization) {
|
||||
window.AvatarCustomization.init(scene, camera);
|
||||
}
|
||||
|
||||
updateLoad(20);
|
||||
|
||||
createSkybox();
|
||||
@@ -3562,10 +3557,6 @@ function gameLoop() {
|
||||
|
||||
if (composer) { composer.render(); } else { renderer.render(scene, camera); }
|
||||
|
||||
// Update avatar position
|
||||
if (window.AvatarCustomization && playerPos) {
|
||||
window.AvatarCustomization.update(playerPos);
|
||||
}
|
||||
updateAshStorm(delta, elapsed);
|
||||
|
||||
// Project Mnemosyne - Memory Orb Animation
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/* Avatar Customization */
|
||||
.avatar-name-tag {
|
||||
position: fixed;
|
||||
transform: translate(-50%, -100%);
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
color: #00ffcc;
|
||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||
font-size: 12px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid rgba(0, 255, 204, 0.3);
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
white-space: nowrap;
|
||||
text-shadow: 0 0 6px rgba(0, 255, 204, 0.5);
|
||||
}
|
||||
|
||||
.avatar-color-picker {
|
||||
position: fixed;
|
||||
top: 60px;
|
||||
right: 16px;
|
||||
background: rgba(10, 15, 26, 0.95);
|
||||
border: 1px solid rgba(0, 255, 204, 0.3);
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
z-index: 1000;
|
||||
min-width: 200px;
|
||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
|
||||
.avatar-color-picker.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.avatar-picker-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
color: #00ffcc;
|
||||
}
|
||||
|
||||
.avatar-picker-close {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #666;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.avatar-picker-close:hover { color: #ff3333; }
|
||||
|
||||
.avatar-picker-name {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.avatar-picker-name label {
|
||||
display: block;
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
text-transform: uppercase;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.avatar-picker-name input {
|
||||
width: 100%;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(0, 255, 204, 0.2);
|
||||
border-radius: 4px;
|
||||
color: #e0e0e0;
|
||||
padding: 6px 8px;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
}
|
||||
.avatar-picker-name input:focus {
|
||||
border-color: rgba(0, 255, 204, 0.5);
|
||||
}
|
||||
|
||||
.avatar-picker-colors label {
|
||||
display: block;
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
text-transform: uppercase;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.avatar-color-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.avatar-color-swatch {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid transparent;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s, transform 0.15s;
|
||||
}
|
||||
.avatar-color-swatch:hover {
|
||||
transform: scale(1.15);
|
||||
}
|
||||
.avatar-color-swatch.active {
|
||||
border-color: white;
|
||||
box-shadow: 0 0 8px currentColor;
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
/**
|
||||
* Avatar Customization Module for The Nexus
|
||||
*
|
||||
* Provides:
|
||||
* - Visible avatar mesh (capsule shape)
|
||||
* - Color picker with 8 presets
|
||||
* - Name tag above avatar
|
||||
* - localStorage persistence
|
||||
*
|
||||
* Usage:
|
||||
* AvatarCustomization.init(scene, camera);
|
||||
* AvatarCustomization.setColor('#ff6600');
|
||||
* AvatarCustomization.setName('Timmy');
|
||||
*/
|
||||
|
||||
const AvatarCustomization = (() => {
|
||||
let avatarMesh = null;
|
||||
let nameTagDiv = null;
|
||||
let colorPickerPanel = null;
|
||||
let currentColor = '#00ffcc';
|
||||
let currentName = 'Visitor';
|
||||
let _scene = null;
|
||||
let _camera = null;
|
||||
|
||||
const STORAGE_KEY = 'nexus-avatar-prefs';
|
||||
const PRESET_COLORS = [
|
||||
{ name: 'Teal', hex: '#00ffcc' },
|
||||
{ name: 'Cyan', hex: '#00ccff' },
|
||||
{ name: 'Purple', hex: '#9966ff' },
|
||||
{ name: 'Pink', hex: '#ff66aa' },
|
||||
{ name: 'Orange', hex: '#ff8833' },
|
||||
{ name: 'Gold', hex: '#ffcc00' },
|
||||
{ name: 'Red', hex: '#ff3333' },
|
||||
{ name: 'Green', hex: '#33ff66' },
|
||||
];
|
||||
|
||||
function loadPrefs() {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (raw) {
|
||||
const prefs = JSON.parse(raw);
|
||||
if (prefs.color) currentColor = prefs.color;
|
||||
if (prefs.name) currentName = prefs.name;
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
function savePrefs() {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
||||
color: currentColor,
|
||||
name: currentName,
|
||||
}));
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
function createAvatarMesh(color) {
|
||||
const geo = new THREE.CapsuleGeometry(0.3, 0.8, 8, 16);
|
||||
const mat = new THREE.MeshStandardMaterial({
|
||||
color: new THREE.Color(color),
|
||||
emissive: new THREE.Color(color).multiplyScalar(0.3),
|
||||
metalness: 0.3,
|
||||
roughness: 0.5,
|
||||
});
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.position.set(0, 1.2, 0);
|
||||
mesh.castShadow = true;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
function updateAvatarColor(hex) {
|
||||
currentColor = hex;
|
||||
if (avatarMesh) {
|
||||
avatarMesh.material.color.set(hex);
|
||||
avatarMesh.material.emissive.set(new THREE.Color(hex).multiplyScalar(0.3));
|
||||
}
|
||||
document.querySelectorAll('.avatar-color-swatch').forEach(el => {
|
||||
el.classList.toggle('active', el.dataset.color === hex);
|
||||
});
|
||||
savePrefs();
|
||||
}
|
||||
|
||||
function createNameTag(name) {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'avatar-name-tag';
|
||||
div.textContent = name;
|
||||
document.body.appendChild(div);
|
||||
return div;
|
||||
}
|
||||
|
||||
function updateNameTagPosition() {
|
||||
if (!nameTagDiv || !_camera) return;
|
||||
const pos = new THREE.Vector3(0, 2.4, 0);
|
||||
if (avatarMesh && avatarMesh.parent) {
|
||||
pos.add(avatarMesh.parent.position);
|
||||
}
|
||||
pos.project(_camera);
|
||||
const x = (pos.x * 0.5 + 0.5) * window.innerWidth;
|
||||
const y = (-pos.y * 0.5 + 0.5) * window.innerHeight;
|
||||
nameTagDiv.style.left = x + 'px';
|
||||
nameTagDiv.style.top = y + 'px';
|
||||
nameTagDiv.style.display = pos.z < 1 ? 'block' : 'none';
|
||||
}
|
||||
|
||||
function updateNameTagText(name) {
|
||||
currentName = name;
|
||||
if (nameTagDiv) nameTagDiv.textContent = name;
|
||||
savePrefs();
|
||||
}
|
||||
|
||||
function createColorPicker() {
|
||||
const panel = document.createElement('div');
|
||||
panel.id = 'avatar-color-picker';
|
||||
panel.className = 'avatar-color-picker hidden';
|
||||
panel.innerHTML = '<div class="avatar-picker-header">' +
|
||||
'<span>Avatar</span>' +
|
||||
'<button class="avatar-picker-close">×</button></div>' +
|
||||
'<div class="avatar-picker-name"><label>Name</label>' +
|
||||
'<input type="text" id="avatar-name-input" maxlength="20" placeholder="Your name" /></div>' +
|
||||
'<div class="avatar-picker-colors"><label>Color</label>' +
|
||||
'<div class="avatar-color-grid">' +
|
||||
PRESET_COLORS.map(c => '<button class="avatar-color-swatch ' +
|
||||
(c.hex === currentColor ? 'active' : '') +
|
||||
'" data-color="' + c.hex + '" style="background:' + c.hex +
|
||||
'" title="' + c.name + '"></button>').join('') +
|
||||
'</div></div>';
|
||||
document.body.appendChild(panel);
|
||||
|
||||
panel.querySelector('.avatar-picker-close').addEventListener('click', () => {
|
||||
panel.classList.add('hidden');
|
||||
});
|
||||
panel.querySelectorAll('.avatar-color-swatch').forEach(el => {
|
||||
el.addEventListener('click', () => updateAvatarColor(el.dataset.color));
|
||||
});
|
||||
const nameInput = panel.querySelector('#avatar-name-input');
|
||||
nameInput.value = currentName;
|
||||
nameInput.addEventListener('input', (e) => {
|
||||
updateNameTagText(e.target.value || 'Visitor');
|
||||
});
|
||||
return panel;
|
||||
}
|
||||
|
||||
function toggleColorPicker() {
|
||||
if (!colorPickerPanel) return;
|
||||
colorPickerPanel.classList.toggle('hidden');
|
||||
const nameInput = colorPickerPanel.querySelector('#avatar-name-input');
|
||||
if (nameInput && !colorPickerPanel.classList.contains('hidden')) {
|
||||
nameInput.value = currentName;
|
||||
nameInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function update(playerPos) {
|
||||
if (!avatarMesh) return;
|
||||
avatarMesh.position.set(playerPos.x, playerPos.y - 0.8, playerPos.z);
|
||||
updateNameTagPosition();
|
||||
}
|
||||
|
||||
function init(sceneRef, cameraRef) {
|
||||
_scene = sceneRef;
|
||||
_camera = cameraRef;
|
||||
loadPrefs();
|
||||
avatarMesh = createAvatarMesh(currentColor);
|
||||
_scene.add(avatarMesh);
|
||||
nameTagDiv = createNameTag(currentName);
|
||||
colorPickerPanel = createColorPicker();
|
||||
|
||||
const hudRight = document.querySelector('.hud-top-right');
|
||||
if (hudRight) {
|
||||
const btn = document.createElement('button');
|
||||
btn.id = 'avatar-customize-btn';
|
||||
btn.className = 'hud-icon-btn';
|
||||
btn.title = 'Customize Avatar';
|
||||
btn.innerHTML = '<span class="hud-icon">🎨</span>';
|
||||
btn.addEventListener('click', toggleColorPicker);
|
||||
hudRight.insertBefore(btn, hudRight.firstChild);
|
||||
}
|
||||
console.log('[AvatarCustomization] Initialized —', currentColor, currentName);
|
||||
}
|
||||
|
||||
return { init, update, setColor: updateAvatarColor, setName: updateNameTagText, toggleColorPicker };
|
||||
})();
|
||||
|
||||
window.AvatarCustomization = AvatarCustomization;
|
||||
136
docs/duplicate-pr-prevention.md
Normal file
136
docs/duplicate-pr-prevention.md
Normal file
@@ -0,0 +1,136 @@
|
||||
# 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
|
||||
@@ -23,7 +23,6 @@
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&family=Orbitron:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="./style.css">
|
||||
<link rel="stylesheet" href="./avatar-customization.css">
|
||||
<link rel="manifest" href="./manifest.json">
|
||||
<script type="importmap">
|
||||
{
|
||||
@@ -396,7 +395,6 @@
|
||||
<div id="memory-connections-panel" class="memory-connections-panel" style="display:none;" aria-label="Memory Connections Panel"></div>
|
||||
|
||||
<script src="./boot.js"></script>
|
||||
<script src="./avatar-customization.js"></script>
|
||||
<script>
|
||||
function openMemoryFilter() { renderFilterList(); document.getElementById('memory-filter').style.display = 'flex'; }
|
||||
function closeMemoryFilter() { document.getElementById('memory-filter').style.display = 'none'; }
|
||||
|
||||
78
scripts/check-existing-prs.sh
Executable file
78
scripts/check-existing-prs.sh
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/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
|
||||
148
scripts/check_existing_prs.py
Executable file
148
scripts/check_existing_prs.py
Executable file
@@ -0,0 +1,148 @@
|
||||
#!/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())
|
||||
48
scripts/pr-safe.sh
Executable file
48
scripts/pr-safe.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/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