-
Notifications
You must be signed in to change notification settings - Fork 73
feat: add Gerrit integration connector for code review workflows #1027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8bbe821
9367dd6
457f64c
dc40ab7
28be475
97e2e32
871a6ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { BACKEND_URL } from '@/lib/config' | ||
| import { buildForwardHeadersAsync } from '@/lib/auth' | ||
|
|
||
| export async function DELETE( | ||
| request: Request, | ||
| { params }: { params: Promise<{ instanceName: string }> } | ||
| ) { | ||
| const { instanceName } = await params | ||
| const safeInstanceName = encodeURIComponent(instanceName) | ||
| const headers = await buildForwardHeadersAsync(request) | ||
|
|
||
| const resp = await fetch(`${BACKEND_URL}/auth/gerrit/${safeInstanceName}/disconnect`, { | ||
| method: 'DELETE', | ||
| headers, | ||
| }) | ||
|
|
||
| const data = await resp.text() | ||
| return new Response(data, { status: resp.status, headers: { 'Content-Type': 'application/json' } }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { BACKEND_URL } from '@/lib/config' | ||
| import { buildForwardHeadersAsync } from '@/lib/auth' | ||
|
|
||
| export async function GET( | ||
| request: Request, | ||
| { params }: { params: Promise<{ instanceName: string }> } | ||
| ) { | ||
| const { instanceName } = await params | ||
| const safeInstanceName = encodeURIComponent(instanceName) | ||
| const headers = await buildForwardHeadersAsync(request) | ||
|
|
||
| const resp = await fetch(`${BACKEND_URL}/auth/gerrit/${safeInstanceName}/status`, { | ||
| method: 'GET', | ||
| headers, | ||
| }) | ||
|
|
||
| const data = await resp.text() | ||
| return new Response(data, { status: resp.status, headers: { 'Content-Type': 'application/json' } }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { BACKEND_URL } from '@/lib/config' | ||
| import { buildForwardHeadersAsync } from '@/lib/auth' | ||
|
|
||
| export async function POST(request: Request) { | ||
| const headers = await buildForwardHeadersAsync(request) | ||
| const body = await request.text() | ||
|
|
||
| const resp = await fetch(`${BACKEND_URL}/auth/gerrit/connect`, { | ||
| method: 'POST', | ||
| headers, | ||
| body, | ||
| }) | ||
|
|
||
| const data = await resp.text() | ||
| return new Response(data, { status: resp.status, headers: { 'Content-Type': 'application/json' } }) | ||
|
Comment on lines
+8
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify Gerrit proxy routes include timeout signal and local catch handling.
rg -n --type=ts -C2 'fetch\(`\$\{BACKEND_URL\}/auth/gerrit' components/frontend/src/app/api/auth/gerrit
rg -n --type=ts -C2 'signal\s*:' components/frontend/src/app/api/auth/gerrit
rg -n --type=ts -C2 'catch\s*\(' components/frontend/src/app/api/auth/gerritRepository: ambient-code/platform Length of output: 2600 🏁 Script executed: cat -n components/frontend/src/app/api/auth/gerrit/connect/route.tsRepository: ambient-code/platform Length of output: 669 🏁 Script executed: # Check if similar unprotected fetch patterns exist in other auth routes
rg -n --type=ts 'await fetch\(`\$\{BACKEND_URL\}' components/frontend/src/app/api/auth --no-heading | head -20Repository: ambient-code/platform Length of output: 2626 🏁 Script executed: # Check for existing timeout patterns or utilities
rg -n --type=ts 'AbortController|setTimeout.*timeout|TIMEOUT|Abort' components/frontend/src/lib --type ts | head -10Repository: ambient-code/platform Length of output: 149 Add timeout + network-failure handling for the backend proxy call. Line 8 issues an upstream Proposed fix export async function POST(request: Request) {
const headers = await buildForwardHeadersAsync(request)
const body = await request.text()
- const resp = await fetch(`${BACKEND_URL}/auth/gerrit/connect`, {
- method: 'POST',
- headers,
- body,
- })
-
- const data = await resp.text()
- return new Response(data, { status: resp.status, headers: { 'Content-Type': 'application/json' } })
+ const controller = new AbortController()
+ const timeout = setTimeout(() => controller.abort(), 10_000)
+ try {
+ const resp = await fetch(`${BACKEND_URL}/auth/gerrit/connect`, {
+ method: 'POST',
+ headers,
+ body,
+ signal: controller.signal,
+ })
+
+ const data = await resp.text()
+ return new Response(data, { status: resp.status, headers: { 'Content-Type': 'application/json' } })
+ } catch {
+ return Response.json({ error: 'Upstream Gerrit connect request failed' }, { status: 504 })
+ } finally {
+ clearTimeout(timeout)
+ }
}🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { BACKEND_URL } from '@/lib/config' | ||
| import { buildForwardHeadersAsync } from '@/lib/auth' | ||
|
|
||
| export async function GET(request: Request) { | ||
| const headers = await buildForwardHeadersAsync(request) | ||
|
|
||
| const resp = await fetch(`${BACKEND_URL}/auth/gerrit/instances`, { | ||
| method: 'GET', | ||
| headers, | ||
| }) | ||
|
|
||
| const data = await resp.text() | ||
| return new Response(data, { status: resp.status, headers: { 'Content-Type': 'application/json' } }) | ||
|
Comment on lines
+7
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's examine the actual file and its context
cat -n components/frontend/src/app/api/auth/gerrit/instances/route.tsRepository: ambient-code/platform Length of output: 609 🏁 Script executed: # Search for other auth/gerrit related routes to find the "robust proxy endpoints"
fd -t f "route.ts" components/frontend/src/app/api/auth/ | head -20Repository: ambient-code/platform Length of output: 1330 🏁 Script executed: # Search for examples of timeout handling in API routes
rg -A 5 -B 5 "timeout|AbortController" components/frontend/src/app/api/ --type tsRepository: ambient-code/platform Length of output: 47 🏁 Script executed: # Search more broadly for fetch calls with timeout handling
rg "fetch" components/frontend/src/app/api/ --type ts -A 3 | head -100Repository: ambient-code/platform Length of output: 8197 🏁 Script executed: # Look for AbortSignal or timeout patterns in lib or utils
rg -r "AbortSignal|AbortController|timeout" components/frontend/src/lib/ --type ts | head -20Repository: ambient-code/platform Length of output: 47 🏁 Script executed: # Search for the word "robust" or "proxy" in the API directory
rg "proxy|robust" components/frontend/src/app/api/ --type tsRepository: ambient-code/platform Length of output: 1909 🏁 Script executed: # Check if there's a middleware or config that might handle timeouts globally
find components/frontend/src -name "*.ts" -path "*/middleware*" -o -name "*.ts" -path "*/config*" | xargs grep -l "timeout" 2>/dev/null | head -10Repository: ambient-code/platform Length of output: 47 🏁 Script executed: # Look for custom fetch wrappers or utilities
fd -t f "fetch|http|proxy" components/frontend/src/lib/ --type ts | xargs grep -l "fetch" 2>/dev/null | head -10Repository: ambient-code/platform Length of output: 234 🏁 Script executed: # Check if there's any middleware
fd -t f "middleware" components/frontend/src/ --type ts | head -10Repository: ambient-code/platform Length of output: 234 🏁 Script executed: # Look at one of the endpoints with error handling more closely to understand the pattern
cat -n components/frontend/src/app/api/version/route.tsRepository: ambient-code/platform Length of output: 988 🏁 Script executed: # Search for any mention of signal or timeout in the entire codebase
rg "signal|Signal" components/frontend/src/app/api/ --type ts -B 2 -A 2 | head -50Repository: ambient-code/platform Length of output: 759 🏁 Script executed: # Search for middleware files more broadly
find components/frontend/src -name "*.ts" | xargs grep -l "middleware" 2>/dev/null | head -10Repository: ambient-code/platform Length of output: 210 🏁 Script executed: # Check if there's a next.config or similar configuration
find components/frontend -name "next.config*" -o -name "tsconfig*" | xargs cat 2>/dev/null | head -50Repository: ambient-code/platform Length of output: 1217 🏁 Script executed: # Look at the gerrit instances route in more detail and its surrounding context
cat -n components/frontend/src/app/api/auth/gerrit/instances/route.tsRepository: ambient-code/platform Length of output: 609 🏁 Script executed: # Check other gerrit routes to see if they have error handling
cat -n components/frontend/src/app/api/auth/gerrit/connect/route.tsRepository: ambient-code/platform Length of output: 669 🏁 Script executed: # Check if Next.js has built-in timeout mechanisms through request.signal
rg "request\.signal" components/frontend/src/app/api/ -A 2 -B 2 | head -30Repository: ambient-code/platform Length of output: 47 🏁 Script executed: # Look at a more complex route to see if there's a pattern for handling long-running operations
cat -n components/frontend/src/app/api/projects/\[name\]/agentic-sessions/\[sessionName\]/agui/run/route.ts | head -80Repository: ambient-code/platform Length of output: 1930 🏁 Script executed: # Check if there's any documentation or patterns for handling timeouts in Next.js routes
rg "fetch.*signal|AbortSignal|timeout" components/frontend/src --type file | head -20Repository: ambient-code/platform Length of output: 93 🏁 Script executed: # Search for any environment-based timeout configuration
rg "timeout|TIMEOUT" components/frontend/src --type file 2>/dev/null | head -20Repository: ambient-code/platform Length of output: 47 🏁 Script executed: # Check if any of the auth routes have error handling
for file in components/frontend/src/app/api/auth/gerrit/*.ts components/frontend/src/app/api/auth/gerrit/*/route.ts; do
if [ -f "$file" ]; then
echo "=== $file ==="
cat "$file"
fi
doneRepository: ambient-code/platform Length of output: 1700 🏁 Script executed: # Check the github auth routes to see if they have a different pattern
cat -n components/frontend/src/app/api/auth/github/user/callback/route.ts | head -50Repository: ambient-code/platform Length of output: 1004 🏁 Script executed: # Final check: confirm if any route has both timeout and error handling combined
rg -A 10 "fetch.*{" components/frontend/src/app/api/ | rg -B 5 -A 5 "signal|AbortController|timeout" | head -20Repository: ambient-code/platform Length of output: 144 🏁 Script executed: # Final verification: check all fetch calls for signal/timeout handling
rg "fetch\(" components/frontend/src/app/api/ -A 5 | rg "signal\|AbortController" -B 3 -A 3Repository: ambient-code/platform Length of output: 47 Add timeout and error handling for the backend fetch call. This route lacks both timeout protection and error handling. If the backend stalls, the route will hang indefinitely, making the endpoint unresponsive. Add 🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.