ai-git-tools 2.0.11 → 2.0.13

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-git-tools",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "AI-powered Git automation tools for commit messages and PR generation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * PR 命令 - 完整複製自 scripts/ai-auto-pr.mjs
3
- *
3
+ *
4
4
  * 使用 pr-modules 的完整邏輯(從 scripts/ai-pr-modules 複製)
5
5
  * 確保功能與 scripts 版本完全相同
6
6
  */
@@ -22,6 +22,14 @@ export async function prCommand() {
22
22
  // 載入配置(使用 scripts/ 的配置載入邏輯)
23
23
  const config = await loadConfig();
24
24
 
25
+ console.log('📋 配置:', config);
26
+
27
+ if (config.output.verbose) {
28
+ console.log('📋 使用配置:');
29
+ console.log(` AI Model: ${config.ai.model}`);
30
+ console.log(` Max Diff Length: ${config.ai.maxDiffLength}`);
31
+ }
32
+
25
33
  // 執行工作流程(使用 scripts/ 的完整工作流)
26
34
  const workflow = new PRWorkflow(config);
27
35
  await workflow.execute();
@@ -47,9 +47,6 @@ export function parseCliArgs() {
47
47
  case '--auto-labels':
48
48
  config.autoLabels = true;
49
49
  break;
50
- case '--no-labels':
51
- config.autoLabels = false;
52
- break;
53
50
  case '--help':
54
51
  showHelp();
55
52
  process.exit(0);
@@ -120,8 +117,7 @@ function showHelp() {
120
117
  --preview 僅預覽 PR 內容,不實際創建
121
118
  --no-confirm 跳過確認直接創建
122
119
  --interactive-reviewers 啟用互動式 reviewer 選擇(預設啟用)
123
- --auto-labels 自動添加 Labels(預設啟用)
124
- --no-labels 不添加 Labels
120
+ --auto-labels 自動添加 Labels(預設啟用)
125
121
  --help 顯示此說明
126
122
 
127
123
  範例:
@@ -8,7 +8,40 @@ import { colors } from '../utils/constants.js';
8
8
  */
9
9
  export class GitHubAPI {
10
10
  constructor(config = {}) {
11
- this.orgName = config.orgName || 'kingsinfo-project';
11
+ // 如果沒有提供 orgName 或為空字串,則自動從 git remote 偵測
12
+ this.orgName = config.orgName || this.detectOrgFromRemote();
13
+ }
14
+
15
+ /**
16
+ * 從 git remote URL 自動偵測組織名稱
17
+ */
18
+ detectOrgFromRemote() {
19
+ try {
20
+ const remoteUrl = execSync('git remote get-url origin', {
21
+ encoding: 'utf-8',
22
+ stdio: ['pipe', 'pipe', 'pipe'],
23
+ }).trim();
24
+
25
+ // 解析 HTTPS 格式: https://github.com/org/repo.git
26
+ const httpsMatch = remoteUrl.match(/github\.com\/([^/]+)\//);
27
+ if (httpsMatch) {
28
+ log.info(`自動偵測組織名稱: ${httpsMatch[1]}\n`);
29
+ return httpsMatch[1];
30
+ }
31
+
32
+ // 解析 SSH 格式: git@github.com:org/repo.git
33
+ const sshMatch = remoteUrl.match(/github\.com:([^/]+)\//);
34
+ if (sshMatch) {
35
+ log.info(`自動偵測組織名稱: ${sshMatch[1]}\n`);
36
+ return sshMatch[1];
37
+ }
38
+
39
+ log.warning('無法從 git remote 偵測組織名稱');
40
+ return null;
41
+ } catch (error) {
42
+ log.warning('無法從 git remote 偵測組織名稱');
43
+ return null;
44
+ }
12
45
  }
13
46
 
14
47
  /**
@@ -80,6 +113,13 @@ export class GitHubAPI {
80
113
  * 從 GitHub 抓取組織的團隊列表
81
114
  */
82
115
  async fetchTeams(orgName = this.orgName) {
116
+ // 如果沒有 orgName,直接返回空結果
117
+ if (!orgName || orgName.trim() === '') {
118
+ log.warning('未設置 GitHub 組織名稱,且無法自動偵測');
119
+ log.info('請在 .ai-pr-config.js 中設置 github.orgName 或使用 --org 參數\n');
120
+ return { teams: {}, members: [] };
121
+ }
122
+
83
123
  try {
84
124
  // 先檢查認證狀態
85
125
  const authStatus = this.checkAuth();
@@ -211,11 +251,15 @@ export class GitHubAPI {
211
251
  // 創建新 PR
212
252
  log.step('正在創建 Pull Request...');
213
253
 
214
- // 使用完整的分支格式(包含組織名稱)以避免 GitHub API 錯誤
215
- const fullHeadBranch = headBranch.includes(':')
216
- ? headBranch
217
- : `${this.orgName}:${headBranch}`;
218
- let createCmd = `gh pr create --base "${baseBranch}" --head "${fullHeadBranch}" --title "${escapedTitle}" --body-file "${bodyFile}"`;
254
+ // 如果有 orgName 且是組織 repo,使用完整的分支格式
255
+ // 如果沒有 orgName,直接使用分支名稱(gh CLI 會自動處理)
256
+ let headRef = headBranch;
257
+ if (headBranch.includes(':')) {
258
+ headRef = headBranch;
259
+ } else if (this.orgName) {
260
+ headRef = `${this.orgName}:${headBranch}`;
261
+ }
262
+ let createCmd = `gh pr create --base "${baseBranch}" --head "${headRef}" --title "${escapedTitle}" --body-file "${bodyFile}"`;
219
263
 
220
264
  if (draftFlag) {
221
265
  createCmd += ` ${draftFlag}`;