@zjex/git-workflow 0.2.24 → 0.3.2

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.
Files changed (99) hide show
  1. package/.github/workflows/deploy-docs.yml +68 -0
  2. package/.github/workflows/test.yml +24 -4
  3. package/.husky/pre-commit +17 -0
  4. package/README.md +72 -1066
  5. package/ROADMAP.md +275 -0
  6. package/dist/index.js +450 -99
  7. package/docs/.vitepress/cache/deps/_metadata.json +52 -0
  8. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js +9719 -0
  9. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js.map +7 -0
  10. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js +12824 -0
  11. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js.map +7 -0
  12. package/docs/.vitepress/cache/deps/package.json +3 -0
  13. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4505 -0
  14. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  15. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
  16. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  17. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  18. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  19. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1665 -0
  20. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  21. package/docs/.vitepress/cache/deps/vitepress___minisearch.js +1813 -0
  22. package/docs/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
  23. package/docs/.vitepress/cache/deps/vue.js +347 -0
  24. package/docs/.vitepress/cache/deps/vue.js.map +7 -0
  25. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js +9719 -0
  26. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js.map +7 -0
  27. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js +12824 -0
  28. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js.map +7 -0
  29. package/docs/.vitepress/cache/deps_temp_44e2fb0f/package.json +3 -0
  30. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js +4505 -0
  31. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js.map +7 -0
  32. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js +583 -0
  33. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js.map +7 -0
  34. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  35. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  36. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js +1665 -0
  37. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  38. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js +1813 -0
  39. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js.map +7 -0
  40. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js +347 -0
  41. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js.map +7 -0
  42. package/docs/.vitepress/config.ts +167 -0
  43. package/docs/.vitepress/theme/custom.css +39 -0
  44. package/docs/.vitepress/theme/index.ts +4 -0
  45. package/docs/README.md +82 -0
  46. package/docs/commands/branch.md +468 -0
  47. package/docs/commands/commit.md +554 -0
  48. package/docs/commands/config.md +346 -0
  49. package/docs/commands/index.md +312 -0
  50. package/docs/commands/interactive.md +384 -0
  51. package/docs/commands/release.md +300 -0
  52. package/docs/commands/stash.md +309 -0
  53. package/docs/commands/tag.md +278 -0
  54. package/docs/commands/update.md +347 -0
  55. package/docs/config/ai-config.md +160 -0
  56. package/docs/config/branch-config.md +133 -0
  57. package/docs/config/commit-config.md +185 -0
  58. package/docs/config/config-file.md +776 -0
  59. package/docs/config/examples.md +279 -0
  60. package/docs/config/index.md +478 -0
  61. package/docs/features/git-wrapped.md +199 -0
  62. package/docs/guide/ai-commit.md +576 -0
  63. package/docs/guide/basic-usage.md +522 -0
  64. package/docs/guide/best-practices.md +426 -0
  65. package/docs/guide/branch-management.md +712 -0
  66. package/docs/guide/getting-started.md +294 -0
  67. package/docs/guide/index.md +168 -0
  68. package/docs/guide/installation.md +449 -0
  69. package/docs/guide/release-management.md +744 -0
  70. package/docs/guide/stash-management.md +608 -0
  71. package/docs/guide/tag-management.md +614 -0
  72. package/docs/index.md +205 -0
  73. package/docs/public/favicon.svg +21 -0
  74. package/docs/public/hero-logo.svg +43 -0
  75. package/docs/public/logo.svg +20 -0
  76. package/package.json +12 -2
  77. package/scripts/publish.js +55 -8
  78. package/scripts/publish.sh +20 -2
  79. package/scripts/release.sh +81 -3
  80. package/scripts/update-test-count.js +55 -0
  81. package/src/ai-service.ts +107 -15
  82. package/src/commands/commit.ts +4 -0
  83. package/src/commands/init.ts +18 -0
  84. package/src/commands/log.ts +503 -0
  85. package/src/config.ts +1 -0
  86. package/src/index.ts +37 -13
  87. package/src/utils.ts +10 -0
  88. package/tests/ai-service.test.ts +237 -2
  89. package/tests/init.test.ts +582 -0
  90. package/tests/log.test.ts +106 -0
  91. package/tests/release.test.ts +333 -0
  92. package/tests/setup.ts +21 -0
  93. package/tests/stash.test.ts +376 -0
  94. package/tests/update.test.ts +402 -0
  95. package/vitest.config.ts +3 -0
  96. package/zjex-logo.svg +22 -0
  97. package/zjex-optimized.svg +34 -0
  98. package/zjex.svg +1 -0
  99. package/src/commands/help.ts +0 -76
@@ -121,7 +121,7 @@ describe("AI Service 模块测试", () => {
121
121
  provider: "github",
122
122
  apiKey: "test-key",
123
123
  language: "zh-CN",
124
- maxTokens: 200,
124
+ // 不设置 maxTokens,让它自动计算
125
125
  },
126
126
  };
127
127
 
@@ -310,7 +310,7 @@ describe("AI Service 模块测试", () => {
310
310
  });
311
311
 
312
312
  it("应该截断过长的 diff", async () => {
313
- const longDiff = "a".repeat(5000);
313
+ const longDiff = "a".repeat(7000); // 超过详细模式的 6000 限制
314
314
  vi.mocked(execOutput).mockReturnValue(longDiff);
315
315
 
316
316
  const mockFetch = vi.mocked(fetch);
@@ -343,6 +343,7 @@ describe("AI Service 模块测试", () => {
343
343
  aiCommit: {
344
344
  ...mockConfig.aiCommit!,
345
345
  language: "en-US" as const,
346
+ detailedDescription: false, // 使用简洁模式测试语言
346
347
  },
347
348
  };
348
349
 
@@ -437,6 +438,240 @@ describe("AI Service 模块测试", () => {
437
438
 
438
439
  expect(body.max_tokens).toBe(500);
439
440
  });
441
+
442
+ it("默认应该启用详细描述模式", async () => {
443
+ const defaultConfig = {
444
+ ...mockConfig,
445
+ aiCommit: {
446
+ ...mockConfig.aiCommit!,
447
+ // 不设置 detailedDescription 和 maxTokens,测试默认行为
448
+ },
449
+ };
450
+ // 移除 maxTokens 设置
451
+ delete defaultConfig.aiCommit!.maxTokens;
452
+
453
+ vi.mocked(execOutput).mockReturnValue("diff --git a/file.ts b/file.ts");
454
+
455
+ const mockFetch = vi.mocked(fetch);
456
+ mockFetch.mockResolvedValue({
457
+ ok: true,
458
+ json: async () => ({
459
+ choices: [
460
+ {
461
+ message: {
462
+ content: "feat(auth): 添加用户登录功能\n\n- 实现用户名密码登录接口\n- 添加登录状态验证中间件",
463
+ },
464
+ },
465
+ ],
466
+ }),
467
+ } as Response);
468
+
469
+ const result = await generateAICommitMessage(defaultConfig);
470
+
471
+ expect(result).toContain("feat(auth): 添加用户登录功能");
472
+ expect(result).toContain("- 实现用户名密码登录接口");
473
+
474
+ // 验证使用了详细描述的 prompt
475
+ const callArgs = mockFetch.mock.calls[0][1] as RequestInit;
476
+ const body = JSON.parse(callArgs.body as string);
477
+ const prompt = body.messages[0].content;
478
+
479
+ expect(prompt).toContain("详细描述:列出主要修改点");
480
+ expect(body.max_tokens).toBe(400); // 详细模式的 token 数
481
+ });
482
+
483
+ it("详细描述模式应该生成包含修改点的 commit message", async () => {
484
+ const detailedConfig = {
485
+ ...mockConfig,
486
+ aiCommit: {
487
+ ...mockConfig.aiCommit!,
488
+ detailedDescription: true,
489
+ },
490
+ };
491
+
492
+ vi.mocked(execOutput).mockReturnValue("diff --git a/file.ts b/file.ts");
493
+
494
+ const mockFetch = vi.mocked(fetch);
495
+ mockFetch.mockResolvedValue({
496
+ ok: true,
497
+ json: async () => ({
498
+ choices: [
499
+ {
500
+ message: {
501
+ content: "feat(auth): 添加用户登录功能\n\n- 实现用户名密码登录接口\n- 添加登录状态验证中间件\n- 完善登录错误处理逻辑",
502
+ },
503
+ },
504
+ ],
505
+ }),
506
+ } as Response);
507
+
508
+ const result = await generateAICommitMessage(detailedConfig);
509
+
510
+ expect(result).toContain("feat(auth): 添加用户登录功能");
511
+ expect(result).toContain("- 实现用户名密码登录接口");
512
+ expect(result).toContain("- 添加登录状态验证中间件");
513
+ expect(result).toContain("- 完善登录错误处理逻辑");
514
+
515
+ // 验证 prompt 包含详细描述的指令
516
+ const callArgs = mockFetch.mock.calls[0][1] as RequestInit;
517
+ const body = JSON.parse(callArgs.body as string);
518
+ const prompt = body.messages[0].content;
519
+
520
+ expect(prompt).toContain("详细描述:列出主要修改点");
521
+ expect(prompt).toContain("以 \"- \" 开头");
522
+ });
523
+
524
+ it("详细描述模式应该使用更大的 maxTokens", async () => {
525
+ const detailedConfig = {
526
+ ...mockConfig,
527
+ aiCommit: {
528
+ ...mockConfig.aiCommit!,
529
+ // 不设置 detailedDescription 和 maxTokens,使用默认值
530
+ },
531
+ };
532
+ // 移除 maxTokens 设置
533
+ delete detailedConfig.aiCommit!.maxTokens;
534
+
535
+ vi.mocked(execOutput).mockReturnValue("diff --git a/file.ts b/file.ts");
536
+
537
+ const mockFetch = vi.mocked(fetch);
538
+ mockFetch.mockResolvedValue({
539
+ ok: true,
540
+ json: async () => ({
541
+ choices: [
542
+ {
543
+ message: {
544
+ content: "feat: add feature\n\n- change 1\n- change 2",
545
+ },
546
+ },
547
+ ],
548
+ }),
549
+ } as Response);
550
+
551
+ await generateAICommitMessage(detailedConfig);
552
+
553
+ const callArgs = mockFetch.mock.calls[0][1] as RequestInit;
554
+ const body = JSON.parse(callArgs.body as string);
555
+
556
+ // 默认启用详细描述模式,应该使用 400 tokens
557
+ expect(body.max_tokens).toBe(400);
558
+ });
559
+
560
+ it("详细描述模式应该允许更长的 diff", async () => {
561
+ const detailedConfig = {
562
+ ...mockConfig,
563
+ aiCommit: {
564
+ ...mockConfig.aiCommit!,
565
+ // 不设置 detailedDescription,使用默认值 true
566
+ },
567
+ };
568
+
569
+ const longDiff = "a".repeat(5500); // 超过简洁模式的 4000 限制,但在详细模式的 6000 限制内
570
+ vi.mocked(execOutput).mockReturnValue(longDiff);
571
+
572
+ const mockFetch = vi.mocked(fetch);
573
+ mockFetch.mockResolvedValue({
574
+ ok: true,
575
+ json: async () => ({
576
+ choices: [
577
+ {
578
+ message: {
579
+ content: "feat: update",
580
+ },
581
+ },
582
+ ],
583
+ }),
584
+ } as Response);
585
+
586
+ await generateAICommitMessage(detailedConfig);
587
+
588
+ const callArgs = mockFetch.mock.calls[0][1] as RequestInit;
589
+ const body = JSON.parse(callArgs.body as string);
590
+ const prompt = body.messages[0].content;
591
+
592
+ // 在详细模式下,5500 字符的 diff 不应该被截断
593
+ expect(prompt).toContain(longDiff);
594
+ expect(prompt).not.toContain("...");
595
+ });
596
+
597
+ it("简洁模式应该生成简短的 commit message", async () => {
598
+ const simpleConfig = {
599
+ ...mockConfig,
600
+ aiCommit: {
601
+ ...mockConfig.aiCommit!,
602
+ detailedDescription: false,
603
+ },
604
+ };
605
+
606
+ vi.mocked(execOutput).mockReturnValue("diff --git a/file.ts b/file.ts");
607
+
608
+ const mockFetch = vi.mocked(fetch);
609
+ mockFetch.mockResolvedValue({
610
+ ok: true,
611
+ json: async () => ({
612
+ choices: [
613
+ {
614
+ message: {
615
+ content: "feat(auth): 添加用户登录功能",
616
+ },
617
+ },
618
+ ],
619
+ }),
620
+ } as Response);
621
+
622
+ const result = await generateAICommitMessage(simpleConfig);
623
+
624
+ expect(result).toBe("feat(auth): 添加用户登录功能");
625
+
626
+ // 验证 prompt 不包含详细描述的指令
627
+ const callArgs = mockFetch.mock.calls[0][1] as RequestInit;
628
+ const body = JSON.parse(callArgs.body as string);
629
+ const prompt = body.messages[0].content;
630
+
631
+ expect(prompt).not.toContain("详细描述:列出主要修改点");
632
+ expect(prompt).toContain("只返回一条 commit message");
633
+ });
634
+
635
+ it("英文详细描述模式应该使用英文指令", async () => {
636
+ const enDetailedConfig = {
637
+ ...mockConfig,
638
+ aiCommit: {
639
+ ...mockConfig.aiCommit!,
640
+ language: "en-US" as const,
641
+ detailedDescription: true,
642
+ },
643
+ };
644
+
645
+ vi.mocked(execOutput).mockReturnValue("diff --git a/file.ts b/file.ts");
646
+
647
+ const mockFetch = vi.mocked(fetch);
648
+ mockFetch.mockResolvedValue({
649
+ ok: true,
650
+ json: async () => ({
651
+ choices: [
652
+ {
653
+ message: {
654
+ content: "feat(auth): add user login functionality\n\n- Implement username/password login API\n- Add login status validation middleware",
655
+ },
656
+ },
657
+ ],
658
+ }),
659
+ } as Response);
660
+
661
+ const result = await generateAICommitMessage(enDetailedConfig);
662
+
663
+ expect(result).toContain("feat(auth): add user login functionality");
664
+ expect(result).toContain("- Implement username/password login API");
665
+
666
+ // 验证 prompt 使用英文指令
667
+ const callArgs = mockFetch.mock.calls[0][1] as RequestInit;
668
+ const body = JSON.parse(callArgs.body as string);
669
+ const prompt = body.messages[0].content;
670
+
671
+ expect(prompt).toContain("Detailed description: List main changes");
672
+ expect(prompt).toContain("starting with \"- \"");
673
+ expect(prompt).not.toContain("详细描述");
674
+ });
440
675
  });
441
676
 
442
677
  describe("Ollama 特殊情况", () => {