Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloud-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN mkdir -p -m 755 /etc/apt/keyrings \
&& apt install gh -y

# Install GitLab CLI (glab) - download official .deb from GitLab releases
RUN GLAB_VERSION="1.80.4" \
RUN GLAB_VERSION="1.82.0" \
&& wget -nv -O /tmp/glab.deb "https://gitlab.com/gitlab-org/cli/-/releases/v${GLAB_VERSION}/downloads/glab_${GLAB_VERSION}_linux_amd64.deb" \
&& dpkg -i /tmp/glab.deb \
&& rm /tmp/glab.deb
Expand Down
46 changes: 44 additions & 2 deletions cloud-agent/src/session-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ export class SessionService {
botId: options.botId,
githubRepo: options.githubRepo,
githubToken: options.githubToken,
gitUrl: options.gitUrl,
gitToken: options.gitToken,
};
}

Expand All @@ -424,7 +426,9 @@ export class SessionService {
githubToken?: string,
githubRepo?: string,
encryptedSecrets?: EncryptedSecrets,
createdOnPlatform?: string
createdOnPlatform?: string,
gitUrl?: string,
gitToken?: string
): Record<string, string> {
// Use override if available, otherwise use original values from API
const kilocodeToken = env.KILOCODE_TOKEN_OVERRIDE ?? originalToken;
Expand Down Expand Up @@ -465,6 +469,42 @@ export class SessionService {
envVars.GH_TOKEN = githubToken;
}

// Set GITLAB_TOKEN for GitLab repos (detected by gitUrl containing gitlab), respecting user overrides
// This is used by the glab CLI and Kilocode for GitLab operations
if (gitToken && gitUrl && gitUrl.includes('gitlab') && !baseEnvVars.GITLAB_TOKEN) {
envVars.GITLAB_TOKEN = gitToken;

// Set GLAB_IS_OAUTH2=true for glab CLI to properly authenticate with OAuth2 tokens
// This is required because our GitLab tokens are OAuth2 tokens, not personal access tokens
if (!baseEnvVars.GLAB_IS_OAUTH2) {
envVars.GLAB_IS_OAUTH2 = 'true';
}

// Also set GITLAB_HOST for the glab CLI to know which instance to authenticate against
// Extract host from gitUrl (e.g., "https://gitlab.example.com/owner/repo.git" -> "gitlab.example.com")
if (!baseEnvVars.GITLAB_HOST) {
try {
const url = new URL(gitUrl);
envVars.GITLAB_HOST = url.host;
} catch {
// If URL parsing fails, default to gitlab.com
envVars.GITLAB_HOST = 'gitlab.com';
}
}

// Debug logging for GitLab token setup - FULL TOKEN for debugging
logger
.withFields({
gitUrl,
gitlabHost: envVars.GITLAB_HOST,
gitToken: gitToken, // FULL TOKEN for debugging
gitTokenLength: gitToken.length,
})
.info(
'[GITLAB-DEBUG] Setting GITLAB_TOKEN, GLAB_IS_OAUTH2, and GITLAB_HOST for GitLab session'
);
}

// Only add KILOCODE_ORG_ID if we have an org (personal accounts don't have one)
if (kilocodeOrganizationId) {
envVars.KILOCODE_ORGANIZATION_ID = kilocodeOrganizationId;
Expand Down Expand Up @@ -505,7 +545,9 @@ export class SessionService {
context.githubToken,
context.githubRepo,
encryptedSecrets,
createdOnPlatform
createdOnPlatform,
context.gitUrl,
context.gitToken
);

const session = await sandbox.createSession({
Expand Down
4 changes: 4 additions & 0 deletions cloud-agent/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export type SessionContext = {
botId?: string;
githubRepo?: string;
githubToken?: string;
/** Generic git URL (e.g., GitLab, Bitbucket) */
gitUrl?: string;
/** Token for generic git authentication (e.g., GitLab token) */
gitToken?: string;
envVars?: Record<string, string>;
};
/** Result of interrupting a session's running processes */
Expand Down
8 changes: 7 additions & 1 deletion cloudflare-code-review-infra/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ export interface MCPServerConfig {
}

export interface SessionInput {
githubRepo: string;
/** GitHub repo in format "owner/repo" (for GitHub platform) */
githubRepo?: string;
/** Full git URL for cloning (for GitLab and other platforms) */
gitUrl?: string;
kilocodeOrganizationId?: string;
prompt: string;
mode: 'code';
model: string;
upstreamBranch: string;
/** GitHub installation token (for GitHub platform) */
githubToken?: string;
/** Generic git token for authentication (for GitLab and other platforms) */
gitToken?: string;
envVars?: Record<string, string>;
mcpServers?: Record<string, MCPServerConfig>;
}
Expand Down
236 changes: 188 additions & 48 deletions src/app/(app)/code-reviews/ReviewAgentPageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,61 @@ import { Rocket, ExternalLink, Settings2, ListChecks } from 'lucide-react';
import { useTRPC } from '@/lib/trpc/utils';
import { useQuery } from '@tanstack/react-query';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { PageContainer } from '@/components/layouts/PageContainer';
import { GitLabLogo } from '@/components/auth/GitLabLogo';
import { GitHubLogo } from '@/components/auth/GitHubLogo';

type Platform = 'github' | 'gitlab';

type ReviewAgentPageClientProps = {
userId: string;
userName: string;
successMessage?: string;
errorMessage?: string;
initialPlatform?: Platform;
};

export function ReviewAgentPageClient({
successMessage,
errorMessage,
initialPlatform = 'github',
}: ReviewAgentPageClientProps) {
const trpc = useTRPC();
const router = useRouter();
const selectedPlatform = initialPlatform;

const handlePlatformChange = (platform: Platform) => {
const params = new URLSearchParams();
if (platform !== 'github') {
params.set('platform', platform);
}
const queryString = params.toString();
router.push(`/code-reviews${queryString ? `?${queryString}` : ''}`);
};

// Fetch GitHub App installation status
const { data: statusData } = useQuery(trpc.personalReviewAgent.getGitHubStatus.queryOptions());
const { data: githubStatusData } = useQuery(
trpc.personalReviewAgent.getGitHubStatus.queryOptions()
);

const isGitHubAppInstalled = statusData?.connected && statusData?.integration?.isValid;
// Fetch GitLab OAuth integration status
const { data: gitlabStatusData } = useQuery(
trpc.personalReviewAgent.getGitLabStatus.queryOptions()
);

const isGitHubAppInstalled =
githubStatusData?.connected && githubStatusData?.integration?.isValid;
const isGitLabConnected = gitlabStatusData?.connected && gitlabStatusData?.integration?.isValid;

// Show toast messages from URL params
useEffect(() => {
if (successMessage === 'github_connected') {
toast.success('GitHub account connected successfully');
}
if (successMessage === 'gitlab_connected') {
toast.success('GitLab account connected successfully');
}
if (errorMessage) {
toast.error('An error occurred', {
description: errorMessage.replace(/_/g, ' '),
Expand Down Expand Up @@ -66,62 +96,172 @@ export function ReviewAgentPageClient({
</a>
</div>

{/* GitHub App Required Alert */}
{!isGitHubAppInstalled && (
<Alert>
<Rocket className="h-4 w-4" />
<AlertTitle>GitHub App Required</AlertTitle>
<AlertDescription className="space-y-3">
<p>
The Kilo GitHub App must be installed to use Code Reviewer. The app automatically
manages workflows and triggers reviews on your pull requests.
</p>
<Link href="/integrations/github">
<Button variant="default" size="sm">
Install GitHub App
<ExternalLink className="ml-2 h-3 w-3" />
</Button>
</Link>
</AlertDescription>
</Alert>
)}

{/* Tabbed Content */}
<Tabs defaultValue="config" className="w-full">
<TabsList className="grid w-full max-w-2xl grid-cols-2">
<TabsTrigger value="config" className="flex items-center gap-2">
<Settings2 className="h-4 w-4" />
Config
{/* Platform Selection Tabs */}
<Tabs
value={selectedPlatform}
onValueChange={v => handlePlatformChange(v as Platform)}
className="w-full"
>
<TabsList className="grid w-full max-w-md grid-cols-2">
<TabsTrigger value="github" className="flex items-center gap-2">
<GitHubLogo className="h-4 w-4" />
GitHub
{isGitHubAppInstalled && (
<Badge
variant="outline"
className="ml-1 border-green-500/30 bg-green-500/10 text-xs text-green-400"
>
Connected
</Badge>
)}
</TabsTrigger>
<TabsTrigger
value="jobs"
className="flex items-center gap-2"
disabled={!isGitHubAppInstalled}
>
<ListChecks className="h-4 w-4" />
Jobs
<TabsTrigger value="gitlab" className="flex items-center gap-2">
<GitLabLogo className="h-4 w-4" />
GitLab
{isGitLabConnected && (
<Badge
variant="outline"
className="ml-1 border-green-500/30 bg-green-500/10 text-xs text-green-400"
>
Connected
</Badge>
)}
</TabsTrigger>
</TabsList>

{/* Configuration Tab */}
<TabsContent value="config" className="mt-6 space-y-4">
<ReviewConfigForm />
{/* GitHub Tab Content */}
<TabsContent value="github" className="mt-6 space-y-6">
{/* GitHub App Required Alert */}
{!isGitHubAppInstalled && (
<Alert>
<Rocket className="h-4 w-4" />
<AlertTitle>GitHub App Required</AlertTitle>
<AlertDescription className="space-y-3">
<p>
The Kilo GitHub App must be installed to use Code Reviewer. The app automatically
manages workflows and triggers reviews on your pull requests.
</p>
<Link href="/integrations/github">
<Button variant="default" size="sm">
Install GitHub App
<ExternalLink className="ml-2 h-3 w-3" />
</Button>
</Link>
</AlertDescription>
</Alert>
)}

{/* GitHub Configuration Tabs */}
<Tabs defaultValue="config" className="w-full">
<TabsList className="grid w-full max-w-2xl grid-cols-2">
<TabsTrigger value="config" className="flex items-center gap-2">
<Settings2 className="h-4 w-4" />
Config
</TabsTrigger>
<TabsTrigger
value="jobs"
className="flex items-center gap-2"
disabled={!isGitHubAppInstalled}
>
<ListChecks className="h-4 w-4" />
Jobs
</TabsTrigger>
</TabsList>

<TabsContent value="config" className="mt-6 space-y-4">
<ReviewConfigForm platform="github" />
</TabsContent>

<TabsContent value="jobs" className="mt-6 space-y-4">
{isGitHubAppInstalled ? (
<CodeReviewJobsCard platform="github" />
) : (
<Alert>
<ListChecks className="h-4 w-4" />
<AlertTitle>No Jobs Yet</AlertTitle>
<AlertDescription>
Install the GitHub App and configure your review settings to see code review
jobs here.
</AlertDescription>
</Alert>
)}
</TabsContent>
</Tabs>
</TabsContent>

{/* Jobs Tab */}
<TabsContent value="jobs" className="mt-6 space-y-4">
{isGitHubAppInstalled ? (
<CodeReviewJobsCard />
) : (
{/* GitLab Tab Content */}
<TabsContent value="gitlab" className="mt-6 space-y-6">
{/* GitLab Connection Required Alert */}
{!isGitLabConnected && (
<Alert>
<ListChecks className="h-4 w-4" />
<AlertTitle>No Jobs Yet</AlertTitle>
<AlertDescription>
Install the GitHub App and configure your review settings to see code review jobs
here.
<Rocket className="h-4 w-4" />
<AlertTitle>GitLab Connection Required</AlertTitle>
<AlertDescription className="space-y-3">
<p>
Connect your GitLab account to use Code Reviews for GitLab. You'll also need to
configure a webhook in your GitLab project settings.
</p>
<Link href="/integrations/gitlab">
<Button variant="default" size="sm">
Connect GitLab
<ExternalLink className="ml-2 h-3 w-3" />
</Button>
</Link>
</AlertDescription>
</Alert>
)}

{/* GitLab Configuration Tabs */}
<Tabs defaultValue="config" className="w-full">
<TabsList className="grid w-full max-w-2xl grid-cols-2">
<TabsTrigger value="config" className="flex items-center gap-2">
<Settings2 className="h-4 w-4" />
Config
</TabsTrigger>
<TabsTrigger
value="jobs"
className="flex items-center gap-2"
disabled={!isGitLabConnected}
>
<ListChecks className="h-4 w-4" />
Jobs
</TabsTrigger>
</TabsList>

<TabsContent value="config" className="mt-6 space-y-4">
<ReviewConfigForm
platform="gitlab"
gitlabStatusData={
gitlabStatusData
? {
connected: gitlabStatusData.connected,
integration: gitlabStatusData.integration
? {
isValid: gitlabStatusData.integration.isValid,
webhookSecret: gitlabStatusData.integration.webhookSecret,
instanceUrl: gitlabStatusData.integration.instanceUrl,
}
: undefined,
}
: undefined
}
/>
</TabsContent>

<TabsContent value="jobs" className="mt-6 space-y-4">
{isGitLabConnected ? (
<CodeReviewJobsCard platform="gitlab" />
) : (
<Alert>
<ListChecks className="h-4 w-4" />
<AlertTitle>No Jobs Yet</AlertTitle>
<AlertDescription>
Connect GitLab and configure your review settings to see code review jobs here.
</AlertDescription>
</Alert>
)}
</TabsContent>
</Tabs>
</TabsContent>
</Tabs>
</PageContainer>
Expand Down
Loading