Skip to content

Commit

Permalink
feat: change the license header to a string (#116)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Rynhard <[email protected]>
  • Loading branch information
andrewrynhard authored Mar 4, 2019
1 parent abfd427 commit 1473b44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
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

0 comments on commit 1473b44

Please sign in to comment.