job51-gitlab-cr-node-jt-1 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +50 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1286,9 +1286,59 @@ ${largeFilePrompt}
1286
1286
  }
1287
1287
  }
1288
1288
 
1289
+ /**
1290
+ * 替换 settings.json 中的环境变量占位符
1291
+ * settings.json 使用 ${VAR} 格式作为占位符,需要在运行时替换为实际值
1292
+ * @param {string} settingsPath settings.json 文件路径
1293
+ */
1294
+ function replaceSettingsEnvVars(settingsPath) {
1295
+ try {
1296
+ if (!fs.existsSync(settingsPath)) {
1297
+ debugLog(`settings.json 文件不存在: ${settingsPath}`);
1298
+ return;
1299
+ }
1300
+
1301
+ let content = fs.readFileSync(settingsPath, 'utf-8');
1302
+ debugLog(`读取 settings.json 内容,准备替换环境变量占位符`);
1303
+
1304
+ // 需要替换的环境变量列表
1305
+ const envVars = [
1306
+ 'ANTHROPIC_AUTH_TOKEN',
1307
+ 'ANTHROPIC_BASE_URL',
1308
+ 'API_TIMEOUT_MS',
1309
+ 'ANTHROPIC_MODEL',
1310
+ 'ANTHROPIC_SMALL_FAST_MODEL',
1311
+ 'SLASH_COMMAND_TOOL_CHAR_BUDGET'
1312
+ ];
1313
+
1314
+ // 替换每个占位符
1315
+ for (const varName of envVars) {
1316
+ const placeholder = `\${${varName}}`;
1317
+ const actualValue = process.env[varName] || '';
1318
+ if (content.includes(placeholder)) {
1319
+ content = content.replace(new RegExp(placeholder.replace(/\$/g, '\\$'), 'g'), actualValue);
1320
+ debugLog(`替换 ${placeholder} -> ${varName === 'ANTHROPIC_AUTH_TOKEN' ? '(已隐藏)' : actualValue}`);
1321
+ }
1322
+ }
1323
+
1324
+ // 写回文件
1325
+ fs.writeFileSync(settingsPath, content, 'utf-8');
1326
+ debugLog(`settings.json 环境变量替换完成`);
1327
+ } catch (error) {
1328
+ warnLog(`替换 settings.json 环境变量失败: ${error.message}`);
1329
+ // 不中断流程,继续执行
1330
+ }
1331
+ }
1332
+
1289
1333
  // 主函数
1290
1334
  async function main() {
1291
1335
  debugLog('开始加载环境变量');
1336
+
1337
+ // 替换 settings.json 中的环境变量占位符
1338
+ // settings.json 路径:工作目录下的 .claude/settings.json
1339
+ const projectDir = process.env.GITLAB_CR_PROJECT_DIR || process.cwd();
1340
+ const settingsPath = path.join(projectDir, '.claude', 'settings.json');
1341
+ replaceSettingsEnvVars(settingsPath);
1292
1342
  // 从环境变量获取配置
1293
1343
  const gitlabUrl = process.env.CI_API_V4_URL;
1294
1344
  const gitlabToken = process.env.GITLAB_ACCESS_TOKEN;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "job51-gitlab-cr-node-jt-1",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "GitLab merge request code review tool with AI-powered analysis and project context support",
5
5
  "main": "index.js",
6
6
  "bin": {