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 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
- --auto-reviewers 自動選擇 reviewers
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 --draft
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
- --draft 創建草稿 PR
193
- --auto-reviewers 自動選擇 reviewers
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 --draft --auto-reviewers
197
+ npx ai-git-tools wf --preview
202
198
  \`\`\`
203
199
 
204
200
  ## ⚙️ 配置
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-git-tools",
3
- "version": "2.0.16",
3
+ "version": "2.0.18",
4
4
  "description": "AI-powered Git automation tools for commit messages and PR generation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -23,8 +23,8 @@ export default {
23
23
 
24
24
  // GitHub 相關配置
25
25
  github: {
26
- orgName: '', // GitHub 組織名稱(留空則自動從 git remote 取得,或使用 'kingsinfo-project')
27
- defaultBase: 'release', // 預設 base 分支(或使用 'auto' 自動偵測最新 release 分支,如 release-2025-m11.1)
26
+ orgName: '', // GitHub 組織名稱(留空則自動從 git remote 取得)
27
+ defaultBase: 'release', // PR分支(使用 'release' 自動偵測最新 release 分支,如 release-2025-m11.1)
28
28
  autoLabels: true, // 自動新增 Labels
29
29
  },
30
30
 
@@ -22,8 +22,6 @@ export async function prCommand() {
22
22
  // 載入配置(使用 scripts/ 的配置載入邏輯)
23
23
  const config = await loadConfig();
24
24
 
25
- console.log('📋 配置:', config);
26
-
27
25
  if (config.output.verbose) {
28
26
  console.log('📋 使用配置:');
29
27
  console.log(` AI Model: ${config.ai.model}`);
@@ -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-pr-config.mjs');
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 !== undefined) config.github.autoLabels = 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> 指定目標分支 (預設: 自動偵測最新 release 分支)
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 main --draft
120
- npx ai-git-tools pr --interactive-reviewers --auto-labels
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(config = {}) {
11
- // 如果沒有提供 orgName 或為空字串,則自動從 git remote 偵測
12
- this.orgName = config.orgName || this.detectOrgFromRemote();
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, config } = params;
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
- let createCmd = `gh pr create --base "${baseBranch}" --head "${headRef}" --title "${escapedTitle}" --body-file "${bodyFile}"`;
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(`Pull Request 創建成功!${config.draft ? ' (草稿模式)' : ''}`);
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
- log.step('正在偵測 release 分支...\n');
103
- const allBranches = this.git.detectReleaseBranches();
104
- const latestRelease = this.git.findLatestReleaseBranch();
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
- throw new PRError('未偵測到任何 release 分支', 'NO_RELEASE_BRANCH', [
113
- '使用 --base 參數指定目標分支',
114
- '確認遠端分支存在: git branch -r | grep release',
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