Add bootstrap option to set a prefix for the commit messages

Signed-off-by: Dries Verachtert <dries.verachtert@dries.eu>
pull/1350/head
Dries Verachtert 4 years ago
parent bd34870334
commit 9cebd601fb

@ -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())

@ -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),

@ -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),

@ -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),

@ -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

@ -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

@ -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

@ -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
}

@ -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)
}

Loading…
Cancel
Save