Skip to content

peterfei/ai-agent-team / .claude/skills/changelog-generator

changelog-generator

Verified

智能变更日志生成器 - 自动分析Git提交历史,生成符合规范的CHANGELOG.md。支持语义化版本管理、多种输出格式、增量更新和GitHub/GitLab集成。

tests/unit/CommitClassifier.test.js

View on GitHub
const CommitClassifier = require('../../src/core/CommitClassifier');

describe('CommitClassifier', () => {
  let classifier;
  let config;

  beforeEach(() => {
    config = {
      types: [
        { type: 'feat', section: 'Features', emoji: '✨', priority: 1 },
        { type: 'fix', section: 'Bug Fixes', emoji: '🐛', priority: 2 },
        { type: 'docs', section: 'Documentation', emoji: '📝', priority: 3 },
        { type: 'chore', section: 'Chores', emoji: '🔧', priority: 4, hidden: true }
      ],
      exclude: {
        types: [],
        scopes: []
      }
    };
    classifier = new CommitClassifier(config);
  });

  describe('classify', () => {
    test('should classify commits by type', () => {
      const commits = [
        { type: 'feat', subject: 'Add feature 1', author: 'Alice', isBreaking: false },
        { type: 'feat', subject: 'Add feature 2', author: 'Bob', isBreaking: false },
        { type: 'fix', subject: 'Fix bug', author: 'Charlie', isBreaking: false }
      ];

      const result = classifier.classify(commits);

      expect(result.changes).toHaveLength(2); // feat and fix
      expect(result.changes[0].type).toBe('feat');
      expect(result.changes[0].commits).toHaveLength(2);
      expect(result.changes[1].type).toBe('fix');
      expect(result.changes[1].commits).toHaveLength(1);
    });

    test('should separate breaking changes', () => {
      const commits = [
        { type: 'feat', subject: 'Add feature', author: 'Alice', isBreaking: false, breaking: [] },
        { type: 'feat', subject: 'Breaking change', author: 'Bob', isBreaking: true, breaking: [{ text: 'API changed' }] }
      ];

      const result = classifier.classify(commits);

      expect(result.breaking).toHaveLength(1);
      expect(result.breaking[0].subject).toBe('Breaking change');
      expect(result.changes[0].commits).toHaveLength(1); // Only non-breaking feat
    });

    test('should exclude hidden types', () => {
      const commits = [
        { type: 'feat', subject: 'Add feature', author: 'Alice', isBreaking: false },
        { type: 'chore', subject: 'Update deps', author: 'Bob', isBreaking: false }
      ];

      const result = classifier.classify(commits);

      expect(result.changes).toHaveLength(1);
      expect(result.changes[0].type).toBe('feat');
    });

    test('should generate correct statistics', () => {
      const commits = [
        { type: 'feat', subject: 'Feature 1', author: 'Alice', isBreaking: false },
        { type: 'feat', subject: 'Feature 2', author: 'Bob', isBreaking: true, breaking: [{}] },
        { type: 'fix', subject: 'Fix', author: 'Alice', isBreaking: false },
        { type: 'chore', subject: 'Chore', author: 'Charlie', isBreaking: false }
      ];

      const result = classifier.classify(commits);

      expect(result.stats.total).toBe(4);
      expect(result.stats.included).toBe(3); // chore is hidden
      expect(result.stats.breaking).toBe(1);
      expect(result.stats.authors).toHaveLength(2); // Only Alice and Bob (chore is excluded)
      expect(result.stats.authors).toContain('Alice');
      expect(result.stats.authors).toContain('Bob');
    });
  });

  describe('shouldInclude', () => {
    test('should include normal commits', () => {
      const commit = { type: 'feat', scope: 'api' };
      expect(classifier.shouldInclude(commit)).toBe(true);
    });

    test('should exclude types in exclude list', () => {
      classifier.excludeTypes = ['chore'];
      const commit = { type: 'chore', scope: null };
      expect(classifier.shouldInclude(commit)).toBe(false);
    });

    test('should exclude scopes in exclude list', () => {
      classifier.excludeScopes = ['deps'];
      const commit = { type: 'feat', scope: 'deps' };
      expect(classifier.shouldInclude(commit)).toBe(false);
    });

    test('should exclude hidden types from config', () => {
      const commit = { type: 'chore', scope: null };
      expect(classifier.shouldInclude(commit)).toBe(false);
    });
  });

  describe('groupByType', () => {
    test('should group commits by type', () => {
      const commits = [
        { type: 'feat', subject: 'Feature 1' },
        { type: 'feat', subject: 'Feature 2' },
        { type: 'fix', subject: 'Fix' }
      ];

      const result = classifier.groupByType(commits);

      expect(result.feat).toHaveLength(2);
      expect(result.fix).toHaveLength(1);
    });

    test('should handle commits without type', () => {
      const commits = [
        { type: null, subject: 'No type' }
      ];

      const result = classifier.groupByType(commits);

      expect(result.other).toHaveLength(1);
    });
  });

  describe('groupByScope', () => {
    test('should group commits by scope', () => {
      const commits = [
        { scope: 'auth', subject: 'Auth feature' },
        { scope: 'auth', subject: 'Auth fix' },
        { scope: 'api', subject: 'API feature' }
      ];

      const result = classifier.groupByScope(commits);

      expect(result.auth).toHaveLength(2);
      expect(result.api).toHaveLength(1);
    });

    test('should use "general" for commits without scope', () => {
      const commits = [
        { scope: null, subject: 'No scope' }
      ];

      const result = classifier.groupByScope(commits);

      expect(result.general).toHaveLength(1);
    });
  });

  describe('validateCommit', () => {
    test('should validate correct commit', () => {
      const commit = {
        type: 'feat',
        subject: 'Add new feature'
      };

      const result = classifier.validateCommit(commit);

      expect(result.valid).toBe(true);
      expect(result.errors).toHaveLength(0);
    });

    test('should fail without subject', () => {
      const commit = {
        type: 'feat',
        subject: ''
      };

      const result = classifier.validateCommit(commit);

      expect(result.valid).toBe(false);
      expect(result.errors).toHaveLength(1);
    });

    test('should warn for unknown type', () => {
      const commit = {
        type: 'unknown',
        subject: 'Some change'
      };

      const result = classifier.validateCommit(commit);

      expect(result.warnings).toHaveLength(1);
    });

    test('should warn for long subject', () => {
      const commit = {
        type: 'feat',
        subject: 'A'.repeat(150)
      };

      const result = classifier.validateCommit(commit);

      expect(result.warnings.length).toBeGreaterThan(0);
    });
  });
});
rea-changelog-updatemorluto/reaPrepare or rewrite REA release changelogs and GitHub release notes from pinned Git history, with verified contributor thanks and Release Please synchronization.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
academy-guideanthropics/skillsStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
claude-apianthropics/skillsReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).Stars: 198kUpdated Claude CodeCodexUnverifiedInstall
doc-coauthoringanthropics/skillsGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.Stars: 198kUpdated Claude CodeCodexVerifiedInstall