Compare commits
1 Commits
feat-repo+
...
1d8b99fe8e
Author | SHA1 | Date | |
---|---|---|---|
1d8b99fe8e |
@ -1,6 +1,7 @@
|
|||||||
env: dev
|
env: dev
|
||||||
http:
|
http:
|
||||||
port: 7122
|
port: 7122
|
||||||
|
|
||||||
db:
|
db:
|
||||||
postgres:
|
postgres:
|
||||||
host: 192.168.31.194
|
host: 192.168.31.194
|
||||||
@ -8,9 +9,5 @@ db:
|
|||||||
database: fennec
|
database: fennec
|
||||||
username: fennec
|
username: fennec
|
||||||
password:
|
password:
|
||||||
redis:
|
|
||||||
mq:
|
|
||||||
host: localhost
|
|
||||||
port: 6379
|
|
||||||
workspaces:
|
workspaces:
|
||||||
root: '/Users/ivanli/Projects/fennec/workspaces'
|
root: '/Users/ivanli/Projects/fennec/workspaces'
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -9087,14 +9087,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mkdirp": {
|
|
||||||
"version": "0.5.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
|
||||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
|
||||||
"requires": {
|
|
||||||
"minimist": "^1.2.5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.29.1",
|
"version": "2.29.1",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
|
||||||
@ -9126,6 +9118,16 @@
|
|||||||
"on-finished": "^2.3.0",
|
"on-finished": "^2.3.0",
|
||||||
"type-is": "^1.6.4",
|
"type-is": "^1.6.4",
|
||||||
"xtend": "^4.0.0"
|
"xtend": "^4.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"mkdirp": {
|
||||||
|
"version": "0.5.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||||
|
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||||
|
"requires": {
|
||||||
|
"minimist": "^1.2.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"multimatch": {
|
"multimatch": {
|
||||||
@ -9489,6 +9491,14 @@
|
|||||||
"minipass": "^2.9.0"
|
"minipass": "^2.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"mkdirp": {
|
||||||
|
"version": "0.5.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||||
|
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||||
|
"requires": {
|
||||||
|
"minimist": "^1.2.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"rimraf": {
|
"rimraf": {
|
||||||
"version": "2.7.1",
|
"version": "2.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
|
||||||
|
@ -8,7 +8,6 @@ import { AppService } from './app.service';
|
|||||||
import { ProjectsModule } from './projects/projects.module';
|
import { ProjectsModule } from './projects/projects.module';
|
||||||
import { ReposModule } from './repos/repos.module';
|
import { ReposModule } from './repos/repos.module';
|
||||||
import configuration from './commons/config/configuration';
|
import configuration from './commons/config/configuration';
|
||||||
import { BullModule } from '@nestjs/bull';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -38,16 +37,6 @@ import { BullModule } from '@nestjs/bull';
|
|||||||
}),
|
}),
|
||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
}),
|
}),
|
||||||
BullModule.forRootAsync({
|
|
||||||
imports: [ConfigModule],
|
|
||||||
useFactory: async (configService: ConfigService) => ({
|
|
||||||
redis: {
|
|
||||||
host: configService.get<string>('redis.mq.host', 'localhost'),
|
|
||||||
port: configService.get<number>('redis.mq.port', 6379),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
inject: [ConfigService],
|
|
||||||
}),
|
|
||||||
ProjectsModule,
|
ProjectsModule,
|
||||||
ReposModule,
|
ReposModule,
|
||||||
],
|
],
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export const WORKSPACE_ACTION = 'workspace-action';
|
|
@ -4,17 +4,9 @@ import { Project } from '../projects/project.entity';
|
|||||||
import { ReposResolver } from './repos.resolver';
|
import { ReposResolver } from './repos.resolver';
|
||||||
import { ReposService } from './repos.service';
|
import { ReposService } from './repos.service';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { BullModule } from '@nestjs/bull';
|
|
||||||
import { WORKSPACE_ACTION } from './repos.constants';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [TypeOrmModule.forFeature([Project]), ConfigModule],
|
||||||
TypeOrmModule.forFeature([Project]),
|
|
||||||
ConfigModule,
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: WORKSPACE_ACTION,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
providers: [ReposResolver, ReposService],
|
providers: [ReposResolver, ReposService],
|
||||||
})
|
})
|
||||||
export class ReposModule {}
|
export class ReposModule {}
|
||||||
|
@ -75,7 +75,7 @@ describe('ReposService', () => {
|
|||||||
it('should be checkout', async () => {
|
it('should be checkout', async () => {
|
||||||
await service.checkoutBranch(getTest1Project(), 'master');
|
await service.checkoutBranch(getTest1Project(), 'master');
|
||||||
const filePath = join(
|
const filePath = join(
|
||||||
service.getWorkspaceRoot(getTest1Project()),
|
service.getWorkspaceRoot(getTest1Project(), 'master'),
|
||||||
'README.md',
|
'README.md',
|
||||||
);
|
);
|
||||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||||
@ -86,7 +86,7 @@ describe('ReposService', () => {
|
|||||||
await service.checkoutBranch(getTest1Project(), 'branch-a');
|
await service.checkoutBranch(getTest1Project(), 'branch-a');
|
||||||
await service.checkoutBranch(getTest1Project(), 'branch-b');
|
await service.checkoutBranch(getTest1Project(), 'branch-b');
|
||||||
const filePath = join(
|
const filePath = join(
|
||||||
service.getWorkspaceRoot(getTest1Project()),
|
service.getWorkspaceRoot(getTest1Project(), 'branch-b'),
|
||||||
'branch-b.md',
|
'branch-b.md',
|
||||||
);
|
);
|
||||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||||
@ -100,7 +100,7 @@ describe('ReposService', () => {
|
|||||||
it('checkout the specified version', async () => {
|
it('checkout the specified version', async () => {
|
||||||
await service.checkoutBranch(getTest1Project(), 'master');
|
await service.checkoutBranch(getTest1Project(), 'master');
|
||||||
const filePath = join(
|
const filePath = join(
|
||||||
service.getWorkspaceRoot(getTest1Project()),
|
service.getWorkspaceRoot(getTest1Project(), 'master'),
|
||||||
'README.md',
|
'README.md',
|
||||||
);
|
);
|
||||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||||
@ -112,7 +112,7 @@ describe('ReposService', () => {
|
|||||||
it('should be checkout', async () => {
|
it('should be checkout', async () => {
|
||||||
await service.checkoutCommit(getTest1Project(), '498c782685');
|
await service.checkoutCommit(getTest1Project(), '498c782685');
|
||||||
const filePath = join(
|
const filePath = join(
|
||||||
service.getWorkspaceRoot(getTest1Project()),
|
service.getWorkspaceRoot(getTest1Project(), '498c782685'),
|
||||||
'README.md',
|
'README.md',
|
||||||
);
|
);
|
||||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||||
@ -121,7 +121,7 @@ describe('ReposService', () => {
|
|||||||
it('should be checkout right commit', async () => {
|
it('should be checkout right commit', async () => {
|
||||||
await service.checkoutCommit(getTest1Project(), '7f7123fe5b');
|
await service.checkoutCommit(getTest1Project(), '7f7123fe5b');
|
||||||
const filePath = join(
|
const filePath = join(
|
||||||
service.getWorkspaceRoot(getTest1Project()),
|
service.getWorkspaceRoot(getTest1Project(), '7f7123fe5b'),
|
||||||
'README.md',
|
'README.md',
|
||||||
);
|
);
|
||||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||||
|
@ -19,10 +19,11 @@ export class ReposService {
|
|||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
getWorkspaceRoot(project: Project): string {
|
getWorkspaceRoot(project: Project, subDir = ''): string {
|
||||||
return join(
|
return join(
|
||||||
this.configService.get<string>('workspaces.root'),
|
this.configService.get<string>('workspaces.root'),
|
||||||
project.name,
|
project.name,
|
||||||
|
encodeURIComponent(subDir),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,14 +31,14 @@ export class ReposService {
|
|||||||
// TODO: 获取锁,失败抛错。
|
// TODO: 获取锁,失败抛错。
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGit(project: Project) {
|
async getGit(project: Project, subDir?: string) {
|
||||||
const workspaceRoot = this.getWorkspaceRoot(project);
|
const workspaceRoot = this.getWorkspaceRoot(project, subDir);
|
||||||
await this.lockWorkspace(workspaceRoot);
|
await this.lockWorkspace(workspaceRoot);
|
||||||
|
|
||||||
const firstInit = await access(workspaceRoot, F_OK)
|
const firstInit = await access(workspaceRoot, F_OK)
|
||||||
.then(() => false)
|
.then(() => false)
|
||||||
.catch(async () => {
|
.catch(async () => {
|
||||||
await mkdir(workspaceRoot);
|
await mkdir(workspaceRoot, { recursive: true });
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
const git = gitP(workspaceRoot);
|
const git = gitP(workspaceRoot);
|
||||||
@ -69,7 +70,7 @@ export class ReposService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkoutBranch(project: Project, branch: string) {
|
async checkoutBranch(project: Project, branch: string) {
|
||||||
const git = await this.getGit(project);
|
const git = await this.getGit(project, branch);
|
||||||
try {
|
try {
|
||||||
await git.fetch(DEFAULT_REMOTE_NAME, branch);
|
await git.fetch(DEFAULT_REMOTE_NAME, branch);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -87,7 +88,7 @@ export class ReposService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkoutCommit(project: Project, commitNumber: string) {
|
async checkoutCommit(project: Project, commitNumber: string) {
|
||||||
const git = await this.getGit(project);
|
const git = await this.getGit(project, commitNumber);
|
||||||
try {
|
try {
|
||||||
await git.fetch(DEFAULT_REMOTE_NAME);
|
await git.fetch(DEFAULT_REMOTE_NAME);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import { Process, Processor } from '@nestjs/bull';
|
|
||||||
import { WORKSPACE_ACTION } from './repos.constants';
|
|
||||||
|
|
||||||
@Processor(WORKSPACE_ACTION)
|
|
||||||
export class WorkspaceActionConsumer {
|
|
||||||
@Process()
|
|
||||||
async dispatch() {}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
import { WorkspaceActions } from './workspace-actions.enum';
|
|
||||||
|
|
||||||
export class WorkspaceAction {
|
|
||||||
action: WorkspaceActions;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
export enum WorkspaceActions {
|
|
||||||
checkoutBranch = 'checkoutBranch',
|
|
||||||
checkoutCommit = 'checkoutCommit',
|
|
||||||
listLogs = 'listLogs',
|
|
||||||
listBranches = 'listBranches',
|
|
||||||
}
|
|
Reference in New Issue
Block a user