BREAKING CHANGE(providers): switch GitLab and Gitea providers to use @apiclient.xyz client libraries and export clients via plugins
This commit is contained in:
18
changelog.md
Normal file
18
changelog.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-02-24 - 2.0.0 - BREAKING CHANGE(providers)
|
||||
switch GitLab and Gitea providers to use @apiclient.xyz client libraries and export clients via plugins
|
||||
|
||||
- Add new dependencies: @apiclient.xyz/gitea@^1.0.3 and @apiclient.xyz/gitlab@^2.0.3 in deno.json
|
||||
- Export giteaClient and gitlabClient from ts/plugins.ts
|
||||
- Refactor GiteaProvider to use plugins.giteaClient.GiteaClient for all API interactions and update mapping types/fields
|
||||
- Refactor GitLabProvider to use plugins.gitlabClient.GitLabClient for all API interactions and update mapping types/fields
|
||||
- Remove BaseProvider.apiFetch helper and setAuthHeader abstract method (breaking change to BaseProvider API)
|
||||
- Adjust mapping logic: simplify Gitea visibility, change group name/path and webUrl construction, update GitLab topics and projectCount handling
|
||||
|
||||
## 2026-02-24 - 1.0.0 - initial release
|
||||
Initial commit and first release of the project.
|
||||
|
||||
- Project initialized with the initial codebase and repository scaffold.
|
||||
- Base files and basic configuration added.
|
||||
- Tagged first release as 1.0.0.
|
||||
@@ -15,7 +15,9 @@
|
||||
"@api.global/typedrequest": "npm:@api.global/typedrequest@^3.2.6",
|
||||
"@api.global/typedserver": "npm:@api.global/typedserver@^8.3.0",
|
||||
"@push.rocks/smartguard": "npm:@push.rocks/smartguard@^3.1.0",
|
||||
"@push.rocks/smartjwt": "npm:@push.rocks/smartjwt@^2.2.1"
|
||||
"@push.rocks/smartjwt": "npm:@push.rocks/smartjwt@^2.2.1",
|
||||
"@apiclient.xyz/gitea": "npm:@apiclient.xyz/gitea@^1.0.3",
|
||||
"@apiclient.xyz/gitlab": "npm:@apiclient.xyz/gitlab@^2.0.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"build": "tsbundle",
|
||||
"startTs": "deno run --allow-all mod.ts server",
|
||||
"watch": "tswatch website"
|
||||
"watch": "tswatch"
|
||||
},
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
|
||||
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@serve.zone/gitops',
|
||||
version: '2.0.0',
|
||||
description: 'GitOps management app for Gitea and GitLab - manage secrets, browse projects, view CI pipelines, and stream build logs'
|
||||
}
|
||||
@@ -18,3 +18,8 @@ export { typedrequest, typedserver };
|
||||
import * as smartguard from '@push.rocks/smartguard';
|
||||
import * as smartjwt from '@push.rocks/smartjwt';
|
||||
export { smartguard, smartjwt };
|
||||
|
||||
// API Clients
|
||||
import * as giteaClient from '@apiclient.xyz/gitea';
|
||||
import * as gitlabClient from '@apiclient.xyz/gitlab';
|
||||
export { giteaClient, gitlabClient };
|
||||
|
||||
@@ -72,18 +72,4 @@ export abstract class BaseProvider {
|
||||
abstract retryPipeline(projectId: string, pipelineId: string): Promise<void>;
|
||||
abstract cancelPipeline(projectId: string, pipelineId: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Helper for making authenticated fetch requests
|
||||
*/
|
||||
protected async apiFetch(
|
||||
path: string,
|
||||
options: RequestInit = {},
|
||||
): Promise<Response> {
|
||||
const url = `${this.baseUrl.replace(/\/+$/, '')}${path}`;
|
||||
const headers = new Headers(options.headers);
|
||||
this.setAuthHeader(headers);
|
||||
return fetch(url, { ...options, headers });
|
||||
}
|
||||
|
||||
protected abstract setAuthHeader(headers: Headers): void;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as plugins from '../plugins.ts';
|
||||
import type * as interfaces from '../../ts_interfaces/index.ts';
|
||||
import { BaseProvider, type ITestConnectionResult, type IListOptions } from './classes.baseprovider.ts';
|
||||
|
||||
@@ -5,54 +6,31 @@ import { BaseProvider, type ITestConnectionResult, type IListOptions } from './c
|
||||
* Gitea API v1 provider implementation
|
||||
*/
|
||||
export class GiteaProvider extends BaseProvider {
|
||||
protected setAuthHeader(headers: Headers): void {
|
||||
headers.set('Authorization', `token ${this.token}`);
|
||||
if (!headers.has('Content-Type')) {
|
||||
headers.set('Content-Type', 'application/json');
|
||||
}
|
||||
private client: plugins.giteaClient.GiteaClient;
|
||||
|
||||
constructor(connectionId: string, baseUrl: string, token: string) {
|
||||
super(connectionId, baseUrl, token);
|
||||
this.client = new plugins.giteaClient.GiteaClient(baseUrl, token);
|
||||
}
|
||||
|
||||
async testConnection(): Promise<ITestConnectionResult> {
|
||||
try {
|
||||
const resp = await this.apiFetch('/api/v1/user');
|
||||
if (!resp.ok) {
|
||||
return { ok: false, error: `HTTP ${resp.status}: ${resp.statusText}` };
|
||||
}
|
||||
return { ok: true };
|
||||
} catch (err) {
|
||||
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
||||
}
|
||||
return this.client.testConnection();
|
||||
}
|
||||
|
||||
async getProjects(opts?: IListOptions): Promise<interfaces.data.IProject[]> {
|
||||
const page = opts?.page || 1;
|
||||
const limit = opts?.perPage || 50;
|
||||
let url = `/api/v1/repos/search?page=${page}&limit=${limit}&sort=updated`;
|
||||
if (opts?.search) {
|
||||
url += `&q=${encodeURIComponent(opts.search)}`;
|
||||
}
|
||||
const resp = await this.apiFetch(url);
|
||||
if (!resp.ok) throw new Error(`Gitea getProjects failed: ${resp.status}`);
|
||||
const body = await resp.json();
|
||||
const repos = body.data || body;
|
||||
return (repos as any[]).map((r) => this.mapProject(r));
|
||||
const repos = await this.client.getRepos(opts);
|
||||
return repos.map((r) => this.mapProject(r));
|
||||
}
|
||||
|
||||
async getGroups(opts?: IListOptions): Promise<interfaces.data.IGroup[]> {
|
||||
const page = opts?.page || 1;
|
||||
const limit = opts?.perPage || 50;
|
||||
const resp = await this.apiFetch(`/api/v1/orgs?page=${page}&limit=${limit}`);
|
||||
if (!resp.ok) throw new Error(`Gitea getGroups failed: ${resp.status}`);
|
||||
const orgs = await resp.json() as any[];
|
||||
const orgs = await this.client.getOrgs(opts);
|
||||
return orgs.map((o) => this.mapGroup(o));
|
||||
}
|
||||
|
||||
// --- Project Secrets ---
|
||||
|
||||
async getProjectSecrets(projectId: string): Promise<interfaces.data.ISecret[]> {
|
||||
const resp = await this.apiFetch(`/api/v1/repos/${projectId}/actions/secrets`);
|
||||
if (!resp.ok) throw new Error(`Gitea getProjectSecrets failed: ${resp.status}`);
|
||||
const secrets = await resp.json() as any[];
|
||||
const secrets = await this.client.getRepoSecrets(projectId);
|
||||
return secrets.map((s) => this.mapSecret(s, 'project', projectId));
|
||||
}
|
||||
|
||||
@@ -61,11 +39,7 @@ export class GiteaProvider extends BaseProvider {
|
||||
key: string,
|
||||
value: string,
|
||||
): Promise<interfaces.data.ISecret> {
|
||||
const resp = await this.apiFetch(`/api/v1/repos/${projectId}/actions/secrets/${key}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ data: value }),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`Gitea createProjectSecret failed: ${resp.status}`);
|
||||
await this.client.setRepoSecret(projectId, key, value);
|
||||
return { key, value: '***', protected: false, masked: true, scope: 'project', scopeId: projectId, connectionId: this.connectionId, environment: '*' };
|
||||
}
|
||||
|
||||
@@ -78,18 +52,13 @@ export class GiteaProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
async deleteProjectSecret(projectId: string, key: string): Promise<void> {
|
||||
const resp = await this.apiFetch(`/api/v1/repos/${projectId}/actions/secrets/${key}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!resp.ok) throw new Error(`Gitea deleteProjectSecret failed: ${resp.status}`);
|
||||
await this.client.deleteRepoSecret(projectId, key);
|
||||
}
|
||||
|
||||
// --- Group Secrets ---
|
||||
|
||||
async getGroupSecrets(groupId: string): Promise<interfaces.data.ISecret[]> {
|
||||
const resp = await this.apiFetch(`/api/v1/orgs/${groupId}/actions/secrets`);
|
||||
if (!resp.ok) throw new Error(`Gitea getGroupSecrets failed: ${resp.status}`);
|
||||
const secrets = await resp.json() as any[];
|
||||
const secrets = await this.client.getOrgSecrets(groupId);
|
||||
return secrets.map((s) => this.mapSecret(s, 'group', groupId));
|
||||
}
|
||||
|
||||
@@ -98,11 +67,7 @@ export class GiteaProvider extends BaseProvider {
|
||||
key: string,
|
||||
value: string,
|
||||
): Promise<interfaces.data.ISecret> {
|
||||
const resp = await this.apiFetch(`/api/v1/orgs/${groupId}/actions/secrets/${key}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ data: value }),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`Gitea createGroupSecret failed: ${resp.status}`);
|
||||
await this.client.setOrgSecret(groupId, key, value);
|
||||
return { key, value: '***', protected: false, masked: true, scope: 'group', scopeId: groupId, connectionId: this.connectionId, environment: '*' };
|
||||
}
|
||||
|
||||
@@ -115,10 +80,7 @@ export class GiteaProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
async deleteGroupSecret(groupId: string, key: string): Promise<void> {
|
||||
const resp = await this.apiFetch(`/api/v1/orgs/${groupId}/actions/secrets/${key}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!resp.ok) throw new Error(`Gitea deleteGroupSecret failed: ${resp.status}`);
|
||||
await this.client.deleteOrgSecret(groupId, key);
|
||||
}
|
||||
|
||||
// --- Pipelines (Action Runs) ---
|
||||
@@ -127,58 +89,33 @@ export class GiteaProvider extends BaseProvider {
|
||||
projectId: string,
|
||||
opts?: IListOptions,
|
||||
): Promise<interfaces.data.IPipeline[]> {
|
||||
const page = opts?.page || 1;
|
||||
const limit = opts?.perPage || 30;
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v1/repos/${projectId}/actions/runs?page=${page}&limit=${limit}`,
|
||||
);
|
||||
if (!resp.ok) throw new Error(`Gitea getPipelines failed: ${resp.status}`);
|
||||
const body = await resp.json();
|
||||
const runs = body.workflow_runs || body;
|
||||
return (runs as any[]).map((r) => this.mapPipeline(r, projectId));
|
||||
const runs = await this.client.getActionRuns(projectId, opts);
|
||||
return runs.map((r) => this.mapPipeline(r, projectId));
|
||||
}
|
||||
|
||||
async getPipelineJobs(
|
||||
projectId: string,
|
||||
pipelineId: string,
|
||||
): Promise<interfaces.data.IPipelineJob[]> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v1/repos/${projectId}/actions/runs/${pipelineId}/jobs`,
|
||||
);
|
||||
if (!resp.ok) throw new Error(`Gitea getPipelineJobs failed: ${resp.status}`);
|
||||
const body = await resp.json();
|
||||
const jobs = body.jobs || body;
|
||||
return (jobs as any[]).map((j) => this.mapJob(j, pipelineId));
|
||||
const jobs = await this.client.getActionRunJobs(projectId, Number(pipelineId));
|
||||
return jobs.map((j) => this.mapJob(j, pipelineId));
|
||||
}
|
||||
|
||||
async getJobLog(projectId: string, jobId: string): Promise<string> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v1/repos/${projectId}/actions/jobs/${jobId}/logs`,
|
||||
);
|
||||
if (!resp.ok) throw new Error(`Gitea getJobLog failed: ${resp.status}`);
|
||||
return resp.text();
|
||||
return this.client.getJobLog(projectId, Number(jobId));
|
||||
}
|
||||
|
||||
async retryPipeline(projectId: string, pipelineId: string): Promise<void> {
|
||||
// Gitea doesn't have a native retry — we re-run the workflow
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v1/repos/${projectId}/actions/runs/${pipelineId}/rerun`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
if (!resp.ok) throw new Error(`Gitea retryPipeline failed: ${resp.status}`);
|
||||
await this.client.rerunAction(projectId, Number(pipelineId));
|
||||
}
|
||||
|
||||
async cancelPipeline(projectId: string, pipelineId: string): Promise<void> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v1/repos/${projectId}/actions/runs/${pipelineId}/cancel`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
if (!resp.ok) throw new Error(`Gitea cancelPipeline failed: ${resp.status}`);
|
||||
await this.client.cancelAction(projectId, Number(pipelineId));
|
||||
}
|
||||
|
||||
// --- Mappers ---
|
||||
|
||||
private mapProject(r: any): interfaces.data.IProject {
|
||||
private mapProject(r: plugins.giteaClient.IGiteaRepository): interfaces.data.IProject {
|
||||
return {
|
||||
id: String(r.id),
|
||||
name: r.name || '',
|
||||
@@ -187,28 +124,28 @@ export class GiteaProvider extends BaseProvider {
|
||||
defaultBranch: r.default_branch || 'main',
|
||||
webUrl: r.html_url || '',
|
||||
connectionId: this.connectionId,
|
||||
visibility: r.private ? 'private' : (r.internal ? 'internal' : 'public'),
|
||||
visibility: r.private ? 'private' : 'public',
|
||||
topics: r.topics || [],
|
||||
lastActivity: r.updated_at || '',
|
||||
};
|
||||
}
|
||||
|
||||
private mapGroup(o: any): interfaces.data.IGroup {
|
||||
private mapGroup(o: plugins.giteaClient.IGiteaOrganization): interfaces.data.IGroup {
|
||||
return {
|
||||
id: String(o.id || o.name),
|
||||
name: o.name || o.username || '',
|
||||
fullPath: o.name || o.username || '',
|
||||
name: o.name || '',
|
||||
fullPath: o.name || '',
|
||||
description: o.description || '',
|
||||
webUrl: `${this.baseUrl}/${o.name || o.username}`,
|
||||
webUrl: `${this.baseUrl}/${o.name}`,
|
||||
connectionId: this.connectionId,
|
||||
visibility: o.visibility || 'public',
|
||||
projectCount: o.repo_count || 0,
|
||||
};
|
||||
}
|
||||
|
||||
private mapSecret(s: any, scope: 'project' | 'group', scopeId: string): interfaces.data.ISecret {
|
||||
private mapSecret(s: plugins.giteaClient.IGiteaSecret, scope: 'project' | 'group', scopeId: string): interfaces.data.ISecret {
|
||||
return {
|
||||
key: s.name || s.key || '',
|
||||
key: s.name || '',
|
||||
value: '***',
|
||||
protected: false,
|
||||
masked: true,
|
||||
@@ -219,7 +156,7 @@ export class GiteaProvider extends BaseProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private mapPipeline(r: any, projectId: string): interfaces.data.IPipeline {
|
||||
private mapPipeline(r: plugins.giteaClient.IGiteaActionRun, projectId: string): interfaces.data.IPipeline {
|
||||
return {
|
||||
id: String(r.id),
|
||||
projectId,
|
||||
@@ -235,7 +172,7 @@ export class GiteaProvider extends BaseProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private mapJob(j: any, pipelineId: string): interfaces.data.IPipelineJob {
|
||||
private mapJob(j: plugins.giteaClient.IGiteaActionRunJob, pipelineId: string): interfaces.data.IPipelineJob {
|
||||
return {
|
||||
id: String(j.id),
|
||||
pipelineId,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as plugins from '../plugins.ts';
|
||||
import type * as interfaces from '../../ts_interfaces/index.ts';
|
||||
import { BaseProvider, type ITestConnectionResult, type IListOptions } from './classes.baseprovider.ts';
|
||||
|
||||
@@ -5,57 +6,31 @@ import { BaseProvider, type ITestConnectionResult, type IListOptions } from './c
|
||||
* GitLab API v4 provider implementation
|
||||
*/
|
||||
export class GitLabProvider extends BaseProvider {
|
||||
protected setAuthHeader(headers: Headers): void {
|
||||
headers.set('PRIVATE-TOKEN', this.token);
|
||||
if (!headers.has('Content-Type')) {
|
||||
headers.set('Content-Type', 'application/json');
|
||||
}
|
||||
private client: plugins.gitlabClient.GitLabClient;
|
||||
|
||||
constructor(connectionId: string, baseUrl: string, token: string) {
|
||||
super(connectionId, baseUrl, token);
|
||||
this.client = new plugins.gitlabClient.GitLabClient(baseUrl, token);
|
||||
}
|
||||
|
||||
async testConnection(): Promise<ITestConnectionResult> {
|
||||
try {
|
||||
const resp = await this.apiFetch('/api/v4/user');
|
||||
if (!resp.ok) {
|
||||
return { ok: false, error: `HTTP ${resp.status}: ${resp.statusText}` };
|
||||
}
|
||||
return { ok: true };
|
||||
} catch (err) {
|
||||
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
||||
}
|
||||
return this.client.testConnection();
|
||||
}
|
||||
|
||||
async getProjects(opts?: IListOptions): Promise<interfaces.data.IProject[]> {
|
||||
const page = opts?.page || 1;
|
||||
const perPage = opts?.perPage || 50;
|
||||
let url = `/api/v4/projects?page=${page}&per_page=${perPage}&order_by=updated_at&sort=desc&membership=true`;
|
||||
if (opts?.search) {
|
||||
url += `&search=${encodeURIComponent(opts.search)}`;
|
||||
}
|
||||
const resp = await this.apiFetch(url);
|
||||
if (!resp.ok) throw new Error(`GitLab getProjects failed: ${resp.status}`);
|
||||
const projects = await resp.json() as any[];
|
||||
const projects = await this.client.getProjects(opts);
|
||||
return projects.map((p) => this.mapProject(p));
|
||||
}
|
||||
|
||||
async getGroups(opts?: IListOptions): Promise<interfaces.data.IGroup[]> {
|
||||
const page = opts?.page || 1;
|
||||
const perPage = opts?.perPage || 50;
|
||||
let url = `/api/v4/groups?page=${page}&per_page=${perPage}&order_by=name&sort=asc`;
|
||||
if (opts?.search) {
|
||||
url += `&search=${encodeURIComponent(opts.search)}`;
|
||||
}
|
||||
const resp = await this.apiFetch(url);
|
||||
if (!resp.ok) throw new Error(`GitLab getGroups failed: ${resp.status}`);
|
||||
const groups = await resp.json() as any[];
|
||||
const groups = await this.client.getGroups(opts);
|
||||
return groups.map((g) => this.mapGroup(g));
|
||||
}
|
||||
|
||||
// --- Project Secrets (CI/CD Variables) ---
|
||||
|
||||
async getProjectSecrets(projectId: string): Promise<interfaces.data.ISecret[]> {
|
||||
const resp = await this.apiFetch(`/api/v4/projects/${encodeURIComponent(projectId)}/variables`);
|
||||
if (!resp.ok) throw new Error(`GitLab getProjectSecrets failed: ${resp.status}`);
|
||||
const vars = await resp.json() as any[];
|
||||
const vars = await this.client.getProjectVariables(projectId);
|
||||
return vars.map((v) => this.mapVariable(v, 'project', projectId));
|
||||
}
|
||||
|
||||
@@ -64,12 +39,7 @@ export class GitLabProvider extends BaseProvider {
|
||||
key: string,
|
||||
value: string,
|
||||
): Promise<interfaces.data.ISecret> {
|
||||
const resp = await this.apiFetch(`/api/v4/projects/${encodeURIComponent(projectId)}/variables`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ key, value, protected: false, masked: false }),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`GitLab createProjectSecret failed: ${resp.status}`);
|
||||
const v = await resp.json();
|
||||
const v = await this.client.createProjectVariable(projectId, key, value);
|
||||
return this.mapVariable(v, 'project', projectId);
|
||||
}
|
||||
|
||||
@@ -78,32 +48,18 @@ export class GitLabProvider extends BaseProvider {
|
||||
key: string,
|
||||
value: string,
|
||||
): Promise<interfaces.data.ISecret> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/projects/${encodeURIComponent(projectId)}/variables/${encodeURIComponent(key)}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ value }),
|
||||
},
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab updateProjectSecret failed: ${resp.status}`);
|
||||
const v = await resp.json();
|
||||
const v = await this.client.updateProjectVariable(projectId, key, value);
|
||||
return this.mapVariable(v, 'project', projectId);
|
||||
}
|
||||
|
||||
async deleteProjectSecret(projectId: string, key: string): Promise<void> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/projects/${encodeURIComponent(projectId)}/variables/${encodeURIComponent(key)}`,
|
||||
{ method: 'DELETE' },
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab deleteProjectSecret failed: ${resp.status}`);
|
||||
await this.client.deleteProjectVariable(projectId, key);
|
||||
}
|
||||
|
||||
// --- Group Secrets (CI/CD Variables) ---
|
||||
|
||||
async getGroupSecrets(groupId: string): Promise<interfaces.data.ISecret[]> {
|
||||
const resp = await this.apiFetch(`/api/v4/groups/${encodeURIComponent(groupId)}/variables`);
|
||||
if (!resp.ok) throw new Error(`GitLab getGroupSecrets failed: ${resp.status}`);
|
||||
const vars = await resp.json() as any[];
|
||||
const vars = await this.client.getGroupVariables(groupId);
|
||||
return vars.map((v) => this.mapVariable(v, 'group', groupId));
|
||||
}
|
||||
|
||||
@@ -112,12 +68,7 @@ export class GitLabProvider extends BaseProvider {
|
||||
key: string,
|
||||
value: string,
|
||||
): Promise<interfaces.data.ISecret> {
|
||||
const resp = await this.apiFetch(`/api/v4/groups/${encodeURIComponent(groupId)}/variables`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ key, value, protected: false, masked: false }),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`GitLab createGroupSecret failed: ${resp.status}`);
|
||||
const v = await resp.json();
|
||||
const v = await this.client.createGroupVariable(groupId, key, value);
|
||||
return this.mapVariable(v, 'group', groupId);
|
||||
}
|
||||
|
||||
@@ -126,24 +77,12 @@ export class GitLabProvider extends BaseProvider {
|
||||
key: string,
|
||||
value: string,
|
||||
): Promise<interfaces.data.ISecret> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/groups/${encodeURIComponent(groupId)}/variables/${encodeURIComponent(key)}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ value }),
|
||||
},
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab updateGroupSecret failed: ${resp.status}`);
|
||||
const v = await resp.json();
|
||||
const v = await this.client.updateGroupVariable(groupId, key, value);
|
||||
return this.mapVariable(v, 'group', groupId);
|
||||
}
|
||||
|
||||
async deleteGroupSecret(groupId: string, key: string): Promise<void> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/groups/${encodeURIComponent(groupId)}/variables/${encodeURIComponent(key)}`,
|
||||
{ method: 'DELETE' },
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab deleteGroupSecret failed: ${resp.status}`);
|
||||
await this.client.deleteGroupVariable(groupId, key);
|
||||
}
|
||||
|
||||
// --- Pipelines ---
|
||||
@@ -152,13 +91,7 @@ export class GitLabProvider extends BaseProvider {
|
||||
projectId: string,
|
||||
opts?: IListOptions,
|
||||
): Promise<interfaces.data.IPipeline[]> {
|
||||
const page = opts?.page || 1;
|
||||
const perPage = opts?.perPage || 30;
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/projects/${encodeURIComponent(projectId)}/pipelines?page=${page}&per_page=${perPage}&order_by=updated_at&sort=desc`,
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab getPipelines failed: ${resp.status}`);
|
||||
const pipelines = await resp.json() as any[];
|
||||
const pipelines = await this.client.getPipelines(projectId, opts);
|
||||
return pipelines.map((p) => this.mapPipeline(p, projectId));
|
||||
}
|
||||
|
||||
@@ -166,42 +99,25 @@ export class GitLabProvider extends BaseProvider {
|
||||
projectId: string,
|
||||
pipelineId: string,
|
||||
): Promise<interfaces.data.IPipelineJob[]> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/projects/${encodeURIComponent(projectId)}/pipelines/${pipelineId}/jobs`,
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab getPipelineJobs failed: ${resp.status}`);
|
||||
const jobs = await resp.json() as any[];
|
||||
const jobs = await this.client.getPipelineJobs(projectId, Number(pipelineId));
|
||||
return jobs.map((j) => this.mapJob(j, pipelineId));
|
||||
}
|
||||
|
||||
async getJobLog(projectId: string, jobId: string): Promise<string> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/projects/${encodeURIComponent(projectId)}/jobs/${jobId}/trace`,
|
||||
{ headers: { Accept: 'text/plain' } },
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab getJobLog failed: ${resp.status}`);
|
||||
return resp.text();
|
||||
return this.client.getJobLog(projectId, Number(jobId));
|
||||
}
|
||||
|
||||
async retryPipeline(projectId: string, pipelineId: string): Promise<void> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/projects/${encodeURIComponent(projectId)}/pipelines/${pipelineId}/retry`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab retryPipeline failed: ${resp.status}`);
|
||||
await this.client.retryPipeline(projectId, Number(pipelineId));
|
||||
}
|
||||
|
||||
async cancelPipeline(projectId: string, pipelineId: string): Promise<void> {
|
||||
const resp = await this.apiFetch(
|
||||
`/api/v4/projects/${encodeURIComponent(projectId)}/pipelines/${pipelineId}/cancel`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
if (!resp.ok) throw new Error(`GitLab cancelPipeline failed: ${resp.status}`);
|
||||
await this.client.cancelPipeline(projectId, Number(pipelineId));
|
||||
}
|
||||
|
||||
// --- Mappers ---
|
||||
|
||||
private mapProject(p: any): interfaces.data.IProject {
|
||||
private mapProject(p: plugins.gitlabClient.IGitLabProject): interfaces.data.IProject {
|
||||
return {
|
||||
id: String(p.id),
|
||||
name: p.name || '',
|
||||
@@ -211,12 +127,12 @@ export class GitLabProvider extends BaseProvider {
|
||||
webUrl: p.web_url || '',
|
||||
connectionId: this.connectionId,
|
||||
visibility: p.visibility || 'private',
|
||||
topics: p.topics || p.tag_list || [],
|
||||
topics: p.topics || [],
|
||||
lastActivity: p.last_activity_at || '',
|
||||
};
|
||||
}
|
||||
|
||||
private mapGroup(g: any): interfaces.data.IGroup {
|
||||
private mapGroup(g: plugins.gitlabClient.IGitLabGroup): interfaces.data.IGroup {
|
||||
return {
|
||||
id: String(g.id),
|
||||
name: g.name || '',
|
||||
@@ -225,12 +141,12 @@ export class GitLabProvider extends BaseProvider {
|
||||
webUrl: g.web_url || '',
|
||||
connectionId: this.connectionId,
|
||||
visibility: g.visibility || 'private',
|
||||
projectCount: g.projects?.length || 0,
|
||||
projectCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
private mapVariable(
|
||||
v: any,
|
||||
v: plugins.gitlabClient.IGitLabVariable,
|
||||
scope: 'project' | 'group',
|
||||
scopeId: string,
|
||||
): interfaces.data.ISecret {
|
||||
@@ -246,7 +162,7 @@ export class GitLabProvider extends BaseProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private mapPipeline(p: any, projectId: string): interfaces.data.IPipeline {
|
||||
private mapPipeline(p: plugins.gitlabClient.IGitLabPipeline, projectId: string): interfaces.data.IPipeline {
|
||||
return {
|
||||
id: String(p.id),
|
||||
projectId,
|
||||
@@ -262,7 +178,7 @@ export class GitLabProvider extends BaseProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private mapJob(j: any, pipelineId: string): interfaces.data.IPipelineJob {
|
||||
private mapJob(j: plugins.gitlabClient.IGitLabJob, pipelineId: string): interfaces.data.IPipelineJob {
|
||||
return {
|
||||
id: String(j.id),
|
||||
pipelineId: String(pipelineId),
|
||||
|
||||
8
ts_web/00_commitinfo_data.ts
Normal file
8
ts_web/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@serve.zone/gitops',
|
||||
version: '2.0.0',
|
||||
description: 'GitOps management app for Gitea and GitLab - manage secrets, browse projects, view CI pipelines, and stream build logs'
|
||||
}
|
||||
Reference in New Issue
Block a user