修复远程仓库信息获取问题。

This commit is contained in:
Ivan Li
2021-02-23 20:19:39 +08:00
parent dfaee1fb56
commit ab6c56e55a
9 changed files with 62 additions and 17 deletions

View File

@@ -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) {