feat(repos): 添加提交日志查询和分支查询

This commit is contained in:
Ivan Li
2021-02-19 13:11:03 +08:00
parent c2c5340278
commit dfaee1fb56
20 changed files with 279 additions and 5 deletions

View File

@@ -0,0 +1,41 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { F_OK } from 'constants';
import { access, mkdir } from 'fs/promises';
import { join } from 'path';
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';
@Injectable()
export class ReposService {
constructor(
@InjectRepository(Project)
private readonly projectRepository: Repository<Project>,
) {}
async getGit(project: Project) {
const workspacePath = join(__dirname, '../../workspaces', project.name);
await access(workspacePath, F_OK).catch(() => mkdir(workspacePath));
return gitP(workspacePath);
}
async listLogs(dto: ListLogsArgs) {
const project = await this.projectRepository.findOneOrFail({
id: dto.projectId,
});
const git = await this.getGit(project);
await git.fetch();
return git.log();
}
async listBranches(dto: ListBranchesArgs) {
const project = await this.projectRepository.findOneOrFail({
id: dto.projectId,
});
const git = await this.getGit(project);
return git.branch();
}
}