Skip to content

Commit

Permalink
refactor(config-ui): unified API type definitions and exports (#6215)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsweet authored Oct 12, 2023
1 parent 080e976 commit 6526762
Show file tree
Hide file tree
Showing 64 changed files with 484 additions and 555 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
*/

import { request } from '@/utils';

import * as T from './types';

export const getApiKeys = (params?: Pagination): Promise<{ count: number; apikeys: T.Key[] }> =>
export const list = (data?: Pagination): Promise<{ count: number; apikeys: T.Key[] }> =>
request('/api-keys', {
data: params,
data,
});

export const createApiKey = (data: Pick<T.Key, 'name' | 'expiredAt' | 'allowedPath'>): Promise<T.Key> =>
export const create = (data: Pick<T.Key, 'name' | 'expiredAt' | 'allowedPath'>): Promise<T.Key> =>
request('/api-keys', {
method: 'POST',
data: {
Expand All @@ -34,7 +33,9 @@ export const createApiKey = (data: Pick<T.Key, 'name' | 'expiredAt' | 'allowedPa
},
});

export const deleteApiKey = (id: string): Promise<void> =>
export const remove = (id: string): Promise<void> =>
request(`/api-keys/${id}`, {
method: 'DELETE',
});

export const renew = (id: ID) => request(`/api-keys/${id}`, { method: 'put' });
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*
*/

import { request } from '@/utils';

export const migrate = () => request('/proceed-db-migration');
export type Key = {
name: string;
expiredAt?: string;
allowedPath: string;
creator: string;
};
40 changes: 40 additions & 0 deletions config-ui/src/api/blueprint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { request } from '@/utils';

import * as T from './types';

export const list = (data: Pagination & { type: string }): Promise<{ count: number; blueprints: T.Blueprint[] }> =>
request('/blueprints', { data });

export const get = (id: ID): Promise<T.Blueprint> => request(`/blueprints/${id}`);

export const create = (data: any) =>
request('/blueprints', {
method: 'post',
data,
});

export const remove = (id: ID) => request(`/blueprints/${id}`, { method: 'delete' });

export const update = (id: ID, data: T.Blueprint) => request(`/blueprints/${id}`, { method: 'patch', data });

export const pipelines = (id: ID) => request(`/blueprints/${id}/pipelines`);

export const trigger = (id: ID, data: T.TriggerQuery) => request(`/blueprints/${id}/trigger`, { method: 'post', data });
47 changes: 47 additions & 0 deletions config-ui/src/api/blueprint/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

export enum ModeEnum {
advanced = 'ADVANCED',
normal = 'NORMAL',
}

export type Blueprint = {
projectName: string;
id: ID;
enable: boolean;
name: string;
mode: ModeEnum;
isManual: boolean;
cronConfig: string;
skipOnFail: boolean;
plan: any;
timeAfter: null | string;
connections: Array<{
pluginName: string;
connectionId: ID;
scopes?: Array<{
scopeId: string;
}>;
}>;
};

export type TriggerQuery = {
skipCollectors: boolean;
fullSync: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,29 @@

import { request } from '@/utils';

export const testConnection = (plugin: string, payload: any) =>
request(`/plugins/${plugin}/test`, { method: 'post', data: payload });
import * as T from './types';

export const createConnection = (plugin: string, payload: any) =>
export const list = (plugin: string): Promise<T.Connection[]> => request(`/plugins/${plugin}/connections`);

export const get = (plugin: string, connectionId: ID): Promise<T.Connection> =>
request(`/plugins/${plugin}/connections/${connectionId}`);

export const create = (plugin: string, payload: T.ConnectionForm): Promise<T.Connection> =>
request(`/plugins/${plugin}/connections`, { method: 'post', data: payload });

export const getConnection = (plugin: string, id: ID) => request(`/plugins/${plugin}/connections/${id}`);
export const remove = (plugin: string, id: ID): Promise<T.Connection> =>
request(`/plugins/${plugin}/connections/${id}`, { method: 'delete' });

export const updateConnection = (plugin: string, id: ID, payload: any) =>
export const update = (plugin: string, id: ID, payload: T.ConnectionForm): Promise<T.Connection> =>
request(`/plugins/${plugin}/connections/${id}`, {
method: 'patch',
data: payload,
});

export const test = (
plugin: string,
payload: Pick<
T.ConnectionForm,
'endpoint' | 'authMethod' | 'username' | 'password' | 'token' | 'appId' | 'secretKey' | 'proxy'
>,
): Promise<T.ConnectionTest> => request(`/plugins/${plugin}/test`, { method: 'post', data: payload });
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,41 @@
*
*/

import { request } from '@/utils';

type GetConnectionRes = {
export type Connection = {
id: ID;
name: string;
endpoint: string;
proxy: string;
authMethod?: string;
token?: string;
username?: string;
password?: string;
authMethod?: string;
proxy: string;
apiKey?: string;
};

export const getConnection = (plugin: string): Promise<GetConnectionRes[]> => request(`/plugins/${plugin}/connections`);

type TestConnectionPayload = {
endpoint: string;
proxy: string;
token?: string;
export type ConnectionForm = {
name: string;
endpoint?: string;
authMethod?: string;
username?: string;
password?: string;
authMethod?: string;
token?: string;
appId?: string;
secretKey?: string;
enableGraphql?: boolean;
proxy: string;
rateLimitPerHour?: number;
};

export const testConnection = (plugin: string, data: TestConnectionPayload) =>
request(`/plugins/${plugin}/test`, {
method: 'post',
data,
});
export type ConnectionTest = {
message: string;
success: boolean;
login?: string;
installations?: Array<{
id: number;
account: {
login: string;
};
}>;
warning?: string;
};
53 changes: 53 additions & 0 deletions config-ui/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { request } from '@/utils';

import * as apiKey from './api-key';
import * as blueprint from './blueprint';
import * as connection from './connection';
import * as pipeline from './pipeline';
import plugin from './plugin';
import * as project from './project';
import * as scope from './scope';
import * as scopeConfig from './scope-config';
import * as task from './task';

const migrate = () => request('/proceed-db-migration');
const ping = () => request('/ping');
const version = (signal?: AbortSignal): Promise<{ version: string }> => request('/version', { signal });
const userInfo = (signal?: AbortSignal): Promise<{ user: string; email: string; logoutURI: string }> =>
request('/userinfo', { signal });

export const API = {
apiKey,
blueprint,
connection,
pipeline,
plugin,
project,
scopeConfig,
scope,
task,
migrate,
ping,
version,
userInfo,
};

export default API;
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,20 @@ import { request } from '@/utils';

import * as T from './types';

export const getPipelines = (): Promise<{ count: number; pipelines: T.Pipeline[] }> => request('/pipelines');
export const list = (): Promise<{ count: number; pipelines: T.Pipeline[] }> => request('/pipelines');

export const getPipeline = (id: ID) => request(`/pipelines/${id}`);
export const get = (id: ID) => request(`/pipelines/${id}`);

export const deletePipeline = (id: ID) =>
export const remove = (id: ID) =>
request(`/pipelines/${id}`, {
method: 'delete',
});

export const rerunPipeline = (id: ID) =>
export const rerun = (id: ID) =>
request(`/pipelines/${id}/rerun`, {
method: 'post',
});

export const getPipelineLog = (id: ID) => request(`/pipelines/${id}/logging.tar.gz`);
export const log = (id: ID) => request(`/pipelines/${id}/logging.tar.gz`);

export const getPipelineTasks = (id: ID) => request(`/pipelines/${id}/tasks`);

export const taskRerun = (id: ID) =>
request(`/tasks/${id}/rerun`, {
method: 'post',
});
export const tasks = (id: ID) => request(`/pipelines/${id}/tasks`);
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@
*
*/

import { request } from '@/utils';
export enum PipelineStatus {
CREATED = 'TASK_CREATED',
PENDING = 'TASK_PENDING',
ACTIVE = 'TASK_ACTIVE',
RUNNING = 'TASK_RUNNING',
RERUN = 'TASK_RERUN',
COMPLETED = 'TASK_COMPLETED',
PARTIAL = 'TASK_PARTIAL',
FAILED = 'TASK_FAILED',
CANCELLED = 'TASK_CANCELLED',
}

import { BlueprintType } from '../types';

type ResponseType = {
blueprints: Array<BlueprintType>;
count: number;
export type Pipeline = {
id: ID;
status: PipelineStatus;
beganAt: string | null;
finishedAt: string | null;
stage: number;
finishedTasks: number;
totalTasks: number;
message: string;
};

export const getBlueprints = (params: Pagination & { type: string }): Promise<ResponseType> =>
request('/blueprints', { data: params });

export const createBlueprint = (payload: any) =>
request('/blueprints', {
method: 'post',
data: payload,
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
*
*/

import { request } from '@/utils';
import * as jira from './jira';
import * as tapd from './tapd';
import * as webhook from './webhook';

export const testConnection = (payload: any) => request('/plugins/github/test', { method: 'post', data: payload });
export const plugin = {
jira,
tapd,
webhook,
};

export default plugin;
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ export type GetBoardsParams = {
maxResults: number;
};

export const getBoards = (prefix: string, params: GetBoardsParams) =>
export const boards = (prefix: string, params: GetBoardsParams) =>
request(`${prefix}/agile/1.0/board`, { data: params });

export const getIssueType = (prefix: string) => request(`${prefix}/api/2/issuetype`);
export const issueType = (prefix: string) => request(`${prefix}/api/2/issuetype`);

export const getField = (prefix: string) => request(`${prefix}/api/2/field`);
export const field = (prefix: string) => request(`${prefix}/api/2/field`);

export const getApplicationTypes = (connectionId: ID, query: { key: string }) =>
export const applicationTypes = (connectionId: ID, query: { key: string }) =>
request(`/plugins/jira/connections/${connectionId}/application-types`, {
data: query,
});

export const getDevPanelCommits = (connectionId: ID, query: { key: string; applicationType: string }) =>
export const devPanelCommits = (connectionId: ID, query: { key: string; applicationType: string }) =>
request(`/plugins/jira/connections/${connectionId}/dev-panel-commits`, { data: query });

export const generateRegex = (pattern: string) =>
Expand Down
Loading

0 comments on commit 6526762

Please sign in to comment.