How No-Mistakes Detects Non-Conforming PR Titles Using Conventional Commit Validation
No-mistakes uses a regex-based validator in internal/conventional/title.go to check PR titles against the conventional commit specification, automatically rewriting invalid titles via TightenTitle before submission.
The no-mistakes repository enforces strict conventional commit standards on every pull request it generates. Through a dedicated validation package, the tool detects non-conforming PR titles and automatically reformats them to meet the type(scope)?: description pattern. This ensures that all agent-generated commits follow standardized semantic versioning conventions without manual intervention.
The Core Validation Logic in internal/conventional/title.go
The validation engine resides in internal/conventional/title.go, where a compiled regular expression (titleRe) defines the canonical conventional commit structure. This regex captures the mandatory type, optional scope, and description components.
A hardcoded map named validTypes enumerates the eleven acceptable commit types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, and revert. Any title must match the regex pattern and contain a type present in this map to pass validation.
The exported function IsTitle performs this dual-check: it executes the regex match and verifies the captured type exists in validTypes. If either condition fails, the function returns false, flagging the title as non-conforming.
Direct Validation Example
import "github.com/kunchenguid/no-mistakes/internal/conventional"
func checkTitle(t string) bool {
return conventional.IsTitle(t) // true only for a valid conventional title
}
Automatic Correction via TightenTitle
When IsTitle returns false, the pipeline invokes TightenTitle to salvage non-conforming titles rather than rejecting them outright. This function first trims whitespace, then applies the same regex validation used by IsTitle.
If the title fails validation, TightenTitle falls back to inferType, a heuristic analyzer that scans the raw text for semantic keywords. For example, titles containing "add" or "fix" map to feat or fix respectively, while documentation terms trigger docs. The function then prefixes the original description with the inferred type, producing a valid conventional commit title.
Tightening Example
title := "Update README"
tightTitle := conventional.TightenTitle(title)
// tightTitle == "docs: Update README"
PR Pipeline Integration
The enforcement mechanism activates in internal/pipeline/steps/pr.go, which orchestrates the pull request creation process. Before submitting to the SCM provider, the step processes the agent-generated title through the conventional commit validator.
The code stores the original title, invokes TightenTitle, and compares the results. When modification occurs, the pipeline logs the transformation via structured logging:
content.Title = strings.TrimSpace(content.Title)
originalTitle := content.Title
content.Title = conventional.TightenTitle(content.Title)
if content.Title != originalTitle {
slog.Warn("tightened agent PR title type",
"from", originalTitle, "to", content.Title)
}
This integration ensures that every PR title emitted by the no-mistakes agent conforms to conventional commit standards, effectively detecting and repairing non-conforming titles before they reach the repository.
Summary
- Regex-based detection: The
titleReregular expression ininternal/conventional/title.govalidates the structural patterntype(scope)?: description. - Type enumeration: The
validTypesmap restricts commits to eleven semantic categories includingfeat,fix, anddocs. - Boolean validation: The
IsTitlefunction returnstrueonly for titles matching both the regex and allowed type list. - Automatic repair: The
TightenTitlefunction rewrites invalid titles by inferring the correct type from content keywords. - Pipeline enforcement:
internal/pipeline/steps/pr.gomandates validation on every PR, logging any automatic corrections for audit trails.
Frequently Asked Questions
What conventional commit types does no-mistakes support?
The validator recognizes eleven specific types defined in the validTypes map: feat, fix, docs, style, refactor, perf, test, build, ci, chore, and revert. Any title using a type outside this list is flagged as non-conforming.
How does no-mistakes handle PR titles that don't match the conventional format?
Rather than rejecting invalid titles, the system passes them through TightenTitle, which attempts to infer the appropriate type from keywords in the text. It then reconstructs the title with the proper prefix, ensuring compliance without manual rewriting.
Where is the validation logic located in the source code?
The core validation resides in internal/conventional/title.go, which exports IsTitle and TightenTitle. The PR pipeline integration that enforces these checks lives in internal/pipeline/steps/pr.go.
Can the validation detect missing scopes or breaking change indicators?
The titleRe regex captures optional scopes and supports the exclamation mark syntax for breaking changes. However, the primary validation focuses on ensuring the type is valid and the basic structure matches the type(scope)?: description pattern.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →