Create PR from comparison screen (#41)
* Task attempt 0958c29b-aea3-42a4-9703-5fc5a6705b1c - Final changes * Task attempt 0958c29b-aea3-42a4-9703-5fc5a6705b1c - Final changes * Task attempt 0958c29b-aea3-42a4-9703-5fc5a6705b1c - Final changes * Task attempt 0958c29b-aea3-42a4-9703-5fc5a6705b1c - Final changes * Task attempt 0958c29b-aea3-42a4-9703-5fc5a6705b1c - Final changes * Task attempt 0958c29b-aea3-42a4-9703-5fc5a6705b1c - Final changes * Prettier * Cargo fmt * Clippy
This commit is contained in:
committed by
GitHub
parent
7fb28b3f38
commit
6a8d7d8a19
@@ -18,7 +18,7 @@ import { Label } from '@/components/ui/label';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Loader2, Volume2 } from 'lucide-react';
|
||||
import { Loader2, Volume2, Key } from 'lucide-react';
|
||||
import type { ThemeMode, EditorType, SoundFile } from 'shared/types';
|
||||
import {
|
||||
EXECUTOR_TYPES,
|
||||
@@ -271,6 +271,71 @@ export function Settings() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Key className="h-5 w-5" />
|
||||
GitHub Integration
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Configure GitHub settings for creating pull requests from task
|
||||
attempts.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="github-token">Personal Access Token</Label>
|
||||
<Input
|
||||
id="github-token"
|
||||
type="password"
|
||||
placeholder="ghp_xxxxxxxxxxxxxxxxxxxx"
|
||||
value={config.github.token || ''}
|
||||
onChange={(e) =>
|
||||
updateConfig({
|
||||
github: {
|
||||
...config.github,
|
||||
token: e.target.value || null,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
GitHub Personal Access Token with 'repo' permissions. Required
|
||||
for creating pull requests.{' '}
|
||||
<a
|
||||
href="https://github.com/settings/tokens"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-blue-600 hover:underline"
|
||||
>
|
||||
Create token here
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="default-pr-base">Default PR Base Branch</Label>
|
||||
<Input
|
||||
id="default-pr-base"
|
||||
placeholder="main"
|
||||
value={config.github.default_pr_base || ''}
|
||||
onChange={(e) =>
|
||||
updateConfig({
|
||||
github: {
|
||||
...config.github,
|
||||
default_pr_base: e.target.value || null,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Default base branch for pull requests. Defaults to 'main' if
|
||||
not specified.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Notifications</CardTitle>
|
||||
|
||||
@@ -10,6 +10,9 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import {
|
||||
ArrowLeft,
|
||||
FileText,
|
||||
@@ -20,6 +23,7 @@ import {
|
||||
Trash2,
|
||||
Eye,
|
||||
EyeOff,
|
||||
GitPullRequest,
|
||||
} from 'lucide-react';
|
||||
import { makeRequest } from '@/lib/api';
|
||||
import type {
|
||||
@@ -58,8 +62,38 @@ export function TaskAttemptComparePage() {
|
||||
const [deletingFiles, setDeletingFiles] = useState<Set<string>>(new Set());
|
||||
const [fileToDelete, setFileToDelete] = useState<string | null>(null);
|
||||
const [showUncommittedWarning, setShowUncommittedWarning] = useState(false);
|
||||
const [creatingPR, setCreatingPR] = useState(false);
|
||||
const [showCreatePRDialog, setShowCreatePRDialog] = useState(false);
|
||||
const [prTitle, setPrTitle] = useState('');
|
||||
const [prBody, setPrBody] = useState('');
|
||||
const [prBaseBranch, setPrBaseBranch] = useState('main');
|
||||
const [taskDetails, setTaskDetails] = useState<{
|
||||
title: string;
|
||||
description: string | null;
|
||||
} | null>(null);
|
||||
|
||||
// Define callbacks first
|
||||
const fetchTaskDetails = useCallback(async () => {
|
||||
if (!projectId || !taskId) return;
|
||||
|
||||
try {
|
||||
const response = await makeRequest(
|
||||
`/api/projects/${projectId}/tasks/${taskId}`
|
||||
);
|
||||
if (response.ok) {
|
||||
const result: ApiResponse<any> = await response.json();
|
||||
if (result.success && result.data) {
|
||||
setTaskDetails({
|
||||
title: result.data.title,
|
||||
description: result.data.description,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// Silently fail - not critical for the main functionality
|
||||
}
|
||||
}, [projectId, taskId]);
|
||||
|
||||
const fetchDiff = useCallback(async () => {
|
||||
if (!projectId || !taskId || !attemptId) return;
|
||||
|
||||
@@ -114,10 +148,18 @@ export function TaskAttemptComparePage() {
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId && taskId && attemptId) {
|
||||
fetchTaskDetails();
|
||||
fetchDiff();
|
||||
fetchBranchStatus();
|
||||
}
|
||||
}, [projectId, taskId, attemptId, fetchDiff, fetchBranchStatus]);
|
||||
}, [
|
||||
projectId,
|
||||
taskId,
|
||||
attemptId,
|
||||
fetchTaskDetails,
|
||||
fetchDiff,
|
||||
fetchBranchStatus,
|
||||
]);
|
||||
|
||||
const handleBackClick = () => {
|
||||
navigate(`/projects/${projectId}/tasks/${taskId}`);
|
||||
@@ -207,6 +249,73 @@ export function TaskAttemptComparePage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreatePRClick = async () => {
|
||||
if (!projectId || !taskId || !attemptId) return;
|
||||
|
||||
// Auto-fill with task details if available
|
||||
if (taskDetails) {
|
||||
setPrTitle(`${taskDetails.title} (vibe-kanban)`);
|
||||
setPrBody(taskDetails.description || '');
|
||||
} else {
|
||||
// Fallback if task details aren't available
|
||||
setPrTitle('Task completion (vibe-kanban)');
|
||||
setPrBody('');
|
||||
}
|
||||
|
||||
setShowCreatePRDialog(true);
|
||||
};
|
||||
|
||||
const handleConfirmCreatePR = async () => {
|
||||
if (!projectId || !taskId || !attemptId) return;
|
||||
|
||||
try {
|
||||
setCreatingPR(true);
|
||||
const response = await makeRequest(
|
||||
`/api/projects/${projectId}/tasks/${taskId}/attempts/${attemptId}/create-pr`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: prTitle,
|
||||
body: prBody || null,
|
||||
base_branch: prBaseBranch || null,
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
const result: ApiResponse<string> = await response.json();
|
||||
if (result.success && result.data) {
|
||||
// Open the PR URL in a new tab
|
||||
window.open(result.data, '_blank');
|
||||
setShowCreatePRDialog(false);
|
||||
// Reset form
|
||||
setPrTitle('');
|
||||
setPrBody('');
|
||||
setPrBaseBranch('main');
|
||||
} else {
|
||||
setError(result.message || 'Failed to create GitHub PR');
|
||||
}
|
||||
} else {
|
||||
setError('Failed to create GitHub PR');
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Failed to create GitHub PR');
|
||||
} finally {
|
||||
setCreatingPR(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelCreatePR = () => {
|
||||
setShowCreatePRDialog(false);
|
||||
// Reset form to empty state - will be auto-filled again when reopened
|
||||
setPrTitle('');
|
||||
setPrBody('');
|
||||
setPrBaseBranch('main');
|
||||
};
|
||||
|
||||
const getChunkClassName = (chunkType: DiffChunkType) => {
|
||||
const baseClass = 'font-mono text-sm whitespace-pre py-1 flex';
|
||||
|
||||
@@ -547,18 +656,34 @@ export function TaskAttemptComparePage() {
|
||||
</Button>
|
||||
)}
|
||||
{!branchStatus?.merged && (
|
||||
<Button
|
||||
onClick={handleMergeClick}
|
||||
disabled={
|
||||
merging ||
|
||||
!diff ||
|
||||
diff.files.length === 0 ||
|
||||
Boolean(branchStatus?.is_behind)
|
||||
}
|
||||
className="bg-green-600 hover:bg-green-700 disabled:bg-gray-400"
|
||||
>
|
||||
{merging ? 'Merging...' : 'Merge Changes'}
|
||||
</Button>
|
||||
<>
|
||||
<Button
|
||||
onClick={handleCreatePRClick}
|
||||
disabled={
|
||||
creatingPR ||
|
||||
!diff ||
|
||||
diff.files.length === 0 ||
|
||||
Boolean(branchStatus?.is_behind)
|
||||
}
|
||||
variant="outline"
|
||||
className="border-blue-300 text-blue-700 hover:bg-blue-50"
|
||||
>
|
||||
<GitPullRequest className="mr-2 h-4 w-4" />
|
||||
{creatingPR ? 'Creating PR...' : 'Create PR'}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleMergeClick}
|
||||
disabled={
|
||||
merging ||
|
||||
!diff ||
|
||||
diff.files.length === 0 ||
|
||||
Boolean(branchStatus?.is_behind)
|
||||
}
|
||||
className="bg-green-600 hover:bg-green-700 disabled:bg-gray-400"
|
||||
>
|
||||
{merging ? 'Merging...' : 'Merge Changes'}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -788,6 +913,63 @@ export function TaskAttemptComparePage() {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Create PR Dialog */}
|
||||
<Dialog
|
||||
open={showCreatePRDialog}
|
||||
onOpenChange={() => handleCancelCreatePR()}
|
||||
>
|
||||
<DialogContent className="sm:max-w-[525px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create GitHub Pull Request</DialogTitle>
|
||||
<DialogDescription>
|
||||
Create a pull request for this task attempt on GitHub.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="pr-title">Title</Label>
|
||||
<Input
|
||||
id="pr-title"
|
||||
value={prTitle}
|
||||
onChange={(e) => setPrTitle(e.target.value)}
|
||||
placeholder="Enter PR title"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="pr-body">Description (optional)</Label>
|
||||
<Textarea
|
||||
id="pr-body"
|
||||
value={prBody}
|
||||
onChange={(e) => setPrBody(e.target.value)}
|
||||
placeholder="Enter PR description"
|
||||
rows={4}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="pr-base">Base Branch</Label>
|
||||
<Input
|
||||
id="pr-base"
|
||||
value={prBaseBranch}
|
||||
onChange={(e) => setPrBaseBranch(e.target.value)}
|
||||
placeholder="main"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={handleCancelCreatePR}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleConfirmCreatePR}
|
||||
disabled={creatingPR || !prTitle.trim()}
|
||||
className="bg-blue-600 hover:bg-blue-700"
|
||||
>
|
||||
{creatingPR ? 'Creating...' : 'Create PR'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user