SuperAPI AI 工具集

conventional-commit

编程与开发

查看项目

更新于 10-14 05:33

技能介绍

用途

这是一个面向 AI 智能体的技能,用于在提交代码变更、编写提交信息或整理 Git 历史时,按照 Conventional Commits 约定生成规范的提交信息。

主要能力与约定

前置要求

提交前需确认当前工作在特性分支,而不是主分支。可执行:

查看当前分支

git branch --show-current

如果处于 main 或 master,需先创建新分支:

创建并切换到新分支

git checkout -b <type>/<short-description>

分支命名遵循 <type>/<short-description>,其中 type 与提交类型一致,例如 feat/add-user-auth、fix/null-pointer-error、refactor/extract-validation。

提交格式

<type>(<scope>): <subject>

<body>

<footer>

头部为必填,scope 可选,所有行需保持在 100 字符以内。

提交类型

  • build:构建系统或 CI 变更
  • chore:常规维护任务
  • ci:持续集成配置
  • deps:依赖更新
  • docs:文档变更
  • feat:新功能
  • fix:缺陷修复
  • perf:性能改进
  • refactor:代码重构(不改变行为)
  • revert:回滚之前的提交
  • style:代码风格与格式
  • test:新增、更新或改进测试

主题行规则

  • 使用祈使、现在时,例如 "add feature" 而非 "added feature"
  • 首字母不大写
  • 结尾不加句点
  • 最长 70 字符

正文指南

  • 说明 what 与 why,而不是 how
  • 使用祈使语气和现在时
  • 包含变更动机
  • 在相关时对比之前的行为

Conventional Commits 结构

提交包含以下结构元素,用于向库的使用者传达意图:

  • fix:类型为 fix 的提交修复代码库中的缺陷(对应语义化版本中的 PATCH)
  • feat:类型为 feat 的提交向代码库引入新功能(对应语义化版本中的 MINOR)
  • BREAKING CHANGE:带有页脚 BREAKING CHANGE: 的提交,或在类型/范围后追加 ! 的提交,引入破坏性的 API 变更(对应语义化版本中的 MAJOR)。BREAKING CHANGE 可以是任意类型的提交的一部分
  • 除 fix: 和 feat: 外的其他类型也被允许,例如 @commitlint/config-conventional(基于 Angular 约定)推荐 build:、chore:、ci:、docs:、style:、refactor:、perf:、test: 等
  • 除 BREAKING CHANGE: 之外还可提供其他页脚,遵循类似 git trailer 格式的约定

示例

简单修复

fix(api): handle null response in user endpoint

The user API could return null for deleted accounts, causing a crash in the dashboard. Add null check before accessing user properties.

带 scope 的功能

feat(alerts): add Slack thread replies for alert updates

When an alert is updated or resolved, post a reply to the original Slack thread instead of creating a new message. This keeps related notifications grouped together.

重构

refactor: extract common validation logic to shared module

Move duplicate validation code from three endpoints into a shared validator class. No behavior change.

破坏性变更

feat(api)!: remove deprecated v1 endpoints

Remove all v1 API endpoints that were deprecated in version 23.1. Clients should migrate to v2 endpoints.

BREAKING CHANGE: v1 endpoints no longer available

回滚格式

revert: feat(api): add new endpoint

This reverts commit abc123def456.

Reason: Caused performance regression in production.

原则

  • 每个提交应是单一、稳定的变更
  • 提交应可独立审查
  • 每次提交后仓库应处于可工作状态

参考

Conventional Commits Specification

限制

资料的官方文本为空,未提供安装、调用方式、平台支持、价格或效果等信息,这些内容暂未提供。