Skip to content

Commit

Permalink
🐛 fix copyright info when has not owner set
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed Oct 28, 2020
1 parent 67f91f7 commit 0bcb9c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
18 changes: 8 additions & 10 deletions pkg/plugin/v2/scaffolds/internal/templates/boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type Boilerplate struct {
// Owner is the copyright owner - e.g. "The Kubernetes Authors"
Owner string

// Year is the copyright year
Year string
// Copyright is copyright info used in the templates
Copyright string
}

// SetTemplateDefaults implements input.Template
Expand All @@ -47,8 +47,10 @@ func (f *Boilerplate) SetTemplateDefaults() error {
f.Path = filepath.Join("hack", "boilerplate.go.txt")
}

if f.Year == "" {
f.Year = fmt.Sprintf("%v", time.Now().Year())
if f.Owner != "" {
f.Copyright = fmt.Sprintf("Copyright %v %v.", time.Now().Year(), f.Owner)
} else {
f.Copyright = fmt.Sprintf("Copyright %v.", time.Now().Year())
}

// Boilerplate given
Expand All @@ -69,9 +71,7 @@ func (f *Boilerplate) SetTemplateDefaults() error {
}

const apache = `/*
{{ if .Owner -}}
Copyright {{ .Year }} {{ .Owner }}.
{{- end }}
{{ .Copyright }}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -87,7 +87,5 @@ limitations under the License.
*/`

const none = `/*
{{ if .Owner -}}
Copyright {{ .Year }} {{ .Owner }}.
{{- end }}
{{ .Copyright }}
*/`
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type Boilerplate struct {
// Owner is the copyright owner - e.g. "The Kubernetes Authors"
Owner string

// Year is the copyright year
Year string
// Copyright is copyright info used in the templates
Copyright string
}

// SetTemplateDefaults implements input.Template
Expand All @@ -47,8 +47,10 @@ func (f *Boilerplate) SetTemplateDefaults() error {
f.Path = filepath.Join("hack", "boilerplate.go.txt")
}

if f.Year == "" {
f.Year = fmt.Sprintf("%v", time.Now().Year())
if f.Owner != "" {
f.Copyright = fmt.Sprintf("Copyright %v %v.", time.Now().Year(), f.Owner)
} else {
f.Copyright = fmt.Sprintf("Copyright %v.", time.Now().Year())
}

// Boilerplate given
Expand All @@ -69,9 +71,7 @@ func (f *Boilerplate) SetTemplateDefaults() error {
}

const apache = `/*
{{ if .Owner -}}
Copyright {{ .Year }} {{ .Owner }}.
{{- end }}
{{ .Copyright }}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -87,7 +87,5 @@ limitations under the License.
*/`

const none = `/*
{{ if .Owner -}}
Copyright {{ .Year }} {{ .Owner }}.
{{- end }}
{{ .Copyright }}
*/`

0 comments on commit 0bcb9c8

Please sign in to comment.