ai-git-tools 2.0.12 → 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
package/src/commands/pr.js
CHANGED
|
@@ -8,8 +8,40 @@ import { colors } from '../utils/constants.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export class GitHubAPI {
|
|
10
10
|
constructor(config = {}) {
|
|
11
|
-
// 如果沒有提供 orgName
|
|
12
|
-
this.orgName = config.orgName ||
|
|
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
|
+
}
|
|
13
45
|
}
|
|
14
46
|
|
|
15
47
|
/**
|
|
@@ -83,8 +115,8 @@ export class GitHubAPI {
|
|
|
83
115
|
async fetchTeams(orgName = this.orgName) {
|
|
84
116
|
// 如果沒有 orgName,直接返回空結果
|
|
85
117
|
if (!orgName || orgName.trim() === '') {
|
|
86
|
-
log.warning('未設置 GitHub
|
|
87
|
-
log.info('請在 .ai-pr-config.
|
|
118
|
+
log.warning('未設置 GitHub 組織名稱,且無法自動偵測');
|
|
119
|
+
log.info('請在 .ai-pr-config.js 中設置 github.orgName 或使用 --org 參數\n');
|
|
88
120
|
return { teams: {}, members: [] };
|
|
89
121
|
}
|
|
90
122
|
|
|
@@ -219,11 +251,15 @@ export class GitHubAPI {
|
|
|
219
251
|
// 創建新 PR
|
|
220
252
|
log.step('正在創建 Pull Request...');
|
|
221
253
|
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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}"`;
|
|
227
263
|
|
|
228
264
|
if (draftFlag) {
|
|
229
265
|
createCmd += ` ${draftFlag}`;
|