feat(repos): 新增 检出指定 commit 功能。
This commit is contained in:
@@ -3,26 +3,30 @@ import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Project } from '../projects/project.entity';
|
||||
import { ReposService } from './repos.service';
|
||||
import { ConfigService, ConfigModule } from '@nestjs/config';
|
||||
import { rm } from 'fs/promises';
|
||||
import { readFile, rm } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import configuration from '../commons/config/configuration';
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
|
||||
const getTest1Project = () =>
|
||||
({
|
||||
id: '1',
|
||||
sshUrl: 'ssh://gitea@git.ivanli.cc:7018/Fennec/test-1.git',
|
||||
name: 'test-1',
|
||||
} as Project);
|
||||
|
||||
describe('ReposService', () => {
|
||||
let service: ReposService;
|
||||
const repositoryMockFactory = jest.fn(() => ({
|
||||
findOneOrFail: jest.fn(
|
||||
(entity): Project => ({
|
||||
id: '1',
|
||||
// sshUrl: 'ssh://gitea@git.ivanli.cc:7018/ivan/test1.git',
|
||||
sshUrl: 'ssh://gitea@git.ivanli.cc:7018/Fennec/fennec-fe.git',
|
||||
name: 'test1',
|
||||
...getTest1Project(),
|
||||
...entity,
|
||||
}),
|
||||
),
|
||||
}));
|
||||
let workspacesRoot: string;
|
||||
afterEach(async () => {
|
||||
await rm(join(workspacesRoot, 'test1'), {
|
||||
await rm(service.getWorkspaceRoot(getTest1Project()), {
|
||||
recursive: true,
|
||||
}).catch(() => undefined);
|
||||
});
|
||||
@@ -43,17 +47,20 @@ describe('ReposService', () => {
|
||||
}).compile();
|
||||
|
||||
service = module.get<ReposService>(ReposService);
|
||||
const configServer = module.get<ConfigService>(ConfigService);
|
||||
workspacesRoot = configServer.get<string>('workspaces.root');
|
||||
|
||||
await rm(join(workspacesRoot, 'test1'), {
|
||||
await rm(service.getWorkspaceRoot(getTest1Project()), {
|
||||
recursive: true,
|
||||
}).catch(() => undefined);
|
||||
}).catch((err) => {
|
||||
console.log('!!!!', err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
it('getWorkspaceRoot', () => {
|
||||
expect(service.getWorkspaceRoot(getTest1Project())).toBeDefined();
|
||||
});
|
||||
describe('listLogs', () => {
|
||||
it('should be return logs', async () => {
|
||||
const result = await service.listLogs({ projectId: '1' });
|
||||
@@ -66,4 +73,61 @@ describe('ReposService', () => {
|
||||
expect(result).toBeDefined();
|
||||
}, 10_000);
|
||||
});
|
||||
describe('checkoutBranch', () => {
|
||||
it('should be checkout', async () => {
|
||||
await service.checkoutBranch(getTest1Project(), 'master');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project()),
|
||||
'README.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit 1/gi);
|
||||
}, 30_000);
|
||||
it('multiplexing workspace', async () => {
|
||||
await service.checkoutBranch(getTest1Project(), 'master');
|
||||
await service.checkoutBranch(getTest1Project(), 'branch-a');
|
||||
await service.checkoutBranch(getTest1Project(), 'branch-b');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project()),
|
||||
'branch-b.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit branch b/gi);
|
||||
}, 30_000);
|
||||
it('nonexistent branch', async () => {
|
||||
return expect(
|
||||
service.checkoutBranch(getTest1Project(), 'nonexistent'),
|
||||
).rejects.toBeInstanceOf(NotFoundException);
|
||||
}, 30_000);
|
||||
it('checkout the specified version', async () => {
|
||||
await service.checkoutBranch(getTest1Project(), 'master');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project()),
|
||||
'README.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit 1/gi);
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
describe('checkoutCommit', () => {
|
||||
it('should be checkout', async () => {
|
||||
await service.checkoutCommit(getTest1Project(), '498c782685');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project()),
|
||||
'README.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit 1/gi);
|
||||
});
|
||||
it('should be checkout right commit', async () => {
|
||||
await service.checkoutCommit(getTest1Project(), '7f7123fe5b');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project()),
|
||||
'README.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/(?!Commit 1)/gi);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user