Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change the license header to a string #116

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .conform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ policies:
spec:
includeSuffixes:
- .go
headerFile: LICENSE_HEADER
header: |
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
3 changes: 0 additions & 3 deletions LICENSE_HEADER

This file was deleted.

14 changes: 6 additions & 8 deletions internal/policy/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,19 @@ type License struct {
// ExcludeSuffixes is the Suffixes used to find files that the license policy
// should not be applied to.
ExcludeSuffixes []string `mapstructure:"excludeSuffixes"`
// LicenseHeaderFile is the path to the license header file.
LicenseHeaderFile string `mapstructure:"headerFile"`
// Header is the contents of the license header.
Header string `mapstructure:"header"`
}

// Compliance implements the policy.Policy.Compliance function.
func (l *License) Compliance(options *policy.Options) (report policy.Report) {
var err error

report = policy.Report{}

var value []byte
if value, err = ioutil.ReadFile(l.LicenseHeaderFile); err != nil {
report.Errors = append(report.Errors, errors.Errorf("Failed to open %s", l.LicenseHeaderFile))
if l.Header == "" {
report.Errors = append(report.Errors, errors.New("Header is not defined"))
return report
}

err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand All @@ -58,7 +56,7 @@ func (l *License) Compliance(options *policy.Options) (report policy.Report) {
report.Errors = append(report.Errors, errors.Errorf("Failed to open %s", path))
return nil
}
ValidateLicenseHeader(&report, info.Name(), contents, value)
ValidateLicenseHeader(&report, info.Name(), contents, []byte(l.Header))
}
}
}
Expand Down