ai-git-tools 2.0.57 → 2.0.58

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/bin/cli.js CHANGED
@@ -87,6 +87,7 @@ program
87
87
  .option('--no-confirm', '跳過確認直接創建')
88
88
  .option('--auto-labels', '自動添加 Labels (預設啟用)')
89
89
  .option('--include-impact', '在 PR 中包含影響範圍分析和注意事項 (預設關閉)')
90
+ .option('--force-new', '強制創建新 PR,不更新現有 PR')
90
91
  .action(async (options) => {
91
92
  try {
92
93
  await prCommand(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-git-tools",
3
- "version": "2.0.57",
3
+ "version": "2.0.58",
4
4
  "description": "AI-powered Git automation tools for commit messages and PR generation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -36,7 +36,7 @@ function checkGHAuth(logger) {
36
36
  /**
37
37
  * PR 命令主函數(完全照抄 scripts/ai-auto-pr.mjs)
38
38
  */
39
- export async function prCommand() {
39
+ export async function prCommand(options = {}) {
40
40
  const logger = new Logger();
41
41
 
42
42
  // ── 第一步:確認 gh CLI 已登入 ──────────────────────────
@@ -54,6 +54,11 @@ export async function prCommand() {
54
54
  console.log(` Max Diff Length: ${config.ai.maxDiffLength}`);
55
55
  }
56
56
 
57
+ // 將命令行選項合併到配置中
58
+ if (options.forceNew) {
59
+ config.forceNew = true;
60
+ }
61
+
57
62
  // 執行工作流程(使用 scripts/ 的完整工作流)
58
63
  const workflow = new PRWorkflow(config);
59
64
  await workflow.execute();
@@ -193,20 +193,22 @@ export class GitHubAPI {
193
193
  * 創建或更新 PR
194
194
  */
195
195
  async createOrUpdatePR(params) {
196
- const { title, body, baseBranch, headBranch, reviewers } = params;
196
+ const { title, body, baseBranch, headBranch, reviewers, forceNew } = params;
197
197
  const bodyFile = '/tmp/pr-body.md';
198
198
  writeFileSync(bodyFile, body);
199
199
 
200
200
  try {
201
- // 檢查 PR 是否已存在
201
+ // 檢查 PR 是否已存在(除非強制創建新 PR)
202
202
  let existingPRUrl = null;
203
- try {
204
- existingPRUrl = execSync(
205
- `gh pr list --head "${headBranch}" --base "${baseBranch}" --json url --jq '.[0].url'`,
206
- { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }
207
- ).trim();
208
- } catch (error) {
209
- // PR 不存在
203
+ if (!forceNew) {
204
+ try {
205
+ existingPRUrl = execSync(
206
+ `gh pr list --head "${headBranch}" --base "${baseBranch}" --json url --jq '.[0].url'`,
207
+ { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }
208
+ ).trim();
209
+ } catch (error) {
210
+ // PR 不存在
211
+ }
210
212
  }
211
213
 
212
214
  const escapedTitle = title.replace(/"/g, '\\"');
@@ -422,6 +422,7 @@ export class PRWorkflow {
422
422
  headBranch,
423
423
  reviewers,
424
424
  config: this.config,
425
+ forceNew: this.config.forceNew,
425
426
  });
426
427
  }
427
428