Skip to content

Commit

Permalink
Update configuration to use omitempty annotation (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmiyake authored Mar 31, 2018
1 parent 0d41123 commit 5aa3c94
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions godelplugin/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ custom-headers:
// Subproject license.
paths:
- subprojectDir
`,
},
},
{
Name: "legacy config is upgraded and empty fields are omitted",
ConfigFiles: map[string]string{
"godel/config/license.yml": `
header: |
// Copyright 2016 Palantir Technologies, Inc.
//
// License content.
`,
},
Legacy: true,
WantOutput: `Upgraded configuration for license-plugin.yml
`,
WantFiles: map[string]string{
"godel/config/license-plugin.yml": `header: |
// Copyright 2016 Palantir Technologies, Inc.
//
// License content.
`,
},
},
Expand Down
12 changes: 6 additions & 6 deletions golicense/config/internal/v0/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ type ProjectConfig struct {
// Header is the expected license header. All applicable files are expected to start with this header followed
// by a newline. Any occurrences of the string {{YEAR}} is treated specially: when generating a license, the current
// year will be substituted for it, and when verifying a license, any 4-digit string will be considered a match.
Header string `yaml:"header"`
Header string `yaml:"header,omitempty"`

// CustomHeaders specifies the custom header parameters. Custom header parameters can be used to specify that
// certain directories or files in the project should use a header that is different from "Header".
CustomHeaders []CustomHeaderConfig `yaml:"custom-headers"`
CustomHeaders []CustomHeaderConfig `yaml:"custom-headers,omitempty"`

// Exclude matches the files and directories that should be excluded from consideration for verifying or applying
// licenses.
Exclude matcher.NamesPathsCfg `yaml:"exclude"`
Exclude matcher.NamesPathsCfg `yaml:"exclude,omitempty"`
}

type CustomHeaderConfig struct {
// Name is the identifier used to identify this custom license parameter. Must be unique.
Name string `yaml:"name"`
Name string `yaml:"name,omitempty"`

// Header is the expected license header. All applicable files are expected to start with this header followed
// by a newline. Any occurrences of the string {{YEAR}} is treated specially: when generating a license, the current
// year will be substituted for it, and when verifying a license, any 4-digit string will be considered a match.
Header string `yaml:"header"`
Header string `yaml:"header,omitempty"`

// Paths specifies the paths for which this custom license is applicable. If multiple custom parameters match a
// file or directory, the parameter with the longest path match is used. If multiple custom parameters match a
// file or directory exactly (match length is equal), it is treated as an error.
Paths []string `yaml:"paths"`
Paths []string `yaml:"paths,omitempty"`
}

func UpgradeConfig(cfgBytes []byte) ([]byte, error) {
Expand Down
3 changes: 2 additions & 1 deletion vendor/github.com/palantir/pkg/gittest/gittest.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/palantir/pkg/matcher/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5aa3c94

Please sign in to comment.