feat_the_progress_of_tasks #5

Merged
Ivan merged 20 commits from feat_the_progress_of_tasks into master 2021-06-27 19:57:14 +08:00
3 changed files with 22 additions and 12 deletions
Showing only changes of commit 7e17de0f15 - Show all commits

View File

@ -1,11 +1,11 @@
import { pick } from 'ramda';
export class ApplicationException extends Error {
code: number;
error: Error;
constructor(
message:
| string
| { error?: Error; message?: string | object; code?: number },
message: string | { error?: Error; message?: string | any; code?: number },
) {
if (message instanceof Object) {
super();
@ -18,4 +18,8 @@ export class ApplicationException extends Error {
super((message as unknown) as any);
}
}
toJSON() {
return pick(['code', 'message'], this);
}
}

View File

@ -1,10 +1,12 @@
import { ObjectType, Field } from '@nestjs/graphql';
import { Type } from 'class-transformer';
import { LogResult, DefaultLogFields } from 'simple-git';
import { PipelineTask } from '../../pipeline-tasks/pipeline-task.entity';
@ObjectType()
export class Commit {
hash: string;
@Type(() => Date)
date: Date;
message: string;
refs: string;

View File

@ -26,6 +26,7 @@ import {
getInstanceName,
getSelfInstanceRouteKey,
} from '../commons/utils/rabbit-mq';
import { ApplicationException } from '../commons/exceptions/application.exception';
const DEFAULT_REMOTE_NAME = 'origin';
const INFO_PATH = '@info';
@ -129,7 +130,7 @@ export class ReposService {
autoDelete: true,
},
})
async listCommits(pipeline: Pipeline): Promise<Commit[] | Nack> {
async listCommits(pipeline: Pipeline): Promise<[Error, Commit[]?]> {
const git = await this.getGit(pipeline.project, undefined, {
fetch: false,
});
@ -140,20 +141,23 @@ export class ReposService {
`remotes/origin/${pipeline.branch}`,
'--',
]);
return data.all.map(
(it) =>
({
...it,
date: new Date(it.date),
} as Commit),
);
return [
null,
data.all.map(
(it) =>
({
...it,
date: new Date(it.date),
} as Commit),
),
];
} catch (error) {
this.logger.error(
{ error, pipeline },
'[listCommits] %s',
error?.message,
);
return new Nack();
return [new ApplicationException(error)];
}
}