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:
jeffusion
2026-03-26 22:05:13 +08:00
committed by 路遥知码力
parent b6e6ee0927
commit 3a97d673f6
2 changed files with 36 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ import { logger } from '../utils/logger';
const publicRoutes = new Hono();
const protectedRoutes = new Hono();
const isRepoListDebugEnabled = process.env.REPO_LIST_DEBUG_LOGS === 'true';
// --- Public Routes ---
@@ -47,9 +48,12 @@ protectedRoutes.get('/repositories', async (c) => {
};
try {
if (isRepoListDebugEnabled) {
logger.debug('开始获取仓库列表', requestContext);
}
const { repos, totalCount } = await giteaService.listAllRepositories(page, limit, query);
if (isRepoListDebugEnabled) {
logger.debug('仓库搜索接口返回成功', {
...requestContext,
reposCount: repos.length,
@@ -58,16 +62,19 @@ protectedRoutes.get('/repositories', async (c) => {
.slice(0, 3)
.map((repo) => (typeof repo.full_name === 'string' ? repo.full_name : null)),
});
}
const webhookUrl = c.req.url.replace(/\/admin\/api\/repositories.*$/, '/webhook/gitea');
const fullNames = repos
.map((repo) => (typeof repo.full_name === 'string' ? repo.full_name : null))
.filter((name): name is string => name !== null);
if (isRepoListDebugEnabled) {
logger.debug('准备批量读取项目级提示词', {
...requestContext,
fullNamesCount: fullNames.length,
fullNamesSample: fullNames.slice(0, 5),
});
}
let promptMap: Record<string, string>;
try {

View File

@@ -3,6 +3,8 @@ import config from '../config';
import { toErrorLogMeta } from '../utils/error-log';
import { logger } from '../utils/logger';
const isRepoListDebugEnabled = process.env.REPO_LIST_DEBUG_LOGS === 'true';
export interface LineComment {
path: string;
line: number;
@@ -424,7 +426,10 @@ export const giteaService: GiteaService = {
};
try {
if (isRepoListDebugEnabled) {
logger.debug('开始请求 Gitea 仓库搜索接口', requestContext);
}
const response = await giteaAdminClient.get('/repos/search', {
params: {
page,
@@ -433,6 +438,7 @@ export const giteaService: GiteaService = {
},
});
if (isRepoListDebugEnabled) {
logger.debug('Gitea 仓库搜索接口返回成功', {
...requestContext,
status: response.status,
@@ -440,6 +446,7 @@ export const giteaService: GiteaService = {
dataCount: Array.isArray(response.data?.data) ? response.data.data.length : null,
headerTotalCount: response.headers['x-total-count'] ?? null,
});
}
const totalCount = Number.parseInt(response.headers['x-total-count'] || '0', 10);
return { repos: response.data.data, totalCount };