ai-git-tools 2.0.16 → 2.0.18
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 +10 -14
- package/package.json +1 -1
- package/src/commands/init.js +2 -2
- package/src/commands/pr.js +0 -2
- package/src/pr-modules/core/config-loader.js +20 -14
- package/src/pr-modules/core/github-api.js +6 -11
- package/src/pr-modules/core/workflow.js +21 -13
package/README.md
CHANGED
|
@@ -157,25 +157,22 @@ npx ai-git-tools ca --verbose
|
|
|
157
157
|
npx ai-git-tools pr [選項]
|
|
158
158
|
|
|
159
159
|
選項:
|
|
160
|
-
-b, --base <branch> 目標分支
|
|
161
|
-
-h, --head <branch> 來源分支
|
|
160
|
+
-b, --base <branch> 目標分支 (預設: 配置檔的 defaultBase 或自動偵測)
|
|
161
|
+
-h, --head <branch> 來源分支 (預設: 當前分支,通常不需指定)
|
|
162
162
|
-m, --model <model> 指定 AI 模型
|
|
163
|
-
--draft 創建草稿 PR
|
|
164
163
|
--preview 僅預覽,不創建 PR
|
|
165
164
|
--no-confirm 跳過確認直接創建
|
|
166
|
-
--
|
|
167
|
-
--auto-labels 自動添加 Labels
|
|
168
|
-
--no-labels 不添加 Labels
|
|
169
|
-
--org <name> GitHub 組織名稱
|
|
165
|
+
--interactive-reviewers 啟用互動式 reviewer 選擇 (預設啟用)
|
|
166
|
+
--auto-labels 自動添加 Labels (預設啟用)
|
|
170
167
|
\`\`\`
|
|
171
168
|
|
|
172
169
|
**範例:**
|
|
173
170
|
|
|
174
171
|
\`\`\`bash
|
|
175
172
|
npx ai-git-tools pr
|
|
176
|
-
npx ai-git-tools pr --
|
|
177
|
-
npx ai-git-tools pr --base main --auto-reviewers
|
|
173
|
+
npx ai-git-tools pr --base release-2025-m12.1
|
|
178
174
|
npx ai-git-tools pr --preview
|
|
175
|
+
npx ai-git-tools pr --no-confirm
|
|
179
176
|
\`\`\`
|
|
180
177
|
|
|
181
178
|
### \`gitai workflow\` (別名: \`wf\`)
|
|
@@ -188,17 +185,16 @@ npx ai-git-tools workflow [選項]
|
|
|
188
185
|
選項:
|
|
189
186
|
-m, --model <model> 指定 AI 模型
|
|
190
187
|
-v, --verbose 顯示詳細輸出
|
|
191
|
-
-b, --base <branch> PR 目標分支
|
|
192
|
-
--
|
|
193
|
-
--auto-
|
|
194
|
-
--auto-labels 自動添加 Labels
|
|
188
|
+
-b, --base <branch> PR 目標分支 (預設: 配置檔 defaultBase 或自動偵測)
|
|
189
|
+
--preview 僅預覽 PR,不創建
|
|
190
|
+
--auto-labels 自動添加 Labels (預設啟用)
|
|
195
191
|
\`\`\`
|
|
196
192
|
|
|
197
193
|
**範例:**
|
|
198
194
|
|
|
199
195
|
\`\`\`bash
|
|
200
196
|
npx ai-git-tools workflow
|
|
201
|
-
npx ai-git-tools wf --
|
|
197
|
+
npx ai-git-tools wf --preview
|
|
202
198
|
\`\`\`
|
|
203
199
|
|
|
204
200
|
## ⚙️ 配置
|
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -23,8 +23,8 @@ export default {
|
|
|
23
23
|
|
|
24
24
|
// GitHub 相關配置
|
|
25
25
|
github: {
|
|
26
|
-
orgName: '', // GitHub 組織名稱(留空則自動從 git remote
|
|
27
|
-
defaultBase: 'release', //
|
|
26
|
+
orgName: '', // GitHub 組織名稱(留空則自動從 git remote 取得)
|
|
27
|
+
defaultBase: 'release', // PR分支(使用 'release' 自動偵測最新 release 分支,如 release-2025-m11.1)
|
|
28
28
|
autoLabels: true, // 自動新增 Labels
|
|
29
29
|
},
|
|
30
30
|
|
package/src/commands/pr.js
CHANGED
|
@@ -10,7 +10,6 @@ export function parseCliArgs() {
|
|
|
10
10
|
baseBranch: null,
|
|
11
11
|
headBranch: null,
|
|
12
12
|
model: null,
|
|
13
|
-
draft: false,
|
|
14
13
|
preview: false,
|
|
15
14
|
noConfirm: false,
|
|
16
15
|
interactiveReviewers: undefined,
|
|
@@ -28,9 +27,6 @@ export function parseCliArgs() {
|
|
|
28
27
|
case '--model':
|
|
29
28
|
config.model = args[++i];
|
|
30
29
|
break;
|
|
31
|
-
case '--draft':
|
|
32
|
-
config.draft = true;
|
|
33
|
-
break;
|
|
34
30
|
case '--preview':
|
|
35
31
|
config.preview = true;
|
|
36
32
|
break;
|
|
@@ -61,7 +57,7 @@ export function parseCliArgs() {
|
|
|
61
57
|
*/
|
|
62
58
|
export async function loadConfig() {
|
|
63
59
|
// 1. 載入預設配置
|
|
64
|
-
const configPath = resolve(process.cwd(), '.ai-
|
|
60
|
+
const configPath = resolve(process.cwd(), '.ai-git-config.mjs');
|
|
65
61
|
let config = null;
|
|
66
62
|
|
|
67
63
|
if (existsSync(configPath)) {
|
|
@@ -83,12 +79,11 @@ export async function loadConfig() {
|
|
|
83
79
|
// 合併配置(CLI 參數優先)
|
|
84
80
|
if (cliConfig.model) config.ai.model = cliConfig.model;
|
|
85
81
|
if (cliConfig.interactiveReviewers !== undefined) config.reviewers.interactiveReviewers = cliConfig.interactiveReviewers;
|
|
86
|
-
if (cliConfig.autoLabels !==
|
|
82
|
+
if (cliConfig.autoLabels !== null) config.github.autoLabels = cliConfig.autoLabels;
|
|
87
83
|
|
|
88
84
|
// 其他 CLI 參數直接加入 config
|
|
89
85
|
config.baseBranch = cliConfig.baseBranch;
|
|
90
86
|
config.headBranch = cliConfig.headBranch;
|
|
91
|
-
config.draft = cliConfig.draft;
|
|
92
87
|
config.preview = cliConfig.preview;
|
|
93
88
|
config.noConfirm = cliConfig.noConfirm;
|
|
94
89
|
|
|
@@ -104,19 +99,30 @@ function showHelp() {
|
|
|
104
99
|
npx ai-git-tools pr [選項]
|
|
105
100
|
|
|
106
101
|
選項:
|
|
107
|
-
--base <branch> 指定目標分支 (預設:
|
|
108
|
-
--head <branch> 指定來源分支 (預設:
|
|
102
|
+
--base <branch> 指定目標分支 (預設: 使用配置檔的 defaultBase 或自動偵測)
|
|
103
|
+
--head <branch> 指定來源分支 (預設: 當前分支,通常不需要指定)
|
|
109
104
|
--model <model> 指定 AI 模型 (預設: gpt-4.1)
|
|
110
|
-
--draft 創建草稿 PR
|
|
111
105
|
--preview 僅預覽 PR 內容,不實際創建
|
|
112
106
|
--no-confirm 跳過確認直接創建
|
|
113
|
-
--interactive-reviewers 啟用互動式 reviewer
|
|
114
|
-
--auto-labels 自動添加 Labels
|
|
107
|
+
--interactive-reviewers 啟用互動式 reviewer 選擇 (預設啟用)
|
|
108
|
+
--auto-labels 自動添加 Labels (預設啟用)
|
|
115
109
|
--help 顯示此說明
|
|
116
110
|
|
|
117
111
|
範例:
|
|
118
112
|
npx ai-git-tools pr
|
|
119
|
-
npx ai-git-tools pr --base
|
|
120
|
-
npx ai-git-tools pr --
|
|
113
|
+
npx ai-git-tools pr --base release-2025-m12.1
|
|
114
|
+
npx ai-git-tools pr --preview
|
|
115
|
+
npx ai-git-tools pr --no-confirm
|
|
116
|
+
|
|
117
|
+
配置檔範例 (.ai-git-config.js):
|
|
118
|
+
export default {
|
|
119
|
+
github: {
|
|
120
|
+
defaultBase: 'release-2025-m12.1', // 指定預設目標分支
|
|
121
|
+
autoLabels: true,
|
|
122
|
+
},
|
|
123
|
+
reviewers: {
|
|
124
|
+
interactiveReviewers: true, // 啟用互動式選擇 reviewers
|
|
125
|
+
},
|
|
126
|
+
};
|
|
121
127
|
`);
|
|
122
128
|
}
|
|
@@ -7,9 +7,9 @@ import { colors } from '../utils/constants.js';
|
|
|
7
7
|
* GitHub API 操作封裝
|
|
8
8
|
*/
|
|
9
9
|
export class GitHubAPI {
|
|
10
|
-
constructor(
|
|
11
|
-
//
|
|
12
|
-
this.orgName =
|
|
10
|
+
constructor() {
|
|
11
|
+
// 自動從 git remote 偵測組織名稱
|
|
12
|
+
this.orgName = this.detectOrgFromRemote();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -211,7 +211,7 @@ export class GitHubAPI {
|
|
|
211
211
|
* 創建或更新 PR
|
|
212
212
|
*/
|
|
213
213
|
async createOrUpdatePR(params) {
|
|
214
|
-
const { title, body, baseBranch, headBranch, reviewers
|
|
214
|
+
const { title, body, baseBranch, headBranch, reviewers } = params;
|
|
215
215
|
const bodyFile = '/tmp/pr-body.md';
|
|
216
216
|
writeFileSync(bodyFile, body);
|
|
217
217
|
|
|
@@ -227,7 +227,6 @@ export class GitHubAPI {
|
|
|
227
227
|
// PR 不存在
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
const draftFlag = config.draft ? '--draft' : '';
|
|
231
230
|
const escapedTitle = title.replace(/"/g, '\\"');
|
|
232
231
|
|
|
233
232
|
if (existingPRUrl) {
|
|
@@ -259,18 +258,14 @@ export class GitHubAPI {
|
|
|
259
258
|
} else if (this.orgName) {
|
|
260
259
|
headRef = `${this.orgName}:${headBranch}`;
|
|
261
260
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (draftFlag) {
|
|
265
|
-
createCmd += ` ${draftFlag}`;
|
|
266
|
-
}
|
|
261
|
+
const createCmd = `gh pr create --base "${baseBranch}" --head "${headRef}" --title "${escapedTitle}" --body-file "${bodyFile}"`;
|
|
267
262
|
|
|
268
263
|
try {
|
|
269
264
|
const result = execSync(createCmd, {
|
|
270
265
|
encoding: 'utf-8',
|
|
271
266
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
272
267
|
});
|
|
273
|
-
log.success(
|
|
268
|
+
log.success('Pull Request 創建成功!');
|
|
274
269
|
|
|
275
270
|
// 提取 PR URL
|
|
276
271
|
const prUrl = result
|
|
@@ -99,20 +99,28 @@ export class PRWorkflow {
|
|
|
99
99
|
|
|
100
100
|
// 自動偵測 base branch
|
|
101
101
|
if (!baseBranch) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (latestRelease) {
|
|
107
|
-
baseBranch = latestRelease;
|
|
108
|
-
this.displayDetectedBranches(allBranches, latestRelease);
|
|
109
|
-
log.success(`自動選擇最新分支: ${baseBranch}`);
|
|
110
|
-
log.info(`提示: 使用 --base <分支名> 指定其他分支\n`);
|
|
102
|
+
// 優先使用配置檔中的 defaultBase
|
|
103
|
+
if (this.config.github?.defaultBase) {
|
|
104
|
+
baseBranch = this.config.github.defaultBase;
|
|
105
|
+
log.success(`使用配置檔指定的分支: ${baseBranch}\n`);
|
|
111
106
|
} else {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
// 如果沒有配置,則自動偵測最新的 release 分支
|
|
108
|
+
log.step('正在偵測 release 分支...\n');
|
|
109
|
+
const allBranches = this.git.detectReleaseBranches();
|
|
110
|
+
const latestRelease = this.git.findLatestReleaseBranch();
|
|
111
|
+
|
|
112
|
+
if (latestRelease) {
|
|
113
|
+
baseBranch = latestRelease;
|
|
114
|
+
this.displayDetectedBranches(allBranches, latestRelease);
|
|
115
|
+
log.success(`自動選擇最新分支: ${baseBranch}`);
|
|
116
|
+
log.info(`提示: 使用 --base <分支名> 指定其他分支\n`);
|
|
117
|
+
} else {
|
|
118
|
+
throw new PRError('未偵測到任何 release 分支', 'NO_RELEASE_BRANCH', [
|
|
119
|
+
'使用 --base 參數指定目標分支',
|
|
120
|
+
'或在 .ai-git-config.js 中設置 github.defaultBase',
|
|
121
|
+
'確認遠端分支存在: git branch -r | grep release',
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
|