Commit 2dd589eb authored by Mahmoud Aglan's avatar Mahmoud Aglan

fixgitlabConn

parent e9fb4382
...@@ -109,12 +109,18 @@ def update_settings(body: SettingsBody, admin: User = Depends(require_superadmin ...@@ -109,12 +109,18 @@ def update_settings(body: SettingsBody, admin: User = Depends(require_superadmin
@router.post("/test-connection") @router.post("/test-connection")
async def test_connection(admin: User = Depends(require_superadmin), db: Session = Depends(get_db)): async def test_connection(body: SettingsBody, admin: User = Depends(require_superadmin), db: Session = Depends(get_db)):
s = db.query(GitLabSettings).first() url = body.gitlab_url.rstrip("/")
if not s or not s.gitlab_url or not s.gitlab_token: if not body.gitlab_token or body.gitlab_token == "UNCHANGED":
raise HTTPException(400, "GitLab URL and token not configured") s = db.query(GitLabSettings).first()
token = s.gitlab_token if s else ""
else:
token = body.gitlab_token
if not url or not token:
raise HTTPException(400, "GitLab URL and token not provided")
try: try:
result = await gitlab_service.test_connection(s.gitlab_url, s.gitlab_token) result = await gitlab_service.test_connection(url, token)
return result return result
except gitlab_service.GitLabError as e: except gitlab_service.GitLabError as e:
raise HTTPException(e.status_code, f"Connection failed: {e.detail}") raise HTTPException(e.status_code, f"Connection failed: {e.detail}")
......
...@@ -139,7 +139,7 @@ export async function downloadZip(token, markdown, chatTitle) { ...@@ -139,7 +139,7 @@ export async function downloadZip(token, markdown, chatTitle) {
export const gitlabGetSettings = (token) => request("GET", "/gitlab/settings", token); export const gitlabGetSettings = (token) => request("GET", "/gitlab/settings", token);
export const gitlabUpdateSettings = (token, data) => request("PUT", "/gitlab/settings", token, data); export const gitlabUpdateSettings = (token, data) => request("PUT", "/gitlab/settings", token, data);
export const gitlabTestConnection = (token) => request("POST", "/gitlab/test-connection", token); export const gitlabTestConnection = (token, data) => request("POST", "/gitlab/test-connection", token, data);
export const gitlabSearchProjects = (token, search, owned) => export const gitlabSearchProjects = (token, search, owned) =>
request("GET", `/gitlab/projects?search=${encodeURIComponent(search || "")}&owned=${owned || false}`, token); request("GET", `/gitlab/projects?search=${encodeURIComponent(search || "")}&owned=${owned || false}`, token);
export const gitlabCreateProject = (token, data) => request("POST", "/gitlab/projects", token, data); export const gitlabCreateProject = (token, data) => request("POST", "/gitlab/projects", token, data);
......
...@@ -70,7 +70,7 @@ export default function GitLabPage() { ...@@ -70,7 +70,7 @@ export default function GitLabPage() {
async function handleTest() { async function handleTest() {
setTesting(true); setTestResult(null); setTesting(true); setTestResult(null);
try { try {
const r = await gitlabTestConnection(t); const r = await gitlabTestConnection(t, { gitlab_url: url, gitlab_token: token || "UNCHANGED" });
setTestResult({ ok: true, msg: `Connected as ${r.name} (@${r.username})` }); setTestResult({ ok: true, msg: `Connected as ${r.name} (@${r.username})` });
} catch (e) { setTestResult({ ok: false, msg: e.message }); } } catch (e) { setTestResult({ ok: false, msg: e.message }); }
setTesting(false); setTesting(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment