job51-gitlab-cr-node-jt-1 2.1.4 → 2.1.6

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 +3 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -119,7 +119,7 @@ class GitLabCodeReviewer {
119
119
  const processBlock = async (diffObject, blockIndex) => {
120
120
  // 创建临时文件存储diff内容,文件地址选择当前文件夹下,避免权限问题
121
121
  const fileName = `temp-diff-block-${Date.now()}-${blockIndex}.diff`;
122
- const tmpFileName = path.join(__dirname, fileName);
122
+ const tmpFileName = path.join(process.cwd(), fileName);
123
123
 
124
124
  try {
125
125
  // 构造包含元数据的 diff 内容
@@ -137,13 +137,6 @@ ${diffObject.diff}`;
137
137
  const review_result = await this.reviewDiffWithClaudeUsingFile(tmpFileName);
138
138
  const blockObj = { ...diffObject, review_result, temp_file_path: tmpFileName };
139
139
 
140
- // 立即发布评论
141
- debugLog(`🤖 AI 代码审查结果: ${blockObj.review_result}`);
142
- await this.postSingleCommentToGitLab(projectId, mergeRequestIid, {
143
- diff_info: blockObj,
144
- block_index: blockObj.block_index,
145
- review_result: blockObj.review_result,
146
- });
147
140
  // 检查审查结果中是否包含严重问题,只有包含严重问题才发布评论
148
141
  if (blockObj.review_result && blockObj.review_result.includes('🔴 严重问题')) {
149
142
  // 立即发布评论
@@ -542,8 +535,8 @@ async function main() {
542
535
  function runClaudeCommand(promptContent) {
543
536
  return new Promise((resolve, reject) => {
544
537
 
545
- // 优先使用项目目录,如果未设置则使用当前脚本目录
546
- const projectDir = process.env.GITLAB_CR_PROJECT_DIR || __dirname;
538
+ // 使用当前工作目录,确保 Claude 能访问临时文件和项目代码
539
+ const projectDir = process.cwd();
547
540
  debugLog("AI review命令开始时间, 工作目录:" + projectDir);
548
541
 
549
542
  // 使用spawn替代exec,更安全地处理命令执行并实现环境隔离
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "job51-gitlab-cr-node-jt-1",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
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": {