ai-git-tools 2.0.32 → 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
package/src/commands/pr.js
CHANGED
|
@@ -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
|
|
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:
|
|
77
|
+
authenticated: Boolean(token),
|
|
73
78
|
details: authStatus,
|
|
74
79
|
};
|
|
75
80
|
} catch (error) {
|
|
76
81
|
return {
|
|
77
82
|
authenticated: false,
|
|
78
|
-
details:
|
|
83
|
+
details:
|
|
84
|
+
error.stderr?.toString?.() ||
|
|
85
|
+
error.stdout?.toString?.() ||
|
|
86
|
+
error.message,
|
|
79
87
|
};
|
|
80
88
|
}
|
|
81
89
|
}
|
|
@@ -114,18 +122,6 @@ export class GitHubAPI {
|
|
|
114
122
|
*/
|
|
115
123
|
async fetchTeams(orgName = this.orgName) {
|
|
116
124
|
try {
|
|
117
|
-
// 先檢查認證狀態
|
|
118
|
-
const authStatus = this.checkAuth();
|
|
119
|
-
if (!authStatus.authenticated) {
|
|
120
|
-
log.error('\n❌ GitHub CLI 未認證\n');
|
|
121
|
-
console.log('請先執行認證:');
|
|
122
|
-
console.log(` ${colors.green}gh auth login${colors.reset}\n`);
|
|
123
|
-
console.log('選擇認證範圍時,請確保包含:');
|
|
124
|
-
console.log(' - repo (必需)');
|
|
125
|
-
console.log(' - read:org (如需使用 reviewer 功能)\n');
|
|
126
|
-
throw new Error('GitHub CLI 未認證,無法創建 PR');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
125
|
log.step(`正在從 GitHub 抓取 ${orgName} 的團隊資訊...`);
|
|
130
126
|
|
|
131
127
|
let teamsJson;
|
|
@@ -32,6 +32,20 @@ export class PRWorkflow {
|
|
|
32
32
|
* 執行完整工作流程
|
|
33
33
|
*/
|
|
34
34
|
async execute() {
|
|
35
|
+
// 0. 檢查 GitHub CLI 認證狀態(預覽模式不需要)
|
|
36
|
+
if (!this.config.preview) {
|
|
37
|
+
const authStatus = this.github.checkAuth();
|
|
38
|
+
if (!authStatus.authenticated) {
|
|
39
|
+
this.logger.error('\n❌ GitHub CLI 未認證\n');
|
|
40
|
+
console.log('請先執行認證:');
|
|
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');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
// 1. 驗證環境和分支
|
|
36
50
|
const { baseBranch, headBranch } = await this.detectAndValidateBranches();
|
|
37
51
|
|