Add Gitea integration + ESLint setup
Phase 3: Gitea Integration - Migration 012: app_settings table + gitea_commit_sha on endpoint_versions - SettingsService: encrypted token storage (AES-256-GCM from JWT_SECRET) - GiteaService: full REST API client — repo management, file CRUD, branches, commit history, diff/compare, pull requests, sync all - giteaController + routes: 15 API endpoints for settings, branches, commits, PRs, endpoint info, sync - VersionService hooks: auto-sync to Gitea on publish/draft (non-blocking) - Frontend: Gitea tab in Settings (connection, sync status, branch mgmt), Gitea panel in EndpointEditor (file link, last commit SHA) - docker-compose.gitea.yml: optional companion Gitea container - Cache fix: index.html served with no-cache for instant deploys ESLint Setup - Backend: eslint 8 + @typescript-eslint configured - Frontend: eslint 8 + @typescript-eslint + react-hooks + react-refresh - Fixed 15 lint issues: unused imports, require statements, escapes, Function type, empty catch blocks - Added npm run lint / lint:fix scripts Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
19
frontend/.eslintrc.cjs
Normal file
19
frontend/.eslintrc.cjs
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: { browser: true, es2020: true },
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:react-hooks/recommended',
|
||||
],
|
||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
||||
'no-console': 'off',
|
||||
'prefer-const': 'warn',
|
||||
},
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useState, useEffect, useMemo } from 'react';
|
||||
import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { endpointsApi, foldersApi, databasesApi, versionsApi } from '@/services/api';
|
||||
import { endpointsApi, foldersApi, databasesApi, versionsApi, giteaApi } from '@/services/api';
|
||||
import { EndpointParameter, QueryTestResult, LogEntry, QueryExecution, EndpointVersion } from '@/types';
|
||||
import { Plus, Trash2, Play, Edit2, ChevronDown, ChevronUp, ArrowLeft, CheckCircle, XCircle, Clock, Copy, X, Terminal, History, RotateCcw, Upload } from 'lucide-react';
|
||||
import { Plus, Trash2, Play, Edit2, ChevronDown, ChevronUp, ArrowLeft, CheckCircle, XCircle, Clock, Copy, X, Terminal, History, RotateCcw, Upload, GitBranch } from 'lucide-react';
|
||||
import toast from 'react-hot-toast';
|
||||
import SqlEditor from '@/components/SqlEditor';
|
||||
import CodeEditor from '@/components/CodeEditor';
|
||||
@@ -105,7 +105,7 @@ export default function EndpointEditor() {
|
||||
try {
|
||||
const saved = localStorage.getItem(storageKey);
|
||||
if (saved) return JSON.parse(saved).testParams || {};
|
||||
} catch {}
|
||||
} catch { /* ignore corrupt localStorage */ }
|
||||
}
|
||||
return {};
|
||||
});
|
||||
@@ -134,7 +134,7 @@ export default function EndpointEditor() {
|
||||
const parsed = JSON.parse(saved);
|
||||
if (parsed.testResult) setTestResult(parsed.testResult);
|
||||
}
|
||||
} catch {}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}, [storageKey]);
|
||||
|
||||
@@ -143,7 +143,7 @@ export default function EndpointEditor() {
|
||||
if (storageKey) {
|
||||
try {
|
||||
localStorage.setItem(storageKey, JSON.stringify({ testParams, testResult }));
|
||||
} catch {}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}, [storageKey, testParams, testResult]);
|
||||
|
||||
@@ -242,6 +242,12 @@ export default function EndpointEditor() {
|
||||
});
|
||||
const [showVersionHistory, setShowVersionHistory] = useState(false);
|
||||
|
||||
const { data: giteaInfo } = useQuery({
|
||||
queryKey: ['gitea-info', id],
|
||||
queryFn: () => giteaApi.getEndpointInfo(id!).then(r => r.data),
|
||||
enabled: isEditing,
|
||||
});
|
||||
|
||||
const draftMutation = useMutation({
|
||||
mutationFn: () => versionsApi.saveDraft(id!, { ...formData, change_message: undefined }),
|
||||
onSuccess: () => {
|
||||
@@ -1099,6 +1105,44 @@ export default function EndpointEditor() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Gitea info */}
|
||||
{isEditing && giteaInfo?.enabled && (
|
||||
<div className="card p-4">
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-gray-700 mb-3">
|
||||
<GitBranch size={16} />
|
||||
<span>Gitea</span>
|
||||
</div>
|
||||
<div className="space-y-2 text-xs">
|
||||
{giteaInfo.file_url && (
|
||||
<a
|
||||
href={giteaInfo.file_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block text-primary-600 hover:text-primary-700 truncate"
|
||||
>
|
||||
View in Gitea
|
||||
</a>
|
||||
)}
|
||||
{giteaInfo.last_commit_sha && (
|
||||
<div className="flex items-center gap-2 text-gray-500">
|
||||
<span>Last commit:</span>
|
||||
<a
|
||||
href={giteaInfo.commit_url || '#'}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="font-mono text-primary-600 hover:text-primary-700"
|
||||
>
|
||||
{giteaInfo.last_commit_sha.slice(0, 7)}
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
{!giteaInfo.last_commit_sha && (
|
||||
<span className="text-gray-400">Not yet synced to Gitea</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Test results */}
|
||||
{testResult && (
|
||||
<div className="card overflow-hidden">
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useState } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { usersApi, dbManagementApi } from '@/services/api';
|
||||
import { usersApi, dbManagementApi, giteaApi } from '@/services/api';
|
||||
import { useAuthStore } from '@/stores/authStore';
|
||||
import toast from 'react-hot-toast';
|
||||
import { User, Lock, UserCircle, Database, Plus, Edit2, Trash2, Eye, EyeOff, Users } from 'lucide-react';
|
||||
import { User, Lock, UserCircle, Database, Plus, Edit2, Trash2, Eye, EyeOff, Users, GitBranch } from 'lucide-react';
|
||||
import Dialog from '@/components/Dialog';
|
||||
import CodeEditor from '@/components/CodeEditor';
|
||||
|
||||
@@ -216,7 +216,7 @@ function PasswordTab({ currentUser }: { currentUser: any }) {
|
||||
}
|
||||
|
||||
function GlobalSettingsTab() {
|
||||
const [subTab, setSubTab] = useState<'databases' | 'users'>('databases');
|
||||
const [subTab, setSubTab] = useState<'databases' | 'users' | 'gitea'>('databases');
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -244,11 +244,262 @@ function GlobalSettingsTab() {
|
||||
<Users className="inline mr-2" size={16} />
|
||||
Пользователи
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setSubTab('gitea')}
|
||||
className={`py-3 px-2 border-b-2 font-medium transition-colors ${
|
||||
subTab === 'gitea'
|
||||
? 'border-primary-600 text-primary-600'
|
||||
: 'border-transparent text-gray-600 hover:text-gray-900'
|
||||
}`}
|
||||
>
|
||||
<GitBranch className="inline mr-2" size={16} />
|
||||
Gitea
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{subTab === 'databases' && <DatabasesSubTab />}
|
||||
{subTab === 'users' && <UsersSubTab />}
|
||||
{subTab === 'gitea' && <GiteaSubTab />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function GiteaSubTab() {
|
||||
const queryClient = useQueryClient();
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
|
||||
const { data: settings, isLoading } = useQuery({
|
||||
queryKey: ['gitea-settings'],
|
||||
queryFn: () => giteaApi.getSettings().then(r => r.data),
|
||||
});
|
||||
|
||||
const { data: syncStatus } = useQuery({
|
||||
queryKey: ['gitea-sync-status'],
|
||||
queryFn: () => giteaApi.getSyncStatus().then(r => r.data),
|
||||
enabled: !!settings?.enabled,
|
||||
});
|
||||
|
||||
const { data: branches } = useQuery({
|
||||
queryKey: ['gitea-branches'],
|
||||
queryFn: () => giteaApi.listBranches().then(r => r.data),
|
||||
enabled: !!settings?.enabled,
|
||||
});
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
enabled: false, url: '', token: '', owner: '', repo: '', prod_branch: 'main',
|
||||
});
|
||||
|
||||
useState(() => {
|
||||
if (settings) setFormData(settings);
|
||||
});
|
||||
|
||||
// Sync form when settings load
|
||||
const prevSettings = settings;
|
||||
if (prevSettings && formData.url === '' && prevSettings.url !== '') {
|
||||
setFormData(prevSettings);
|
||||
}
|
||||
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: (data: any) => giteaApi.updateSettings(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['gitea-settings'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['gitea-branches'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['gitea-sync-status'] });
|
||||
toast.success('Gitea settings saved');
|
||||
},
|
||||
onError: () => toast.error('Failed to save Gitea settings'),
|
||||
});
|
||||
|
||||
const testMutation = useMutation({
|
||||
mutationFn: () => giteaApi.testConnection(),
|
||||
onSuccess: (res) => {
|
||||
if (res.data.success) toast.success(res.data.message);
|
||||
else toast.error(res.data.message);
|
||||
},
|
||||
onError: () => toast.error('Connection test failed'),
|
||||
});
|
||||
|
||||
const syncMutation = useMutation({
|
||||
mutationFn: () => giteaApi.syncAll(),
|
||||
onSuccess: (res) => {
|
||||
toast.success(`Synced ${res.data.synced} endpoints${res.data.errors?.length ? `, ${res.data.errors.length} errors` : ''}`);
|
||||
queryClient.invalidateQueries({ queryKey: ['gitea-sync-status'] });
|
||||
},
|
||||
onError: () => toast.error('Sync failed'),
|
||||
});
|
||||
|
||||
const createBranchMutation = useMutation({
|
||||
mutationFn: (name: string) => giteaApi.createBranch(name),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['gitea-branches'] });
|
||||
toast.success('Branch created');
|
||||
},
|
||||
onError: () => toast.error('Failed to create branch'),
|
||||
});
|
||||
|
||||
const deleteBranchMutation = useMutation({
|
||||
mutationFn: (name: string) => giteaApi.deleteBranch(name),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['gitea-branches'] });
|
||||
toast.success('Branch deleted');
|
||||
},
|
||||
onError: () => toast.error('Failed to delete branch'),
|
||||
});
|
||||
|
||||
if (isLoading) return <div className="text-center py-8"><div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600 mx-auto"></div></div>;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h3 className="text-xl font-semibold text-gray-900 mb-1">Gitea Integration</h3>
|
||||
<p className="text-sm text-gray-600">Version control for endpoints via Gitea (branches, merges, diffs, PR)</p>
|
||||
</div>
|
||||
|
||||
{/* Connection form */}
|
||||
<div className="border border-gray-200 rounded-lg p-4 space-y-4">
|
||||
<label className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={formData.enabled}
|
||||
onChange={(e) => setFormData({ ...formData, enabled: e.target.checked })}
|
||||
className="rounded"
|
||||
/>
|
||||
<span className="text-sm font-medium text-gray-700">Enable Gitea integration</span>
|
||||
</label>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Gitea URL</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.url}
|
||||
onChange={(e) => setFormData({ ...formData, url: e.target.value })}
|
||||
className="input w-full"
|
||||
placeholder="http://gitea:3000"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">API Token</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
value={formData.token}
|
||||
onChange={(e) => setFormData({ ...formData, token: e.target.value })}
|
||||
className="input w-full pr-10"
|
||||
placeholder="gitea_api_token"
|
||||
/>
|
||||
<button type="button" onClick={() => setShowPassword(!showPassword)} className="absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-gray-100 rounded">
|
||||
{showPassword ? <EyeOff size={18} /> : <Eye size={18} />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Owner (user/org)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.owner}
|
||||
onChange={(e) => setFormData({ ...formData, owner: e.target.value })}
|
||||
className="input w-full"
|
||||
placeholder="myorg"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Repository</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.repo}
|
||||
onChange={(e) => setFormData({ ...formData, repo: e.target.value })}
|
||||
className="input w-full"
|
||||
placeholder="kis-endpoints"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Prod Branch</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.prod_branch}
|
||||
onChange={(e) => setFormData({ ...formData, prod_branch: e.target.value })}
|
||||
className="input w-full"
|
||||
placeholder="main"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3 pt-2">
|
||||
<button onClick={() => saveMutation.mutate(formData)} disabled={saveMutation.isPending} className="btn btn-primary">
|
||||
{saveMutation.isPending ? 'Saving...' : 'Save'}
|
||||
</button>
|
||||
<button onClick={() => testMutation.mutate()} disabled={testMutation.isPending} className="btn btn-secondary">
|
||||
{testMutation.isPending ? 'Testing...' : 'Test Connection'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sync status */}
|
||||
{settings?.enabled && (
|
||||
<div className="border border-gray-200 rounded-lg p-4">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900">Sync Status</h4>
|
||||
{syncStatus && (
|
||||
<p className="text-sm text-gray-600">
|
||||
{syncStatus.synced}/{syncStatus.total} endpoints synced
|
||||
{syncStatus.unsynced > 0 && <span className="text-orange-600 ml-1">({syncStatus.unsynced} unsynced)</span>}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<button onClick={() => syncMutation.mutate()} disabled={syncMutation.isPending} className="btn btn-secondary text-sm">
|
||||
{syncMutation.isPending ? 'Syncing...' : 'Sync All'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Branches */}
|
||||
{settings?.enabled && branches && (
|
||||
<div className="border border-gray-200 rounded-lg p-4">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<h4 className="font-medium text-gray-900">Branches ({branches.length})</h4>
|
||||
<button
|
||||
onClick={() => {
|
||||
const name = prompt('Branch name:');
|
||||
if (name) createBranchMutation.mutate(name);
|
||||
}}
|
||||
className="btn btn-secondary text-sm flex items-center gap-1"
|
||||
>
|
||||
<Plus size={14} /> New Branch
|
||||
</button>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{branches.map((b: any) => (
|
||||
<div key={b.name} className="flex items-center justify-between text-sm border border-gray-100 rounded-lg p-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch size={14} className="text-gray-500" />
|
||||
<span className="font-mono font-medium">{b.name}</span>
|
||||
{b.name === (settings?.prod_branch || 'main') && (
|
||||
<span className="text-[10px] bg-green-100 text-green-700 px-1.5 py-0.5 rounded">prod</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-gray-400 font-mono">{b.commit?.id?.slice(0, 7)}</span>
|
||||
{b.name !== (settings?.prod_branch || 'main') && (
|
||||
<button
|
||||
onClick={() => { if (confirm(`Delete branch ${b.name}?`)) deleteBranchMutation.mutate(b.name); }}
|
||||
className="p-1 hover:bg-red-50 rounded text-red-500"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import { AuthResponse, User, Endpoint, Folder, ApiKey, Database, QueryTestResult, ImportPreviewResponse, EndpointVersion } from '@/types';
|
||||
import { AuthResponse, User, Endpoint, Folder, ApiKey, Database, QueryTestResult, ImportPreviewResponse, EndpointVersion, GiteaSettings, GiteaBranch, GiteaCommit, GiteaEndpointInfo } from '@/types';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
@@ -164,6 +164,23 @@ export const versionsApi = {
|
||||
api.get<EndpointVersion>(`/endpoints/${endpointId}/draft`),
|
||||
};
|
||||
|
||||
// Gitea API
|
||||
export const giteaApi = {
|
||||
getSettings: () => api.get<GiteaSettings>('/gitea/settings'),
|
||||
updateSettings: (data: Partial<GiteaSettings>) => api.put('/gitea/settings', data),
|
||||
testConnection: () => api.post<{ success: boolean; message: string }>('/gitea/test'),
|
||||
syncAll: () => api.post<{ synced: number; errors: string[] }>('/gitea/sync-all'),
|
||||
getSyncStatus: () => api.get<{ total: number; synced: number; unsynced: number }>('/gitea/sync-status'),
|
||||
listBranches: () => api.get<GiteaBranch[]>('/gitea/branches'),
|
||||
createBranch: (name: string, from?: string) => api.post('/gitea/branches', { name, from }),
|
||||
deleteBranch: (name: string) => api.delete(`/gitea/branches/${encodeURIComponent(name)}`),
|
||||
compareBranches: (base: string, head: string) => api.get('/gitea/compare', { params: { base, head } }),
|
||||
getCommitHistory: (path?: string, branch?: string) => api.get<GiteaCommit[]>('/gitea/commits', { params: { path, branch } }),
|
||||
getEndpointInfo: (endpointId: string) => api.get<GiteaEndpointInfo>(`/gitea/endpoints/${endpointId}/info`),
|
||||
createPR: (data: { title: string; head: string; base?: string; body?: string }) => api.post('/gitea/pulls', data),
|
||||
mergePR: (index: number) => api.post(`/gitea/pulls/${index}/merge`),
|
||||
};
|
||||
|
||||
// Folders API
|
||||
export const foldersApi = {
|
||||
getAll: () =>
|
||||
|
||||
@@ -134,6 +134,38 @@ export interface QueryTestResult {
|
||||
processedQuery?: string;
|
||||
}
|
||||
|
||||
export interface GiteaSettings {
|
||||
enabled: boolean;
|
||||
url: string;
|
||||
token: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
prod_branch: string;
|
||||
}
|
||||
|
||||
export interface GiteaBranch {
|
||||
name: string;
|
||||
commit: { id: string; message: string; timestamp: string };
|
||||
}
|
||||
|
||||
export interface GiteaCommit {
|
||||
sha: string;
|
||||
message: string;
|
||||
author: { name: string; email: string; date: string };
|
||||
html_url: string;
|
||||
}
|
||||
|
||||
export interface GiteaEndpointInfo {
|
||||
enabled: boolean;
|
||||
url?: string;
|
||||
owner?: string;
|
||||
repo?: string;
|
||||
file_url?: string;
|
||||
repo_path?: string;
|
||||
last_commit_sha?: string;
|
||||
commit_url?: string;
|
||||
}
|
||||
|
||||
export type VersionStatus = 'draft' | 'published' | 'archived';
|
||||
|
||||
export interface EndpointVersion {
|
||||
|
||||
Reference in New Issue
Block a user