Add PR review and merge capabilities for repository owners

Implemented comprehensive PR management for repo owners across GitHub, GitLab, and Nostr:

**For Repository Owners (viewing their own repos):**
- See ALL incoming PRs/patches from contributors, not just their own
- "Review" button to checkout PR branch and preview changes live
- Merge button to merge PRs directly from UI
- Works for GitHub, GitLab, and Nostr repositories

**For Contributors (viewing others' repos):**
- See only their own PRs/patches
- "Merged" badge displayed when PR has been merged
- State tracking via NIP-34 status events (kind 1630-1633) for Nostr

**PR List Enhancements:**
- Show author (display "you" for own PRs, username for others)
- Color coding: green for open, purple for merged
- Conditional actions based on ownership and state
- Different section titles: "Incoming PRs/Patches" vs "Your PRs/Patches"

**Technical Implementation:**
- Extended usePullRequests to detect repo ownership via pubkey/username
- Query all PRs when user is owner, filter to user's PRs otherwise
- For Nostr: query status events to determine merged/closed state
- Updated MergeDialog to accept pre-filled source/target branches
- Added isOwner and authorPubkey fields to PullRequest interface

This enables full PR workflow in Shakespeare: review, preview, and merge contributions.
This commit is contained in:
shakespeare.diy committed 2025-10-15 00:56:08 -05:00
1 parent b88e2ab4f8
commit 0318a8c836
3 files changed
+200 -95

No files matched your search

+69 -16
View File
@@ -982,34 +982,87 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
{!isLoadingPRs && pullRequests && pullRequests.length > 0 && (
<div className="space-y-2 mb-3">
<div className="text-xs font-medium text-muted-foreground mb-2">
{originUrl.startsWith('nostr://') ? 'Your Patches' : 'Your Open PRs'}
{pullRequests.some(pr => !pr.isOwner)
? (originUrl.startsWith('nostr://') ? 'Incoming Patches' : 'Incoming PRs')
: (originUrl.startsWith('nostr://') ? 'Your Patches' : 'Your Open PRs')
}
</div>
{pullRequests.map((pr) => (
<div
key={pr.id}
className="flex items-start gap-3 p-3 rounded-md border bg-muted/20 hover:bg-muted/40 transition-colors"
>
<GitPullRequest className="h-4 w-4 text-green-600 mt-0.5 shrink-0" />
<GitPullRequest className={cn(
"h-4 w-4 mt-0.5 shrink-0",
pr.state === 'merged' ? 'text-purple-600' : 'text-green-600'
)} />
<div className="flex-1 min-w-0">
<div className="flex items-start justify-between gap-2">
<div className="flex-1 min-w-0">
<h4 className="text-sm font-medium truncate">
{pr.title}
</h4>
<div className="flex items-center gap-2">
<h4 className="text-sm font-medium truncate">
{pr.title}
</h4>
{pr.state === 'merged' && (
<Badge variant="secondary" className="text-xs">
Merged
</Badge>
)}
</div>
<p className="text-xs text-muted-foreground mt-1">
#{pr.number} • {pr.sourceBranch} → {pr.targetBranch}
#{pr.number} by {pr.isOwner ? 'you' : pr.author} • {pr.sourceBranch} → {pr.targetBranch}
</p>
</div>
{!originUrl.startsWith('nostr://') && (
<Button
variant="ghost"
size="sm"
className="h-8 shrink-0"
onClick={() => window.open(pr.url, '_blank')}
>
<ExternalLink className="h-3 w-3" />
</Button>
)}
<div className="flex items-center gap-1">
{!pr.isOwner && pr.state === 'open' && (
<>
<Button
variant="ghost"
size="sm"
className="h-8"
onClick={async () => {
try {
await git.checkout({
dir: projectPath,
ref: pr.sourceBranch,
});
await refetchGitStatus();
toast({
title: 'Branch checked out',
description: `Switched to ${pr.sourceBranch}`,
});
} catch (err) {
toast({
title: 'Checkout failed',
description: err instanceof Error ? err.message : 'Unknown error',
variant: 'destructive',
});
}
}}
>
<GitBranch className="h-3 w-3 mr-1" />
Review
</Button>
<MergeDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
sourceBranch={pr.sourceBranch}
targetBranch={pr.targetBranch}
onMergeComplete={refetchGitStatus}
/>
</>
)}
{!originUrl.startsWith('nostr://') && (
<Button
variant="ghost"
size="sm"
className="h-8 shrink-0"
onClick={() => window.open(pr.url, '_blank')}
>
<ExternalLink className="h-3 w-3" />
</Button>
)}
</div>
</div>
</div>
</div>
+5 -1
View File
@@ -35,6 +35,8 @@ import { useSearchParams } from 'react-router-dom';
interface MergeDialogProps {
projectId: string;
currentBranch: string | null;
sourceBranch?: string;
targetBranch?: string;
open?: boolean;
onOpenChange?: (open: boolean) => void;
onMergeComplete?: () => void;
@@ -58,13 +60,15 @@ interface MergePreview {
export function MergeDialog({
projectId,
currentBranch,
sourceBranch: initialSourceBranch,
targetBranch: initialTargetBranch,
open,
onOpenChange,
onMergeComplete,
}: MergeDialogProps) {
const [isOpen, setIsOpen] = useState(open ?? false);
const [branches, setBranches] = useState<string[]>([]);
const [sourceBranch, setSourceBranch] = useState<string>('');
const [sourceBranch, setSourceBranch] = useState<string>(initialSourceBranch || '');
const [isLoadingBranches, setIsLoadingBranches] = useState(false);
const [isLoadingPreview, setIsLoadingPreview] = useState(false);
const [isMerging, setIsMerging] = useState(false);