ai-git-tools 2.0.33 → 2.0.34

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-git-tools",
3
- "version": "2.0.33",
3
+ "version": "2.0.34",
4
4
  "description": "AI-powered Git automation tools for commit messages and PR generation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -6,9 +6,11 @@
6
6
  */
7
7
 
8
8
  import { PRWorkflow } from '../pr-modules/core/workflow.js';
9
+ import { GitHubAPI } from '../pr-modules/core/github-api.js';
9
10
  import { loadConfig } from '../pr-modules/core/config-loader.js';
10
11
  import { handleError } from '../pr-modules/utils/helpers.js';
11
12
  import { Logger } from '../pr-modules/ui/logger.js';
13
+ import { colors } from '../pr-modules/utils/constants.js';
12
14
 
13
15
  /**
14
16
  * PR 命令主函數(完全照抄 scripts/ai-auto-pr.mjs)
@@ -28,6 +30,19 @@ export async function prCommand() {
28
30
  console.log(` Max Diff Length: ${config.ai.maxDiffLength}`);
29
31
  }
30
32
 
33
+ // 在進入 workflow 前先檢查 GitHub CLI 認證
34
+ if (!config.preview) {
35
+ const github = new GitHubAPI();
36
+ const authStatus = github.checkAuth();
37
+ if (!authStatus.authenticated) {
38
+ logger.error('\n❌ GitHub CLI 未認證\n');
39
+ console.log('請先執行認證:');
40
+ console.log(` ${colors.green}gh auth login${colors.reset}\n`);
41
+ console.log('完成登入後再執行: npx ai-git-tools pr\n');
42
+ return;
43
+ }
44
+ }
45
+
31
46
  // 執行工作流程(使用 scripts/ 的完整工作流)
32
47
  const workflow = new PRWorkflow(config);
33
48
  await workflow.execute();
@@ -63,19 +63,27 @@ export class GitHubAPI {
63
63
  */
64
64
  checkAuth() {
65
65
  try {
66
- const authStatus = execSync('gh auth status 2>&1', {
66
+ const authStatus = execSync('gh auth status --hostname github.com', {
67
67
  encoding: 'utf-8',
68
68
  stdio: ['pipe', 'pipe', 'pipe'],
69
69
  });
70
70
 
71
+ const token = execSync('gh auth token', {
72
+ encoding: 'utf-8',
73
+ stdio: ['pipe', 'pipe', 'pipe'],
74
+ }).trim();
75
+
71
76
  return {
72
- authenticated: authStatus.includes('Logged in'),
77
+ authenticated: Boolean(token),
73
78
  details: authStatus,
74
79
  };
75
80
  } catch (error) {
76
81
  return {
77
82
  authenticated: false,
78
- details: error.message,
83
+ details:
84
+ error.stderr?.toString?.() ||
85
+ error.stdout?.toString?.() ||
86
+ error.message,
79
87
  };
80
88
  }
81
89
  }
@@ -38,7 +38,7 @@ export class PRWorkflow {
38
38
  if (!authStatus.authenticated) {
39
39
  this.logger.error('\n❌ GitHub CLI 未認證\n');
40
40
  console.log('請先執行認證:');
41
- console.log(` ${this.logger.colors.green}gh auth login${this.logger.colors.reset}\n`);
41
+ console.log(` ${colors.green}gh auth login${colors.reset}\n`);
42
42
  console.log('選擇認證範圍時,請確保包含:');
43
43
  console.log(' - repo (必需)');
44
44
  console.log(' - read:org (如需使用 reviewer 功能)\n');