49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { RecordModel } from "pocketbase";
|
|
import pbClient from "../pbClient";
|
|
import { managePb404 } from "../../utils/pbTools";
|
|
|
|
export interface PipelineRecordModel extends RecordModel {
|
|
project_id: string;
|
|
user_id: string;
|
|
pipeline_id: number;
|
|
ref: string;
|
|
status: string;
|
|
web_url: string;
|
|
// 2024-03-06 02:53:59.509Z
|
|
created_at: string;
|
|
started_at: string;
|
|
finished_at: string;
|
|
duration: number;
|
|
queued_duration: number;
|
|
}
|
|
|
|
const getOne = (id: string) =>
|
|
managePb404(
|
|
async () => await pbClient.collection("pipeline").getOne(id)
|
|
) as Promise<PipelineRecordModel>;
|
|
|
|
/**
|
|
* 获取项目最新一次构建
|
|
* @param project_id 项目id
|
|
*/
|
|
const getLatestOne = (project_id: string) => {
|
|
return managePb404(
|
|
async () =>
|
|
await pbClient
|
|
.collection("pipeline")
|
|
.getFirstListItem(`project_id="${project_id}"`, {
|
|
sort: "-created_at",
|
|
})
|
|
) as Promise<PipelineRecordModel>;
|
|
};
|
|
|
|
const create = async (data: Partial<PipelineRecordModel>) =>
|
|
await pbClient.collection("pipeline").create<PipelineRecordModel>(data);
|
|
|
|
const pipeline = {
|
|
create,
|
|
getOne,
|
|
getLatestOne,
|
|
};
|
|
export default pipeline;
|