ai-git-tools 2.0.38 → 2.0.39
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
|
@@ -11,9 +11,13 @@ export class GitOperations {
|
|
|
11
11
|
*/
|
|
12
12
|
detectReleaseBranches() {
|
|
13
13
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// 嘗試同步遠端,失敗就用本機已知的遠端資訊
|
|
15
|
+
try {
|
|
16
|
+
execSync('git fetch origin', { stdio: 'ignore', timeout: 15000 });
|
|
17
|
+
} catch (_) {
|
|
18
|
+
// fetch 失敗,繼續使用已經 cache 的遠端分支
|
|
19
|
+
}
|
|
20
|
+
const branches = execSync('git branch -r', { encoding: 'utf-8' })
|
|
17
21
|
.split('\n')
|
|
18
22
|
.map((b) => b.trim())
|
|
19
23
|
.filter((b) => b.startsWith('origin/release-'))
|
|
@@ -31,12 +35,18 @@ export class GitOperations {
|
|
|
31
35
|
const branches = this.detectReleaseBranches();
|
|
32
36
|
if (branches.length === 0) return null;
|
|
33
37
|
|
|
38
|
+
// 優先選月分支(-m),其次週分支(-w),最後 fallback 到全部 release 分支
|
|
34
39
|
const monthlyBranches = branches.filter((b) => b.includes('-m'));
|
|
35
40
|
const weeklyBranches = branches.filter((b) => b.includes('-w'));
|
|
36
|
-
const priorityBranches =
|
|
41
|
+
const priorityBranches =
|
|
42
|
+
monthlyBranches.length > 0
|
|
43
|
+
? monthlyBranches
|
|
44
|
+
: weeklyBranches.length > 0
|
|
45
|
+
? weeklyBranches
|
|
46
|
+
: branches;
|
|
37
47
|
|
|
38
48
|
priorityBranches.sort().reverse();
|
|
39
|
-
return priorityBranches[0];
|
|
49
|
+
return priorityBranches[0] || null;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
/**
|
|
@@ -135,9 +145,27 @@ export class GitOperations {
|
|
|
135
145
|
*/
|
|
136
146
|
async push(branch) {
|
|
137
147
|
try {
|
|
138
|
-
execSync(`git push -u origin ${branch}`, {
|
|
148
|
+
execSync(`git push -u origin ${branch}`, {
|
|
149
|
+
stdio: ['ignore', 'inherit', 'pipe'],
|
|
150
|
+
encoding: 'utf-8',
|
|
151
|
+
});
|
|
139
152
|
return true;
|
|
140
153
|
} catch (error) {
|
|
154
|
+
const errMsg = (error.stderr || error.message || '').toString();
|
|
155
|
+
const is403 = errMsg.includes('403') || errMsg.includes('Write access') || errMsg.includes('write access');
|
|
156
|
+
if (is403) {
|
|
157
|
+
throw new PRError(
|
|
158
|
+
'\u63a8送失敗:git 沒有寫入權限',
|
|
159
|
+
'GIT_PUSH_FORBIDDEN',
|
|
160
|
+
[
|
|
161
|
+
'建議執行以下指令讓 git 使用 gh 的認證:',
|
|
162
|
+
' gh auth setup-git',
|
|
163
|
+
'或者改用 SSH 權限:',
|
|
164
|
+
' git remote set-url origin git@github.com:<org>/<repo>.git',
|
|
165
|
+
],
|
|
166
|
+
`git push -u origin ${branch}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
141
169
|
throw new PRError(
|
|
142
170
|
'推送失敗',
|
|
143
171
|
'GIT_PUSH_FAILED',
|