diff --git a/cmd/flux/bootstrap.go b/cmd/flux/bootstrap.go index 1c1dc1c2..7909b824 100644 --- a/cmd/flux/bootstrap.go +++ b/cmd/flux/bootstrap.go @@ -67,6 +67,7 @@ type bootstrapFlags struct { authorName string authorEmail string + commitMessagePrefix string commitMessageAppendix string } @@ -118,6 +119,7 @@ func init() { bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.authorName, "author-name", "Flux", "author name for Git commits") bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.authorEmail, "author-email", "", "author email for Git commits") + bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.commitMessagePrefix, "commit-message-prefix", "", "string to prepend to the commit messages, e.g. 'ci skip:'") bootstrapCmd.PersistentFlags().StringVar(&bootstrapArgs.commitMessageAppendix, "commit-message-appendix", "", "string to add to the commit messages, e.g. '[ci skip]'") bootstrapCmd.PersistentFlags().Var(&bootstrapArgs.arch, "arch", bootstrapArgs.arch.Description()) diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index 536fa7de..1d98188d 100644 --- a/cmd/flux/bootstrap_git.go +++ b/cmd/flux/bootstrap_git.go @@ -204,6 +204,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithRepositoryURL(gitArgs.url), bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), + bootstrap.WithCommitMessagePrefix(bootstrapArgs.commitMessagePrefix), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithKubeconfig(rootArgs.kubeconfig, rootArgs.kubecontext), bootstrap.WithPostGenerateSecretFunc(promptPublicKey), diff --git a/cmd/flux/bootstrap_github.go b/cmd/flux/bootstrap_github.go index 065a9fb6..bb9ab11a 100644 --- a/cmd/flux/bootstrap_github.go +++ b/cmd/flux/bootstrap_github.go @@ -222,6 +222,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithBootstrapTransportType("https"), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), + bootstrap.WithCommitMessagePrefix(bootstrapArgs.commitMessagePrefix), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithProviderTeamPermissions(mapTeamSlice(githubArgs.teams, ghDefaultPermission)), bootstrap.WithReadWriteKeyPermissions(githubArgs.readWriteKey), diff --git a/cmd/flux/bootstrap_gitlab.go b/cmd/flux/bootstrap_gitlab.go index a00bbd66..56643a08 100644 --- a/cmd/flux/bootstrap_gitlab.go +++ b/cmd/flux/bootstrap_gitlab.go @@ -238,6 +238,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithBootstrapTransportType("https"), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), + bootstrap.WithCommitMessagePrefix(bootstrapArgs.commitMessagePrefix), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithProviderTeamPermissions(mapTeamSlice(gitlabArgs.teams, glDefaultPermission)), bootstrap.WithReadWriteKeyPermissions(gitlabArgs.readWriteKey), diff --git a/docs/cmd/flux_bootstrap.md b/docs/cmd/flux_bootstrap.md index 9f1adb8b..4bc0dbeb 100644 --- a/docs/cmd/flux_bootstrap.md +++ b/docs/cmd/flux_bootstrap.md @@ -17,6 +17,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git --branch string Git branch (default "main") --ca-file string path to TLS CA file used for validating self-signed certificates --cluster-domain string internal cluster domain (default "cluster.local") + --commit-message-prefix string string to prepend to the commit messages, e.g. 'ci skip:' --commit-message-appendix string string to add to the commit messages, e.g. '[ci skip]' --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components-extra strings list of components in addition to those supplied or defaulted, accepts comma-separated values diff --git a/docs/cmd/flux_bootstrap_git.md b/docs/cmd/flux_bootstrap_git.md index 70e8628d..4b2d335e 100644 --- a/docs/cmd/flux_bootstrap_git.md +++ b/docs/cmd/flux_bootstrap_git.md @@ -52,6 +52,7 @@ flux bootstrap git [flags] --branch string Git branch (default "main") --ca-file string path to TLS CA file used for validating self-signed certificates --cluster-domain string internal cluster domain (default "cluster.local") + --commit-message-prefix string string to prepend to the commit messages, e.g. 'ci skip:' --commit-message-appendix string string to add to the commit messages, e.g. '[ci skip]' --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components-extra strings list of components in addition to those supplied or defaulted, accepts comma-separated values diff --git a/docs/cmd/flux_bootstrap_gitlab.md b/docs/cmd/flux_bootstrap_gitlab.md index f2c114df..6090c795 100644 --- a/docs/cmd/flux_bootstrap_gitlab.md +++ b/docs/cmd/flux_bootstrap_gitlab.md @@ -66,6 +66,7 @@ flux bootstrap gitlab [flags] --branch string Git branch (default "main") --ca-file string path to TLS CA file used for validating self-signed certificates --cluster-domain string internal cluster domain (default "cluster.local") + --commit-message-prefix string string to prepend to the commit messages, e.g. 'ci skip:' --commit-message-appendix string string to add to the commit messages, e.g. '[ci skip]' --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --components-extra strings list of components in addition to those supplied or defaulted, accepts comma-separated values diff --git a/internal/bootstrap/bootstrap_plain_git.go b/internal/bootstrap/bootstrap_plain_git.go index c932375d..adec4f30 100644 --- a/internal/bootstrap/bootstrap_plain_git.go +++ b/internal/bootstrap/bootstrap_plain_git.go @@ -51,6 +51,7 @@ type PlainGitBootstrapper struct { branch string author git.Author + commitMessagePrefix string commitMessageAppendix string kubeconfig string @@ -133,6 +134,9 @@ func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifest // Git commit generated commitMsg := fmt.Sprintf("Add Flux %s component manifests", options.Version) + if b.commitMessagePrefix != "" { + commitMsg = b.commitMessagePrefix + commitMsg + } if b.commitMessageAppendix != "" { commitMsg = commitMsg + "\n\n" + b.commitMessageAppendix } @@ -297,6 +301,9 @@ func (b *PlainGitBootstrapper) ReconcileSyncConfig(ctx context.Context, options // Git commit generated commitMsg := fmt.Sprintf("Add Flux sync manifests") + if b.commitMessagePrefix != "" { + commitMsg = b.commitMessagePrefix + commitMsg + } if b.commitMessageAppendix != "" { commitMsg = commitMsg + "\n\n" + b.commitMessageAppendix } diff --git a/internal/bootstrap/options.go b/internal/bootstrap/options.go index 88972c1e..337b7e32 100644 --- a/internal/bootstrap/options.go +++ b/internal/bootstrap/options.go @@ -62,6 +62,20 @@ func (o authorOption) applyGitProvider(b *GitProviderBootstrapper) { o.applyGit(b.PlainGitBootstrapper) } +func WithCommitMessagePrefix(prefix string) Option { + return commitMessagePrefixOption(prefix) +} + +type commitMessagePrefixOption string + +func (o commitMessagePrefixOption) applyGit(b *PlainGitBootstrapper) { + b.commitMessagePrefix = string(o) +} + +func (o commitMessagePrefixOption) applyGitProvider(b *GitProviderBootstrapper) { + o.applyGit(b.PlainGitBootstrapper) +} + func WithCommitMessageAppendix(appendix string) Option { return commitMessageAppendixOption(appendix) }