feat: add custom commit and PR templates in server config#5091
Conversation
Add support for configuring commit message and pull request templates
at the server configuration level. This allows operators to define
server-wide default templates that can be used when creating commits
and pull requests through the Flipt UI.
Templates are configured per storage backend and support:
- commit_message: Template for commit messages
- proposal_title: Template for pull request titles
- proposal_body: Template for pull request body content
Template priority (highest to lowest):
1. Repository-level templates (in flipt.yaml)
2. Server-level templates (in config.yml storage section)
3. Built-in defaults
This is useful for CI/CD integration, such as adding [skip ci]
to commit messages to prevent unnecessary pipeline triggers.
Example configuration:
storage:
default:
templates:
commit_message: "{{ (index .Changes 0) }} [skip ci]"
Fixes #5087
Signed-off-by: Mark Phelps <[email protected]>
Add TemplatesConfig.Validate() method to check that all configured templates are valid Go text/templates at config load time. This provides clear error messages at startup rather than silently falling back to defaults when a template has a syntax error. - Added Validate() method to TemplatesConfig in internal/config/storage.go - Call validation from StorageConfig.validate() during config load - Added comprehensive tests for template validation - Updated documentation in DefaultFliptConfig to clarify graceful degradation Signed-off-by: Mark Phelps <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## v2 #5091 +/- ##
==========================================
+ Coverage 60.31% 60.37% +0.05%
==========================================
Files 136 137 +1
Lines 13394 13423 +29
==========================================
+ Hits 8079 8104 +25
- Misses 4631 4634 +3
- Partials 684 685 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add the templates property to the JSON schema for storage configuration. This allows the schema validation test to pass when using the new templates configuration option. Signed-off-by: Mark Phelps <[email protected]>
Add the templates property to the Cue schema for storage configuration, matching the JSON schema update. Signed-off-by: Mark Phelps <[email protected]>
|
Documentation Updates 1 document(s) were updated by changes in this PR: flipt |
Address code review feedback: 1. Move TemplatesConfig from per-storage to root config level since templates are server-wide defaults (can still be overridden at repository level via flipt.yaml) 2. Change DefaultFliptConfig and related functions to accept value types instead of pointers, eliminating the nil parameter antipattern 3. Move TemplatesConfig to its own file (templates.go) since it's no longer related to storage configuration 4. Update JSON and Cue schemas to reflect templates at root level 5. Fix JSON tags to use camelCase convention Signed-off-by: Mark Phelps <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds support for configuring custom commit message and pull request templates at the server configuration level. These templates can be used when creating commits and pull requests through the Flipt UI, providing a flexible way to customize the format of commit messages and PR content.
Key Changes:
- Added
TemplatesConfigstruct with validation for commit messages, PR titles, and PR bodies - Extended
Configstruct to include global templates configuration - Updated
DefaultFliptConfigandGetConfigto accept and apply server-level templates - Added comprehensive tests for template validation and server-level template functionality
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/config/templates.go | New file defining TemplatesConfig struct and validation method for server-level templates |
| internal/config/templates_test.go | Comprehensive tests for template validation including valid and invalid template syntax |
| internal/config/config.go | Added Templates field to root Config struct and integrated validation |
| internal/storage/fs/config.go | Updated DefaultFliptConfig and GetConfig to accept server templates; repository templates override server templates |
| internal/storage/fs/config_test.go | Added tests for server-level templates and partial template overrides |
| internal/storage/fs/snapshot_test.go | Updated test calls to pass empty TemplatesConfig{} |
| internal/storage/fs/config_fuzz_test.go | Updated fuzz test calls to pass empty TemplatesConfig{} |
| internal/storage/environments/git/store.go | Added serverTemplates field to Environment struct and ServerTemplates() method; passed templates through GetConfig calls |
| internal/storage/environments/git/store_test.go | Updated test calls to pass empty TemplatesConfig{} to NewEnvironmentFromRepo |
| internal/storage/environments/environments.go | Passed f.cfg.Templates to NewEnvironmentFromRepo in factory |
| internal/coss/storage/environments/git/store.go | Updated to call e.ServerTemplates() when getting config |
| cmd/flipt/validate.go | Updated to pass empty TemplatesConfig{} for CLI validation without server config |
| config/local.yml | Added example configuration showing template usage (contains documentation error) |
| config/flipt.schema.json | Added JSON schema definition for root-level templates configuration |
| config/flipt.schema.cue | Added CUE schema definition for root-level templates configuration |
Comments suppressed due to low confidence (1)
internal/storage/fs/config.go:223
- Inconsistent error handling for repository-level template parsing. The commit message template returns an error on parse failure (lines 198-205), while proposal title and body templates only log warnings (lines 210, 219). This inconsistency could lead to unexpected behavior where some invalid templates cause startup failures while others are silently ignored.
Consider either:
- Making all template parsing errors return errors (recommended for early failure detection), or
- Making all template parsing errors log warnings (if you want to be lenient)
The current behavior is confusing because it's not clear why commit message templates are treated differently.
if conf.Templates.CommitMsg != "" {
tmpl, err := template.New("commitMessage").Parse(conf.Templates.CommitMsg)
if err != nil {
return nil, err
}
c.Templates.CommitMessageTemplate = tmpl
}
if conf.Templates.ProposalTitle != "" {
tmpl, err := template.New("proposalTitle").Parse(conf.Templates.ProposalTitle)
if err != nil {
logger.Warn("failed to parse template", zap.String("template", "proposalTitle"), zap.Error(err))
} else {
c.Templates.ProposalTitleTemplate = tmpl
}
}
if conf.Templates.ProposalBody != "" {
tmpl, err := template.New("proposalBody").Parse(conf.Templates.ProposalBody)
if err != nil {
logger.Warn("failed to parse template", zap.String("template", "proposalBody"), zap.Error(err))
} else {
c.Templates.ProposalBodyTemplate = tmpl
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Signed-off-by: Mark Phelps <[email protected]>
Summary
Add support for configuring custom commit message and pull request templates at the server configuration level (per storage backend). This allows operators to define server-wide default templates that can be used when creating commits and pull requests through the Flipt UI.
Changes
TemplatesConfigstruct tointernal/config/storage.gowith fields for commit messages, PR titles, and PR bodiesStorageConfigto include aTemplatesfield allowing per-storage backend configurationfs.GetConfig()to accept and apply server-level templates as defaultsserverTemplatesparameter toNewEnvironmentFromRepoand passed through the call chainconfig/local.ymlwith example template configurationBackward Compatibility
This change is fully backward compatible. All parameters are optional and the feature gracefully falls back to defaults.
Related
Fixes #5087