Kiểm tra commit message & changelog API

Kiểm tra commit message theo Conventional Commits, tạo CHANGELOG từ git log và tính version kế tiếp theo semver, kèm gợi ý sửa.

GETPOSThttps://apibox.io.vn/v1/commit-lint
Tiện ích lập trình▶ Dùng thử online

Một endpoint, ba chế độ. lint kiểm tra một message, danh sách commits hoặc nội dung git log dán vào theo Conventional Commits 1.0.0 với bộ quy tắc phổ biến config-conventional (danh sách type và chữ thường, scope, chữ đầu và dấu chấm cuối subject, độ dài header / dòng body, dòng trống, footer BREAKING CHANGE) hoặc preset angular chặt hơn; tuỳ chỉnh bằng types, scopes, header_max, require_scope. Commit merge, revert, fixup được bỏ qua. Mỗi message sai có suggestion đã sửa (đổi từ đồng nghĩa như feature → feat, quá khứ → mệnh lệnh).

changelog nhóm commit thành BREAKING CHANGES, Features, Bug Fixes, Performance, Reverts (all_types=1 thêm docs, refactor, CI…), gắn link issue và commit khi có repo_url (GitHub hoặc GitLab), tiêu đề nhóm tiếng Anh hoặc tiếng Việt (lang=vi). bump trả version kế tiếp từ current_version (breaking → major, feat → minor, fix / perf → patch; bản 0.x chỉ tăng minor khi có breaking trừ khi pre_major=0; prerelease=beta cho bản thử nghiệm).

Định dạng log nhận được: git log mặc định, git log --oneline hoặc các message ngăn bằng ---. Không chạy file cấu hình nào: mọi thiết lập truyền qua tham số. Dùng trong pipeline GitLab / Bitbucket / Gitea, bot chat hay script release mà không cần cài công cụ Node.

Markdown · OpenAPI · Postman · llms.txt

Tham số

TênVị tríKiểuBắt buộcMặc định
actionbody|querystringkhônglintlint, changelog hoặc bump (hoặc theo đường dẫn /v1/commit-lint/changelog; tên khác mode).
messagebody|querystringkhôngMột commit message (header, body, footer).
commitsbodyarraykhôngDanh sách message dạng chuỗi hoặc {hash, message} (tối đa 2000).
logbodystringkhôngKết quả git log / git log --oneline dán vào.
presetbody|querystringkhôngconventionalconventional (config-conventional) hoặc angular.
typesbody|querystringkhôngDanh sách type cho phép, cách nhau dấu phẩy (thay danh sách của preset).
scopesbody|querystringkhôngDanh sách scope cho phép.
header_maxbody|querynumberkhông100Độ dài header tối đa (angular: 72).
require_scopebody|querybooleankhôngBắt buộc có scope.
current_versionbody|querystringkhôngVersion hiện tại cho bump / changelog, ví dụ 1.4.2 hoặc v1.4.2.
prereleasebody|querystringkhôngNhãn pre-release, ví dụ beta.
repo_urlbody|querystringkhônghttps://github.com/owner/repo (hoặc GitLab) để tạo link issue / commit / so sánh.
versionbody|querystringkhôngTiêu đề version của changelog (mặc định: version kế tiếp tính được hoặc "Unreleased").
langbody|querystringkhôngenTiêu đề nhóm en hoặc vi.
all_typesbody|querybooleankhôngKèm nhóm docs / refactor / test / build / CI / chore.

Ví dụ

curl -X POST "https://apibox.io.vn/v1/commit-lint" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message":"Fixed login redirect."}'

Kết quả trả về

{
  "valid": false,
  "commits": 1,
  "invalid": 1,
  "ignored": 0,
  "config": {
    "preset": "conventional",
    "types": [
      "build",
      "chore",
      "ci",
      "docs",
      "feat",
      "fix",
      "perf",
      "refactor",
      "revert",
      "style",
      "test"
    ],
    "scopes": null,
    "header_max": 100
  },
  "results": [
    {
      "header": "Fixed login redirect.",
      "valid": false,
      "parsed": {
        "type": null,
        "scope": null,
        "subject": null,
        "breaking": false
      },
      "issues": [
        {
          "rule": "type-empty",
          "severity": "error",
          "message": "No type: the header must start with a type such as feat, fix, docs (\"type(scope): subject\")"
        },
        {
          "rule": "subject-empty",
          "severity": "error",
          "message": "No subject after \"type: \""
        }
      ],
      "suggestion": "fix: login redirect"
    }
  ],
  "spec": "https://www.conventionalcommits.org/en/v1.0.0/"
}

Ứng dụng

  • Chặn commit message sai chuẩn trong pipeline GitLab, Bitbucket
  • Tạo release note từ các commit kể từ tag trước
  • Tính version semver kế tiếp trong script deploy
  • Gợi ý message đã sửa cho người đóng góp trong bot review

Hỏi đáp

Áp dụng những quy tắc nào?

Bộ quy tắc của @commitlint/config-conventional (type, scope, subject, độ dài header và body, dòng trống) viết lại phía server, hoặc preset angular; có thể tuỳ chỉnh type, scope và độ dài.

Version kế tiếp được tính thế nào?

Có breaking change (! hoặc footer BREAKING CHANGE) → major, có feat → minor, fix / perf / revert → patch, còn lại không phát hành. Bản dưới 1.0.0 mặc định chỉ tăng minor khi có breaking.

Có đọc được repo của tôi không?

Không: hãy dán kết quả git log (hoặc gửi các message). Không lưu gì.

API liên quan

Bắt đầu với 1.000 request miễn phí mỗi tháng. Nhận API key miễn phí →