mirror of
https://github.com/jeffusion/gitea-ai-assistant.git
synced 2026-03-27 10:05:50 +00:00
fix(logs): gate repository list debug logs behind REPO_LIST_DEBUG_LOGS env flag
- Add REPO_LIST_DEBUG_LOGS environment variable to control debug output - Gate debug logs in admin controller and gitea service - Keep error/warn logs always enabled for production visibility Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
This commit is contained in:
@@ -9,6 +9,7 @@ import { logger } from '../utils/logger';
|
|||||||
|
|
||||||
const publicRoutes = new Hono();
|
const publicRoutes = new Hono();
|
||||||
const protectedRoutes = new Hono();
|
const protectedRoutes = new Hono();
|
||||||
|
const isRepoListDebugEnabled = process.env.REPO_LIST_DEBUG_LOGS === 'true';
|
||||||
|
|
||||||
// --- Public Routes ---
|
// --- Public Routes ---
|
||||||
|
|
||||||
@@ -47,9 +48,12 @@ protectedRoutes.get('/repositories', async (c) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (isRepoListDebugEnabled) {
|
||||||
logger.debug('开始获取仓库列表', requestContext);
|
logger.debug('开始获取仓库列表', requestContext);
|
||||||
|
}
|
||||||
|
|
||||||
const { repos, totalCount } = await giteaService.listAllRepositories(page, limit, query);
|
const { repos, totalCount } = await giteaService.listAllRepositories(page, limit, query);
|
||||||
|
if (isRepoListDebugEnabled) {
|
||||||
logger.debug('仓库搜索接口返回成功', {
|
logger.debug('仓库搜索接口返回成功', {
|
||||||
...requestContext,
|
...requestContext,
|
||||||
reposCount: repos.length,
|
reposCount: repos.length,
|
||||||
@@ -58,16 +62,19 @@ protectedRoutes.get('/repositories', async (c) => {
|
|||||||
.slice(0, 3)
|
.slice(0, 3)
|
||||||
.map((repo) => (typeof repo.full_name === 'string' ? repo.full_name : null)),
|
.map((repo) => (typeof repo.full_name === 'string' ? repo.full_name : null)),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const webhookUrl = c.req.url.replace(/\/admin\/api\/repositories.*$/, '/webhook/gitea');
|
const webhookUrl = c.req.url.replace(/\/admin\/api\/repositories.*$/, '/webhook/gitea');
|
||||||
const fullNames = repos
|
const fullNames = repos
|
||||||
.map((repo) => (typeof repo.full_name === 'string' ? repo.full_name : null))
|
.map((repo) => (typeof repo.full_name === 'string' ? repo.full_name : null))
|
||||||
.filter((name): name is string => name !== null);
|
.filter((name): name is string => name !== null);
|
||||||
|
if (isRepoListDebugEnabled) {
|
||||||
logger.debug('准备批量读取项目级提示词', {
|
logger.debug('准备批量读取项目级提示词', {
|
||||||
...requestContext,
|
...requestContext,
|
||||||
fullNamesCount: fullNames.length,
|
fullNamesCount: fullNames.length,
|
||||||
fullNamesSample: fullNames.slice(0, 5),
|
fullNamesSample: fullNames.slice(0, 5),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let promptMap: Record<string, string>;
|
let promptMap: Record<string, string>;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import config from '../config';
|
|||||||
import { toErrorLogMeta } from '../utils/error-log';
|
import { toErrorLogMeta } from '../utils/error-log';
|
||||||
import { logger } from '../utils/logger';
|
import { logger } from '../utils/logger';
|
||||||
|
|
||||||
|
const isRepoListDebugEnabled = process.env.REPO_LIST_DEBUG_LOGS === 'true';
|
||||||
|
|
||||||
export interface LineComment {
|
export interface LineComment {
|
||||||
path: string;
|
path: string;
|
||||||
line: number;
|
line: number;
|
||||||
@@ -424,7 +426,10 @@ export const giteaService: GiteaService = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (isRepoListDebugEnabled) {
|
||||||
logger.debug('开始请求 Gitea 仓库搜索接口', requestContext);
|
logger.debug('开始请求 Gitea 仓库搜索接口', requestContext);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await giteaAdminClient.get('/repos/search', {
|
const response = await giteaAdminClient.get('/repos/search', {
|
||||||
params: {
|
params: {
|
||||||
page,
|
page,
|
||||||
@@ -433,6 +438,7 @@ export const giteaService: GiteaService = {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isRepoListDebugEnabled) {
|
||||||
logger.debug('Gitea 仓库搜索接口返回成功', {
|
logger.debug('Gitea 仓库搜索接口返回成功', {
|
||||||
...requestContext,
|
...requestContext,
|
||||||
status: response.status,
|
status: response.status,
|
||||||
@@ -440,6 +446,7 @@ export const giteaService: GiteaService = {
|
|||||||
dataCount: Array.isArray(response.data?.data) ? response.data.data.length : null,
|
dataCount: Array.isArray(response.data?.data) ? response.data.data.length : null,
|
||||||
headerTotalCount: response.headers['x-total-count'] ?? null,
|
headerTotalCount: response.headers['x-total-count'] ?? null,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const totalCount = Number.parseInt(response.headers['x-total-count'] || '0', 10);
|
const totalCount = Number.parseInt(response.headers['x-total-count'] || '0', 10);
|
||||||
return { repos: response.data.data, totalCount };
|
return { repos: response.data.data, totalCount };
|
||||||
|
|||||||
Reference in New Issue
Block a user