refactor: 重构部署功能
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import type { Context } from 'koa';
|
||||
import { Controller, Get } from '../../decorators/route.ts';
|
||||
import { gitea } from '../../libs/gitea.ts';
|
||||
import { log } from '../../libs/logger.ts';
|
||||
import { prisma } from '../../libs/prisma.ts';
|
||||
import { BusinessError } from '../../middlewares/exception.ts';
|
||||
import { getBranchesQuerySchema, getCommitsQuerySchema } from './dto.ts';
|
||||
|
||||
const TAG = 'Git';
|
||||
|
||||
@Controller('/git')
|
||||
export class GitController {
|
||||
@Get('/commits')
|
||||
@@ -30,7 +33,7 @@ export class GitController {
|
||||
|
||||
// Get access token from session
|
||||
const accessToken = ctx.session?.gitea?.access_token;
|
||||
console.log('Access token present:', !!accessToken);
|
||||
log.debug(TAG, 'Access token present: %s', !!accessToken);
|
||||
|
||||
if (!accessToken) {
|
||||
throw new BusinessError(
|
||||
@@ -44,7 +47,7 @@ export class GitController {
|
||||
const commits = await gitea.getCommits(owner, repo, accessToken, branch);
|
||||
return commits;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch commits:', error);
|
||||
log.error(TAG, 'Failed to fetch commits:', error);
|
||||
throw new BusinessError('Failed to fetch commits from Gitea', 1005, 500);
|
||||
}
|
||||
}
|
||||
@@ -80,7 +83,7 @@ export class GitController {
|
||||
const branches = await gitea.getBranches(owner, repo, accessToken);
|
||||
return branches;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch branches:', error);
|
||||
log.error(TAG, 'Failed to fetch branches:', error);
|
||||
throw new BusinessError('Failed to fetch branches from Gitea', 1006, 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export class PipelineController {
|
||||
const templates = await getAvailableTemplates();
|
||||
return templates;
|
||||
} catch (error) {
|
||||
console.error('Failed to get templates:', error);
|
||||
log.error('pipeline', 'Failed to get templates:', error);
|
||||
throw new BusinessError('获取模板失败', 3002, 500);
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ export class PipelineController {
|
||||
log.info('pipeline', 'Created pipeline from template: %s', pipeline.name);
|
||||
return pipeline;
|
||||
} catch (error) {
|
||||
console.error('Failed to create pipeline from template:', error);
|
||||
log.error('pipeline', 'Failed to create pipeline from template:', error);
|
||||
if (error instanceof BusinessError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -68,27 +68,21 @@ export class ProjectController {
|
||||
throw new BusinessError('项目不存在', 1002, 404);
|
||||
}
|
||||
|
||||
// 获取工作目录状态信息
|
||||
// 获取工作目录状态信息(不包含目录大小)
|
||||
let workspaceStatus = null;
|
||||
if (project.projectDir) {
|
||||
try {
|
||||
const status = await GitManager.checkWorkspaceStatus(
|
||||
project.projectDir,
|
||||
);
|
||||
let size = 0;
|
||||
let gitInfo = null;
|
||||
|
||||
if (status.exists && !status.isEmpty) {
|
||||
size = await GitManager.getDirectorySize(project.projectDir);
|
||||
}
|
||||
|
||||
if (status.hasGit) {
|
||||
gitInfo = await GitManager.getGitInfo(project.projectDir);
|
||||
}
|
||||
|
||||
workspaceStatus = {
|
||||
...status,
|
||||
size,
|
||||
gitInfo,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user