ai-git-tools 2.0.34 → 2.0.35
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 +1 -1
- package/src/commands/pr.js +25 -14
- package/src/pr-modules/core/github-api.js +11 -21
- package/src/pr-modules/core/workflow.js +5 -10
package/package.json
CHANGED
package/src/commands/pr.js
CHANGED
|
@@ -5,19 +5,43 @@
|
|
|
5
5
|
* 確保功能與 scripts 版本完全相同
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { execSync } from 'child_process';
|
|
8
9
|
import { PRWorkflow } from '../pr-modules/core/workflow.js';
|
|
9
|
-
import { GitHubAPI } from '../pr-modules/core/github-api.js';
|
|
10
10
|
import { loadConfig } from '../pr-modules/core/config-loader.js';
|
|
11
11
|
import { handleError } from '../pr-modules/utils/helpers.js';
|
|
12
12
|
import { Logger } from '../pr-modules/ui/logger.js';
|
|
13
13
|
import { colors } from '../pr-modules/utils/constants.js';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* 檢查 gh CLI 是否已登入,未登入則印出提示並回傳 false
|
|
17
|
+
*/
|
|
18
|
+
function checkGHAuth(logger) {
|
|
19
|
+
try {
|
|
20
|
+
execSync('gh auth token', { stdio: 'pipe' });
|
|
21
|
+
return true;
|
|
22
|
+
} catch (_) {
|
|
23
|
+
logger.error('GitHub CLI 未登入,無法執行 PR 相關操作');
|
|
24
|
+
console.log('');
|
|
25
|
+
console.log('請先執行認證:');
|
|
26
|
+
console.log(` ${colors.green}gh auth login${colors.reset}`);
|
|
27
|
+
console.log('');
|
|
28
|
+
console.log('登入時請確保選取以下範圍:');
|
|
29
|
+
console.log(' - repo(必需)');
|
|
30
|
+
console.log(' - read:org(如需 reviewer 功能)');
|
|
31
|
+
console.log('');
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
15
36
|
/**
|
|
16
37
|
* PR 命令主函數(完全照抄 scripts/ai-auto-pr.mjs)
|
|
17
38
|
*/
|
|
18
39
|
export async function prCommand() {
|
|
19
40
|
const logger = new Logger();
|
|
20
41
|
|
|
42
|
+
// ── 第一步:確認 gh CLI 已登入 ──────────────────────────
|
|
43
|
+
if (!checkGHAuth(logger)) return;
|
|
44
|
+
|
|
21
45
|
try {
|
|
22
46
|
logger.header('AI Auto PR Generator (v2.0 Enhanced)');
|
|
23
47
|
|
|
@@ -30,19 +54,6 @@ export async function prCommand() {
|
|
|
30
54
|
console.log(` Max Diff Length: ${config.ai.maxDiffLength}`);
|
|
31
55
|
}
|
|
32
56
|
|
|
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
|
-
|
|
46
57
|
// 執行工作流程(使用 scripts/ 的完整工作流)
|
|
47
58
|
const workflow = new PRWorkflow(config);
|
|
48
59
|
await workflow.execute();
|
|
@@ -63,28 +63,10 @@ export class GitHubAPI {
|
|
|
63
63
|
*/
|
|
64
64
|
checkAuth() {
|
|
65
65
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const token = execSync('gh auth token', {
|
|
72
|
-
encoding: 'utf-8',
|
|
73
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
74
|
-
}).trim();
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
authenticated: Boolean(token),
|
|
78
|
-
details: authStatus,
|
|
79
|
-
};
|
|
66
|
+
execSync('gh auth token', { stdio: 'pipe' });
|
|
67
|
+
return { authenticated: true };
|
|
80
68
|
} catch (error) {
|
|
81
|
-
return {
|
|
82
|
-
authenticated: false,
|
|
83
|
-
details:
|
|
84
|
-
error.stderr?.toString?.() ||
|
|
85
|
-
error.stdout?.toString?.() ||
|
|
86
|
-
error.message,
|
|
87
|
-
};
|
|
69
|
+
return { authenticated: false };
|
|
88
70
|
}
|
|
89
71
|
}
|
|
90
72
|
|
|
@@ -122,6 +104,14 @@ export class GitHubAPI {
|
|
|
122
104
|
*/
|
|
123
105
|
async fetchTeams(orgName = this.orgName) {
|
|
124
106
|
try {
|
|
107
|
+
// 先檢查認證狀態
|
|
108
|
+
const authStatus = this.checkAuth();
|
|
109
|
+
if (!authStatus.authenticated) {
|
|
110
|
+
log.warning('GitHub CLI 未認證');
|
|
111
|
+
log.info('請執行: gh auth login\n');
|
|
112
|
+
return { teams: {}, members: [] };
|
|
113
|
+
}
|
|
114
|
+
|
|
125
115
|
log.step(`正在從 GitHub 抓取 ${orgName} 的團隊資訊...`);
|
|
126
116
|
|
|
127
117
|
let teamsJson;
|
|
@@ -32,17 +32,12 @@ export class PRWorkflow {
|
|
|
32
32
|
* 執行完整工作流程
|
|
33
33
|
*/
|
|
34
34
|
async execute() {
|
|
35
|
-
// 0.
|
|
35
|
+
// 0. 確認 gh CLI 已登入(預覽模式可跳過)
|
|
36
36
|
if (!this.config.preview) {
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.log(` ${colors.green}gh auth login${colors.reset}\n`);
|
|
42
|
-
console.log('選擇認證範圍時,請確保包含:');
|
|
43
|
-
console.log(' - repo (必需)');
|
|
44
|
-
console.log(' - read:org (如需使用 reviewer 功能)\n');
|
|
45
|
-
throw new Error('GitHub CLI 未認證,無法創建 PR');
|
|
37
|
+
const auth = this.github.checkAuth();
|
|
38
|
+
if (!auth.authenticated) {
|
|
39
|
+
log.error('GitHub CLI 未登入,請先執行: gh auth login');
|
|
40
|
+
throw new Error('GitHub CLI 未登入');
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
43
|
|