Compare commits
No commits in common. "7e17de0f15c0deb70b7b9bf5bcbe2eeb8cc35a44" and "5b5a6576511e509f9c3f6315104d56d108affd38" have entirely different histories.
7e17de0f15
...
5b5a657651
@ -1,11 +1,11 @@
|
|||||||
import { pick } from 'ramda';
|
|
||||||
|
|
||||||
export class ApplicationException extends Error {
|
export class ApplicationException extends Error {
|
||||||
code: number;
|
code: number;
|
||||||
error: Error;
|
error: Error;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
message: string | { error?: Error; message?: string | any; code?: number },
|
message:
|
||||||
|
| string
|
||||||
|
| { error?: Error; message?: string | object; code?: number },
|
||||||
) {
|
) {
|
||||||
if (message instanceof Object) {
|
if (message instanceof Object) {
|
||||||
super();
|
super();
|
||||||
@ -18,8 +18,4 @@ export class ApplicationException extends Error {
|
|||||||
super((message as unknown) as any);
|
super((message as unknown) as any);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
|
||||||
return pick(['code', 'message'], this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -53,22 +53,8 @@ export class BaseDbService<Entity extends AppBaseEntity> extends TypeormHelper {
|
|||||||
async isDuplicateEntityForUpdate<Dto extends Entity>(
|
async isDuplicateEntityForUpdate<Dto extends Entity>(
|
||||||
id: string,
|
id: string,
|
||||||
dto: Partial<Dto>,
|
dto: Partial<Dto>,
|
||||||
extendsFields?: Array<keyof Dto & string>,
|
|
||||||
): Promise<false | never>;
|
|
||||||
async isDuplicateEntityForUpdate<Dto extends Entity>(
|
|
||||||
old: Entity,
|
|
||||||
dto: Partial<Dto>,
|
|
||||||
extendsFields?: Array<keyof Dto & string>,
|
|
||||||
): Promise<false | never>;
|
|
||||||
async isDuplicateEntityForUpdate<Dto extends Entity>(
|
|
||||||
id: string | Entity,
|
|
||||||
dto: Partial<Dto>,
|
|
||||||
extendsFields: Array<keyof Dto & string> = [],
|
extendsFields: Array<keyof Dto & string> = [],
|
||||||
): Promise<false | never> {
|
): Promise<false | never> {
|
||||||
if (typeof id !== 'string') {
|
|
||||||
dto = Object.assign({}, id, dto);
|
|
||||||
id = id.id;
|
|
||||||
}
|
|
||||||
const qb = this.repository.createQueryBuilder('entity');
|
const qb = this.repository.createQueryBuilder('entity');
|
||||||
const compareFields = this.getCompareFields(dto, [
|
const compareFields = this.getCompareFields(dto, [
|
||||||
...this.uniqueFields,
|
...this.uniqueFields,
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { Field, InputType, Int, ObjectType } from '@nestjs/graphql';
|
import { InputType, ObjectType } from '@nestjs/graphql';
|
||||||
import { WorkUnit } from './work-unit.model';
|
import { WorkUnit } from './work-unit.model';
|
||||||
|
|
||||||
@InputType('WorkUnitMetadataInput')
|
@InputType('WorkUnitMetadataInput')
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class WorkUnitMetadata {
|
export class WorkUnitMetadata {
|
||||||
@Field(() => Int)
|
|
||||||
version = 1;
|
version = 1;
|
||||||
units: WorkUnit[];
|
units: WorkUnit[];
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,6 @@ export class PipelineTasksService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
task.logs.push(l);
|
task.logs.push(l);
|
||||||
} else {
|
|
||||||
l.logs += event.message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (terminalTaskStatuses.includes(event.status)) {
|
if (terminalTaskStatuses.includes(event.status)) {
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import { InputType, OmitType } from '@nestjs/graphql';
|
import { InputType } from '@nestjs/graphql';
|
||||||
import { CreatePipelineInput } from './create-pipeline.input';
|
import { CreatePipelineInput } from './create-pipeline.input';
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
export class UpdatePipelineInput extends OmitType(CreatePipelineInput, [
|
export class UpdatePipelineInput extends CreatePipelineInput {
|
||||||
'projectId',
|
|
||||||
]) {
|
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,14 @@ export class PipelinesResolver {
|
|||||||
@Mutation(() => Pipeline)
|
@Mutation(() => Pipeline)
|
||||||
async createPipeline(
|
async createPipeline(
|
||||||
@Args('pipeline', { type: () => CreatePipelineInput })
|
@Args('pipeline', { type: () => CreatePipelineInput })
|
||||||
dto: CreatePipelineInput,
|
dto: UpdatePipelineInput,
|
||||||
) {
|
) {
|
||||||
return await this.service.create(dto);
|
return await this.service.create(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => Pipeline)
|
@Mutation(() => Pipeline)
|
||||||
async updatePipeline(
|
async updatePipeline(
|
||||||
@Args('pipeline', { type: () => UpdatePipelineInput })
|
@Args('Pipeline', { type: () => UpdatePipelineInput })
|
||||||
dto: UpdatePipelineInput,
|
dto: UpdatePipelineInput,
|
||||||
) {
|
) {
|
||||||
const tmp = await this.service.update(dto);
|
const tmp = await this.service.update(dto);
|
||||||
|
@ -14,8 +14,6 @@ import {
|
|||||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
||||||
import { Commit } from '../repos/dtos/log-list.model';
|
import { Commit } from '../repos/dtos/log-list.model';
|
||||||
import { getAppInstanceRouteKey } from '../commons/utils/rabbit-mq';
|
import { getAppInstanceRouteKey } from '../commons/utils/rabbit-mq';
|
||||||
import { ApplicationException } from '../commons/exceptions/application.exception';
|
|
||||||
import { plainToClass } from 'class-transformer';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PipelinesService extends BaseDbService<Pipeline> {
|
export class PipelinesService extends BaseDbService<Pipeline> {
|
||||||
@ -44,8 +42,8 @@ export class PipelinesService extends BaseDbService<Pipeline> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async update(dto: UpdatePipelineInput) {
|
async update(dto: UpdatePipelineInput) {
|
||||||
|
await this.isDuplicateEntityForUpdate(dto.id, dto);
|
||||||
const old = await this.findOne(dto.id);
|
const old = await this.findOne(dto.id);
|
||||||
await this.isDuplicateEntityForUpdate(old, dto);
|
|
||||||
return await this.repository.save(this.repository.merge(old, dto));
|
return await this.repository.save(this.repository.merge(old, dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,17 +60,17 @@ export class PipelinesService extends BaseDbService<Pipeline> {
|
|||||||
}
|
}
|
||||||
async listCommits(pipeline: Pipeline) {
|
async listCommits(pipeline: Pipeline) {
|
||||||
return await this.amqpConnection
|
return await this.amqpConnection
|
||||||
.request<[Error, Commit[]]>({
|
.request<Commit[]>({
|
||||||
exchange: EXCHANGE_REPO,
|
exchange: EXCHANGE_REPO,
|
||||||
routingKey: ROUTE_LIST_COMMITS,
|
routingKey: ROUTE_LIST_COMMITS,
|
||||||
payload: pipeline,
|
payload: pipeline,
|
||||||
timeout: 30_000,
|
timeout: 10_000,
|
||||||
})
|
})
|
||||||
.then(([error, list]) => {
|
.then((list) =>
|
||||||
if (error) {
|
list.map((item) => {
|
||||||
throw new ApplicationException(error);
|
item.date = new Date(item.date);
|
||||||
}
|
return item;
|
||||||
return plainToClass(Commit, list);
|
}),
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import { ObjectType, Field } from '@nestjs/graphql';
|
import { ObjectType, Field } from '@nestjs/graphql';
|
||||||
import { Type } from 'class-transformer';
|
|
||||||
import { LogResult, DefaultLogFields } from 'simple-git';
|
import { LogResult, DefaultLogFields } from 'simple-git';
|
||||||
import { PipelineTask } from '../../pipeline-tasks/pipeline-task.entity';
|
import { PipelineTask } from '../../pipeline-tasks/pipeline-task.entity';
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class Commit {
|
export class Commit {
|
||||||
hash: string;
|
hash: string;
|
||||||
@Type(() => Date)
|
|
||||||
date: Date;
|
date: Date;
|
||||||
message: string;
|
message: string;
|
||||||
refs: string;
|
refs: string;
|
||||||
|
@ -26,7 +26,6 @@ import {
|
|||||||
getInstanceName,
|
getInstanceName,
|
||||||
getSelfInstanceRouteKey,
|
getSelfInstanceRouteKey,
|
||||||
} from '../commons/utils/rabbit-mq';
|
} from '../commons/utils/rabbit-mq';
|
||||||
import { ApplicationException } from '../commons/exceptions/application.exception';
|
|
||||||
|
|
||||||
const DEFAULT_REMOTE_NAME = 'origin';
|
const DEFAULT_REMOTE_NAME = 'origin';
|
||||||
const INFO_PATH = '@info';
|
const INFO_PATH = '@info';
|
||||||
@ -130,7 +129,7 @@ export class ReposService {
|
|||||||
autoDelete: true,
|
autoDelete: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
async listCommits(pipeline: Pipeline): Promise<[Error, Commit[]?]> {
|
async listCommits(pipeline: Pipeline): Promise<Commit[] | Nack> {
|
||||||
const git = await this.getGit(pipeline.project, undefined, {
|
const git = await this.getGit(pipeline.project, undefined, {
|
||||||
fetch: false,
|
fetch: false,
|
||||||
});
|
});
|
||||||
@ -141,23 +140,20 @@ export class ReposService {
|
|||||||
`remotes/origin/${pipeline.branch}`,
|
`remotes/origin/${pipeline.branch}`,
|
||||||
'--',
|
'--',
|
||||||
]);
|
]);
|
||||||
return [
|
return data.all.map(
|
||||||
null,
|
|
||||||
data.all.map(
|
|
||||||
(it) =>
|
(it) =>
|
||||||
({
|
({
|
||||||
...it,
|
...it,
|
||||||
date: new Date(it.date),
|
date: new Date(it.date),
|
||||||
} as Commit),
|
} as Commit),
|
||||||
),
|
);
|
||||||
];
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
{ error, pipeline },
|
{ error, pipeline },
|
||||||
'[listCommits] %s',
|
'[listCommits] %s',
|
||||||
error?.message,
|
error?.message,
|
||||||
);
|
);
|
||||||
return [new ApplicationException(error)];
|
return new Nack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user