Files
gitops/ts/providers/classes.baseprovider.ts

76 lines
2.1 KiB
TypeScript

import type * as interfaces from '../../ts_interfaces/index.ts';
export interface ITestConnectionResult {
ok: boolean;
error?: string;
}
export interface IListOptions {
search?: string;
page?: number;
perPage?: number;
}
/**
* Abstract base class for Git provider implementations.
* Subclasses implement Gitea API v1 or GitLab API v4.
*/
export abstract class BaseProvider {
constructor(
public readonly connectionId: string,
public readonly baseUrl: string,
protected readonly token: string,
) {}
// Connection
abstract testConnection(): Promise<ITestConnectionResult>;
// Projects
abstract getProjects(opts?: IListOptions): Promise<interfaces.data.IProject[]>;
// Groups / Orgs
abstract getGroups(opts?: IListOptions): Promise<interfaces.data.IGroup[]>;
// Secrets — project scope
abstract getProjectSecrets(projectId: string): Promise<interfaces.data.ISecret[]>;
abstract createProjectSecret(
projectId: string,
key: string,
value: string,
): Promise<interfaces.data.ISecret>;
abstract updateProjectSecret(
projectId: string,
key: string,
value: string,
): Promise<interfaces.data.ISecret>;
abstract deleteProjectSecret(projectId: string, key: string): Promise<void>;
// Secrets — group scope
abstract getGroupSecrets(groupId: string): Promise<interfaces.data.ISecret[]>;
abstract createGroupSecret(
groupId: string,
key: string,
value: string,
): Promise<interfaces.data.ISecret>;
abstract updateGroupSecret(
groupId: string,
key: string,
value: string,
): Promise<interfaces.data.ISecret>;
abstract deleteGroupSecret(groupId: string, key: string): Promise<void>;
// Pipelines / CI
abstract getPipelines(
projectId: string,
opts?: IListOptions,
): Promise<interfaces.data.IPipeline[]>;
abstract getPipelineJobs(
projectId: string,
pipelineId: string,
): Promise<interfaces.data.IPipelineJob[]>;
abstract getJobLog(projectId: string, jobId: string): Promise<string>;
abstract retryPipeline(projectId: string, pipelineId: string): Promise<void>;
abstract cancelPipeline(projectId: string, pipelineId: string): Promise<void>;
}