feat(pipelines): add commits query api.
This commit is contained in:
@ -2,6 +2,17 @@ import { ObjectType, Field } from '@nestjs/graphql';
|
||||
import { LogResult, DefaultLogFields } from 'simple-git';
|
||||
import { PipelineTask } from '../../pipeline-tasks/pipeline-task.entity';
|
||||
|
||||
@ObjectType()
|
||||
export class Commit {
|
||||
hash: string;
|
||||
date: Date;
|
||||
message: string;
|
||||
refs: string;
|
||||
body: string;
|
||||
author_name: string;
|
||||
author_email: string;
|
||||
tasks: PipelineTask[];
|
||||
}
|
||||
@ObjectType()
|
||||
export class LogFields {
|
||||
hash: string;
|
||||
|
@ -6,8 +6,7 @@ import { ReposService } from './repos.service';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { ProjectsModule } from '../projects/projects.module';
|
||||
import { BullModule } from '@nestjs/bull';
|
||||
import { LIST_LOGS_TASK, LIST_LOGS_PUB_SUB } from './repos.constants';
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
import { LIST_LOGS_TASK } from './repos.constants';
|
||||
import { ListLogsConsumer } from './list-logs.consumer';
|
||||
|
||||
@Module({
|
||||
|
@ -10,13 +10,23 @@ import { gitP } from 'simple-git';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Project } from '../projects/project.entity';
|
||||
import { ListBranchesArgs } from './dtos/list-branches.args';
|
||||
import { ListLogsArgs } from './dtos/list-logs.args';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Commit } from './dtos/log-list.model';
|
||||
|
||||
const DEFAULT_REMOTE_NAME = 'origin';
|
||||
const INFO_PATH = '@info';
|
||||
@Injectable()
|
||||
export class ReposService {
|
||||
async listCommits(project: Project, branch?: string) {
|
||||
const git = await this.getGit(project, undefined, { fetch: false });
|
||||
const data = await git.log(
|
||||
branch ? ['--branches', `remotes/origin/${branch}`, '--'] : ['--all'],
|
||||
);
|
||||
return data.all.map((it) => ({
|
||||
...it,
|
||||
date: new Date(it.date),
|
||||
}));
|
||||
}
|
||||
constructor(
|
||||
@InjectRepository(Project)
|
||||
private readonly projectRepository: Repository<Project>,
|
||||
@ -31,7 +41,11 @@ export class ReposService {
|
||||
);
|
||||
}
|
||||
|
||||
async getGit(project: Project, workspaceRoot?: string) {
|
||||
async getGit(
|
||||
project: Project,
|
||||
workspaceRoot?: string,
|
||||
{ fetch = true } = {},
|
||||
) {
|
||||
if (!workspaceRoot) {
|
||||
workspaceRoot = this.getWorkspaceRoot(project);
|
||||
}
|
||||
@ -44,7 +58,9 @@ export class ReposService {
|
||||
await git.init();
|
||||
await git.addRemote(DEFAULT_REMOTE_NAME, project.sshUrl);
|
||||
}
|
||||
await git.fetch();
|
||||
if (fetch) {
|
||||
await git.fetch();
|
||||
}
|
||||
return git;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user