Gitea-Client herausgelöst, Konfiguration für Organisation und System-Konto, Test-Nachbauten
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ea71b3f1c3
commit
531ee2a02b
6 files changed
+824
-47
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { config } from '../config.js'
|
||||
|
||||
/**
|
||||
* Baut die Authorization-/Content-Type-Header fuer einen Gitea-API-Aufruf.
|
||||
* Wirft, wenn GITEA_API_TOKEN nicht gesetzt ist.
|
||||
*/
|
||||
function giteaHeaders() {
|
||||
if (!config.gitea.apiToken) {
|
||||
throw new Error('GITEA_API_TOKEN fehlt in .env')
|
||||
}
|
||||
return {
|
||||
Authorization: `token ${config.gitea.apiToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruft `${config.gitea.baseUrl}/api/v1<path>` auf und liefert die geparste JSON-Antwort
|
||||
* (oder null ohne Body). Eine Nicht-2xx-Antwort wirft eine Error mit .status; ein 409
|
||||
* "same name already exists" wird in die deutsche Meldung uebersetzt (Subdomain-/Repo-Name).
|
||||
*/
|
||||
export async function giteaFetch(path, options = {}) {
|
||||
const response = await fetch(`${config.gitea.baseUrl}/api/v1${path}`, {
|
||||
...options,
|
||||
headers: { ...giteaHeaders(), ...options.headers },
|
||||
})
|
||||
|
||||
const text = await response.text()
|
||||
let data = null
|
||||
if (text) {
|
||||
try {
|
||||
data = JSON.parse(text)
|
||||
} catch {
|
||||
data = { message: text }
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = data?.message || `Gitea ${response.status}`
|
||||
if (response.status === 409 && /same name already exists/i.test(message)) {
|
||||
message = 'Ein Gitea-Repository mit diesem Namen existiert bereits. Bitte einen anderen Subdomain-/Repo-Namen w�hlen.'
|
||||
}
|
||||
const error = new Error(message)
|
||||
error.status = response.status
|
||||
throw error
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Zerlegt "owner/repo" in [owner, repo]. Reines String-Splitting ohne Validierung -
|
||||
* fuer nicht "owner/repo"-foermige Eingaben ist das Ergebnis entsprechend kurz/lang.
|
||||
*/
|
||||
export function splitRepo(fullName) {
|
||||
return String(fullName || '').split('/')
|
||||
}
|
||||
Reference in new issue
Block a user