ai-git-tools 2.0.14 → 2.0.16
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/README.md
CHANGED
package/package.json
CHANGED
|
@@ -15,7 +15,6 @@ export function parseCliArgs() {
|
|
|
15
15
|
noConfirm: false,
|
|
16
16
|
interactiveReviewers: undefined,
|
|
17
17
|
autoLabels: null,
|
|
18
|
-
orgName: null,
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -29,9 +28,6 @@ export function parseCliArgs() {
|
|
|
29
28
|
case '--model':
|
|
30
29
|
config.model = args[++i];
|
|
31
30
|
break;
|
|
32
|
-
case '--org':
|
|
33
|
-
config.orgName = args[++i];
|
|
34
|
-
break;
|
|
35
31
|
case '--draft':
|
|
36
32
|
config.draft = true;
|
|
37
33
|
break;
|
|
@@ -65,7 +61,7 @@ export function parseCliArgs() {
|
|
|
65
61
|
*/
|
|
66
62
|
export async function loadConfig() {
|
|
67
63
|
// 1. 載入預設配置
|
|
68
|
-
const configPath = resolve(process.cwd(), '.ai-pr-config.
|
|
64
|
+
const configPath = resolve(process.cwd(), '.ai-pr-config.mjs');
|
|
69
65
|
let config = null;
|
|
70
66
|
|
|
71
67
|
if (existsSync(configPath)) {
|
|
@@ -75,7 +71,7 @@ export async function loadConfig() {
|
|
|
75
71
|
// 使用內建預設值
|
|
76
72
|
config = {
|
|
77
73
|
ai: { model: 'gpt-4.1', maxDiffLength: 8000, maxRetries: 3 },
|
|
78
|
-
github: {
|
|
74
|
+
github: { defaultBase: 'release', autoLabels: true },
|
|
79
75
|
reviewers: { interactiveReviewers: true, maxSuggested: 5, gitHistoryDepth: 20, excludeAuthors: [] },
|
|
80
76
|
output: { verbose: false, saveHistory: false },
|
|
81
77
|
};
|
|
@@ -86,7 +82,6 @@ export async function loadConfig() {
|
|
|
86
82
|
|
|
87
83
|
// 合併配置(CLI 參數優先)
|
|
88
84
|
if (cliConfig.model) config.ai.model = cliConfig.model;
|
|
89
|
-
if (cliConfig.orgName) config.github.orgName = cliConfig.orgName;
|
|
90
85
|
if (cliConfig.interactiveReviewers !== undefined) config.reviewers.interactiveReviewers = cliConfig.interactiveReviewers;
|
|
91
86
|
if (cliConfig.autoLabels !== undefined) config.github.autoLabels = cliConfig.autoLabels;
|
|
92
87
|
|
|
@@ -106,13 +101,12 @@ export async function loadConfig() {
|
|
|
106
101
|
function showHelp() {
|
|
107
102
|
console.log(`
|
|
108
103
|
使用方式:
|
|
109
|
-
|
|
104
|
+
npx ai-git-tools pr [選項]
|
|
110
105
|
|
|
111
106
|
選項:
|
|
112
107
|
--base <branch> 指定目標分支 (預設: 自動偵測最新 release 分支)
|
|
113
108
|
--head <branch> 指定來源分支 (預設: 當前分支)
|
|
114
109
|
--model <model> 指定 AI 模型 (預設: gpt-4.1)
|
|
115
|
-
--org <org-name> 指定 GitHub 組織名稱 (預設: kingsinfo-project)
|
|
116
110
|
--draft 創建草稿 PR
|
|
117
111
|
--preview 僅預覽 PR 內容,不實際創建
|
|
118
112
|
--no-confirm 跳過確認直接創建
|
|
@@ -121,8 +115,8 @@ function showHelp() {
|
|
|
121
115
|
--help 顯示此說明
|
|
122
116
|
|
|
123
117
|
範例:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
npx ai-git-tools pr
|
|
119
|
+
npx ai-git-tools pr --base main --draft
|
|
120
|
+
npx ai-git-tools pr --interactive-reviewers --auto-labels
|
|
127
121
|
`);
|
|
128
122
|
}
|
|
@@ -15,7 +15,7 @@ export class PRWorkflow {
|
|
|
15
15
|
constructor(config) {
|
|
16
16
|
this.config = config;
|
|
17
17
|
this.git = new GitOperations();
|
|
18
|
-
this.github = new GitHubAPI(
|
|
18
|
+
this.github = new GitHubAPI(); // 自動從 git remote 偵測組織名稱
|
|
19
19
|
this.ai = new AIAnalyzer({ model: config.ai.model });
|
|
20
20
|
this.labelAnalyzer = new LabelAnalyzer();
|
|
21
21
|
this.reviewerSelector = new ReviewerSelector({
|
|
@@ -319,15 +319,21 @@ export class PRWorkflow {
|
|
|
319
319
|
// 獲取當前用戶
|
|
320
320
|
const currentUser = this.git.getCurrentUser();
|
|
321
321
|
|
|
322
|
-
// 抓取 GitHub 團隊資訊
|
|
323
|
-
const teams = await this.github.fetchTeams();
|
|
324
|
-
|
|
325
322
|
// 根據 Git History 建議 Reviewers
|
|
326
323
|
const suggestedReviewers = this.reviewerSelector.getReviewersByGitHistory(
|
|
327
324
|
changeData.changedFiles
|
|
328
325
|
);
|
|
329
326
|
|
|
330
|
-
//
|
|
327
|
+
// 如果禁用互動式選擇,直接自動選擇
|
|
328
|
+
if (!this.config.reviewers.interactiveReviewers) {
|
|
329
|
+
console.log('🤖 自動選擇 reviewers(基於 Git 歷史)\n');
|
|
330
|
+
return this.reviewerSelector.autoSelectReviewers(suggestedReviewers, currentUser);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// 抓取 GitHub 團隊資訊(只在互動模式需要)
|
|
334
|
+
const teams = await this.github.fetchTeams();
|
|
335
|
+
|
|
336
|
+
// 選擇 Reviewers(互動模式)
|
|
331
337
|
return await this.reviewerSelector.select(teams, suggestedReviewers, currentUser);
|
|
332
338
|
}
|
|
333
339
|
|
|
@@ -353,6 +359,8 @@ export class PRWorkflow {
|
|
|
353
359
|
const labels = await this.labelAnalyzer.analyzeAndApply(prNumber, prData);
|
|
354
360
|
if (labels.length > 0) {
|
|
355
361
|
console.log(`📌 已添加 Labels: ${labels.join(', ')}\n`);
|
|
362
|
+
} else {
|
|
363
|
+
log.info('未找到適合的 Labels');
|
|
356
364
|
}
|
|
357
365
|
}
|
|
358
366
|
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI Git Tools 配置檔範本
|
|
3
|
-
*
|
|
4
|
-
* 此配置檔用於:
|
|
5
|
-
* - gitai commit:自動生成單個 commit
|
|
6
|
-
* - gitai commit-all:智能分析並批量 commit
|
|
7
|
-
* - gitai pr:自動生成 PR
|
|
8
|
-
* - gitai workflow:完整工作流程
|
|
9
|
-
*/
|
|
10
|
-
export default {
|
|
11
|
-
// AI 設定
|
|
12
|
-
ai: {
|
|
13
|
-
model: 'gpt-4.1', // AI 模型:gpt-4.1, claude-haiku-4.5, claude-sonnet-4.5
|
|
14
|
-
maxDiffLength: 8000, // 最大 diff 長度(字元)- 太小會導致 AI 看不到完整變更
|
|
15
|
-
maxRetries: 3, // API 失敗時的最大重試次數
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
// GitHub 設定(用於 PR 工具)
|
|
19
|
-
github: {
|
|
20
|
-
orgName: '', // GitHub 組織名稱(留空則自動從 git remote 取得,或使用 'kingsinfo-project')
|
|
21
|
-
defaultBase: 'release', // 預設目標分支:'release' | 'auto' | 'main' | 'develop' | 'master'
|
|
22
|
-
autoLabels: true, // 自動添加 Labels
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
// Reviewer 設定(用於 PR 工具)
|
|
26
|
-
reviewers: {
|
|
27
|
-
interactiveReviewers: true, // 是否啟用 reviewer 選擇功能(true: 啟用互動選擇 | false: 跳過選擇)
|
|
28
|
-
maxSuggested: 5, // 最多建議的 reviewers 數量(基於 Git 歷史分析)
|
|
29
|
-
gitHistoryDepth: 20, // Git 歷史分析深度(查看最近 N 筆 commit)
|
|
30
|
-
excludeAuthors: [], // 排除特定作者(email 或 username),例如: ['bot@', 'ci-user']
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
// 輸出設定
|
|
34
|
-
output: {
|
|
35
|
-
verbose: false, // 顯示詳細輸出
|
|
36
|
-
saveHistory: false, // 儲存操作歷史(未來功能)
|
|
37
|
-
},
|
|
38
|
-
};
|