mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Merge pull request #432 from chriswritescode-dev/feat/repo-secrets
feat(secrets): repository secrets and variables for agent shells and terminals
This commit is contained in:
77 files changed
+4289
-206
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { SecretKind, SecretListResponse, SetSecretRequest } from '@opencode-manager/shared/schemas'
|
||||
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
|
||||
|
||||
export type SecretScope = { scope: 'global' } | { scope: 'repo'; repoId: number }
|
||||
|
||||
const KIND_SEGMENT: Record<SecretKind, string> = {
|
||||
secret: 'secrets',
|
||||
variable: 'variables',
|
||||
}
|
||||
|
||||
function secretsPath(scope: SecretScope, kind: SecretKind): string {
|
||||
const segment = KIND_SEGMENT[kind]
|
||||
return scope.scope === 'global'
|
||||
? `${API_BASE_URL}/api/${segment}`
|
||||
: `${API_BASE_URL}/api/repos/${scope.repoId}/${segment}`
|
||||
}
|
||||
|
||||
export async function listSecrets(scope: SecretScope, kind: SecretKind): Promise<SecretListResponse> {
|
||||
return fetchWrapper(secretsPath(scope, kind))
|
||||
}
|
||||
|
||||
export async function setSecret(
|
||||
scope: SecretScope,
|
||||
kind: SecretKind,
|
||||
name: string,
|
||||
request: SetSecretRequest,
|
||||
): Promise<void> {
|
||||
return fetchWrapperVoid(`${secretsPath(scope, kind)}/${encodeURIComponent(name)}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request),
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteSecret(
|
||||
scope: SecretScope,
|
||||
kind: SecretKind,
|
||||
name: string,
|
||||
environment?: string,
|
||||
): Promise<void> {
|
||||
return fetchWrapperVoid(`${secretsPath(scope, kind)}/${encodeURIComponent(name)}`, {
|
||||
method: 'DELETE',
|
||||
...(environment ? { params: { environment } } : {}),
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user