修复远程仓库信息获取问题。
This commit is contained in:
@@ -8,18 +8,35 @@ 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 { log } from 'console';
|
||||
|
||||
@Injectable()
|
||||
export class ReposService {
|
||||
constructor(
|
||||
@InjectRepository(Project)
|
||||
private readonly projectRepository: Repository<Project>,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async getGit(project: Project) {
|
||||
const workspacePath = join(__dirname, '../../workspaces', project.name);
|
||||
await access(workspacePath, F_OK).catch(() => mkdir(workspacePath));
|
||||
return gitP(workspacePath);
|
||||
const workspacePath = join(
|
||||
this.configService.get<string>('workspaces.root'),
|
||||
project.name,
|
||||
);
|
||||
const firstInit = await access(workspacePath, F_OK)
|
||||
.then(() => false)
|
||||
.catch(async () => {
|
||||
await mkdir(workspacePath);
|
||||
return true;
|
||||
});
|
||||
const git = gitP(workspacePath);
|
||||
if (firstInit) {
|
||||
await git.init();
|
||||
await git.addRemote('origin', project.sshUrl);
|
||||
// await git.clone(project.sshUrl, workspacePath);
|
||||
}
|
||||
return git;
|
||||
}
|
||||
|
||||
async listLogs(dto: ListLogsArgs) {
|
||||
@@ -27,8 +44,17 @@ export class ReposService {
|
||||
id: dto.projectId,
|
||||
});
|
||||
const git = await this.getGit(project);
|
||||
await git.fetch();
|
||||
return git.log();
|
||||
await git
|
||||
.outputHandler((command, stdout, stderr) => {
|
||||
stdout.pipe(process.stdout);
|
||||
stderr.pipe(process.stderr);
|
||||
})
|
||||
.fetch();
|
||||
// await git.checkoutBranch('master', 'origin/master');
|
||||
return await git.log({
|
||||
'--branches': dto.branch ?? '',
|
||||
'--remotes': 'origin',
|
||||
});
|
||||
}
|
||||
|
||||
async listBranches(dto: ListBranchesArgs) {
|
||||
|
Reference in New Issue
Block a user