-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What - [x] Update tests for failing builds - [x] Commit code to repos - [x] Genericize test finder - [x] Commit right code to repo
- Loading branch information
Showing
14 changed files
with
1,379 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,13 @@ import { useState, useEffect } from "react"; | |
import { Button } from "@/components/ui/button"; | ||
import { Loader2, AlertCircle } from "lucide-react"; | ||
import { PullRequestItem } from "./pull-request"; | ||
import { PullRequest, TestFile } from "./types"; | ||
import { | ||
getAssignedPullRequests, | ||
commitChangesToPullRequest, | ||
} from "@/lib/github"; | ||
import { PullRequest } from "./types"; | ||
import { getAssignedPullRequests } from "@/lib/github"; | ||
|
||
export default function DashboardPage() { | ||
const [pullRequests, setPullRequests] = useState<PullRequest[]>([]); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState<string | null>(null); | ||
const [selectedPR, setSelectedPR] = useState<PullRequest | null>(null); | ||
const [testFiles, setTestFiles] = useState<TestFile[]>([]); | ||
const [selectedFiles, setSelectedFiles] = useState<Record<string, boolean>>( | ||
{} | ||
); | ||
const [expandedFiles, setExpandedFiles] = useState<Record<string, boolean>>( | ||
{} | ||
); | ||
const [analyzing, setAnalyzing] = useState(false); | ||
const [loadingPR, setLoadingPR] = useState<number | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchAndSetPullRequests = async () => { | ||
|
@@ -62,64 +49,8 @@ export default function DashboardPage() { | |
fetchAndSetPullRequests(); | ||
}, []); | ||
|
||
const handleOpenTests = (pr: PullRequest, mode: "write" | "update") => { | ||
setSelectedPR(pr); | ||
setAnalyzing(true); | ||
setLoadingPR(pr.id); | ||
|
||
// Simulating API call to get test files | ||
// TODO: update this to dynamically generate based on the PR diff and spec file directory | ||
setTimeout(() => { | ||
const mockTestFiles: TestFile[] = []; | ||
|
||
if (mode === "write") { | ||
mockTestFiles.push({ | ||
name: "signup_spec.rb", | ||
oldContent: "", | ||
newContent: | ||
"describe 'Signup' do\n it 'allows new user to sign up' do\n # Test code here\n end\nend", | ||
isEntirelyNew: true, | ||
}); | ||
|
||
mockTestFiles.push({ | ||
name: "login_spec.rb", | ||
oldContent: | ||
"describe 'Login' do\n it 'allows existing user to log in' do\n visit '/login'\n fill_in 'Email', with: '[email protected]'\n fill_in 'Password', with: 'password123'\n click_button 'Log In'\n expect(page).to have_content('Welcome back!')\n end\nend", | ||
newContent: | ||
"describe 'Login' do\n it 'allows existing user to log in' do\n visit '/login'\n fill_in 'Email', with: '[email protected]'\n fill_in 'Password', with: 'password123'\n click_button 'Log In'\n expect(page).to have_content('Welcome back!')\n end\n\n\n it 'shows error message for invalid credentials' do\n visit '/login'\n fill_in 'Email', with: '[email protected]'\n fill_in 'Password', with: 'wrongpassword'\n click_button 'Log In'\n expect(page).to have_content('Invalid email or password')\n end\nend", | ||
isEntirelyNew: false, | ||
}); | ||
} else if (mode === "update") { | ||
mockTestFiles.push({ | ||
name: "logic_spec.rb", | ||
oldContent: | ||
"describe 'BusinessLogic' do\n it 'calculates total correctly' do\n expect(calculate_total(10, 5)).to eq(15)\n end\n\n it 'applies discount' do\n expect(apply_discount(100, 0.1)).to eq(90)\n end\nend", | ||
newContent: | ||
"describe 'BusinessLogic' do\n it 'calculates total correctly' do\n expect(calculate_total(10, 5)).to eq(15)\n end\n\n it 'applies percentage discount' do\n expect(apply_percentage_discount(100, 10)).to eq(90)\n end\n\n it 'applies flat discount' do\n expect(apply_flat_discount(100, 10)).to eq(90)\n end\nend", | ||
isEntirelyNew: false, | ||
}); | ||
} | ||
|
||
setTestFiles(mockTestFiles); | ||
const newSelectedFiles: Record<string, boolean> = {}; | ||
const newExpandedFiles: Record<string, boolean> = {}; | ||
mockTestFiles.forEach((file) => { | ||
newExpandedFiles[file.name] = true; | ||
if (mode === "update") { | ||
newSelectedFiles[file.name] = true; | ||
} | ||
}); | ||
setSelectedFiles(newSelectedFiles); | ||
setExpandedFiles(newExpandedFiles); | ||
setAnalyzing(false); | ||
setLoadingPR(null); | ||
}, 1000); | ||
}; | ||
|
||
const handleReconnectGitHub = async () => { | ||
try { | ||
// Redirect to GitHub OAuth flow to get new permissions | ||
// Make sure NEXT_PUBLIC_GITHUB_CLIENT_ID is properly set in your environment variables | ||
const clientId = process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID; | ||
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL; | ||
if (!clientId) { | ||
|
@@ -137,28 +68,6 @@ export default function DashboardPage() { | |
} | ||
}; | ||
|
||
const handleConfirmChanges = async () => { | ||
if (!selectedPR) return; | ||
|
||
setLoadingPR(selectedPR.id); | ||
try { | ||
const filesToCommit = testFiles.filter( | ||
(file) => selectedFiles[file.name] | ||
); | ||
// TODO: await commitChangesToPullRequest(selectedPR, filesToCommit); | ||
// Reset state after successful commit | ||
setSelectedPR(null); | ||
setTestFiles([]); | ||
setSelectedFiles({}); | ||
setExpandedFiles({}); | ||
} catch (error) { | ||
console.error("Error committing changes:", error); | ||
setError("Failed to commit changes. Please try again."); | ||
} finally { | ||
setLoadingPR(null); | ||
} | ||
}; | ||
|
||
if (loading) { | ||
return ( | ||
<div className="flex justify-center items-center h-full"> | ||
|
@@ -191,33 +100,7 @@ export default function DashboardPage() { | |
{pr.repository.full_name} | ||
</h3> | ||
</div> | ||
<PullRequestItem | ||
pullRequest={pr} | ||
onOpenTests={handleOpenTests} | ||
selectedPR={selectedPR} | ||
testFiles={testFiles} | ||
selectedFiles={selectedFiles} | ||
expandedFiles={expandedFiles} | ||
analyzing={analyzing} | ||
onFileToggle={(fileName) => { | ||
setSelectedFiles((prev) => ({ | ||
...prev, | ||
[fileName]: !prev[fileName], | ||
})); | ||
setExpandedFiles((prev) => ({ | ||
...prev, | ||
[fileName]: !prev[fileName], | ||
})); | ||
}} | ||
onConfirmChanges={handleConfirmChanges} | ||
onCancelChanges={() => { | ||
setSelectedPR(null); | ||
setTestFiles([]); | ||
setSelectedFiles({}); | ||
setExpandedFiles({}); | ||
}} | ||
loadingPR={loadingPR} | ||
/> | ||
<PullRequestItem pullRequest={pr} /> | ||
</li> | ||
))} | ||
</ul> | ||
|
Oops, something went wrong.