feat(repos): 添加提交日志查询和分支查询
This commit is contained in:
41
src/repos/repos.service.ts
Normal file
41
src/repos/repos.service.ts
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user