diff --git a/cmd/enforce.go b/cmd/enforce.go index 54f77878..b4b12530 100644 --- a/cmd/enforce.go +++ b/cmd/enforce.go @@ -26,8 +26,8 @@ var enforceCmd = &cobra.Command{ // after this point cmd.SilenceUsage = true - summarizer := cmd.Flags().Lookup("summary").Value.String() - e, err := enforcer.New(summarizer) + reporter := cmd.Flags().Lookup("reporter").Value.String() + e, err := enforcer.New(reporter) if err != nil { return fmt.Errorf("failed to create enforcer: %+v", err) } @@ -48,6 +48,6 @@ var enforceCmd = &cobra.Command{ func init() { enforceCmd.Flags().String("commit-msg-file", "", "the path to the temporary commit message file") - enforceCmd.Flags().String("summary", "none", "the summary method to use") + enforceCmd.Flags().String("reporter", "none", "the reporter method to use") rootCmd.AddCommand(enforceCmd) } diff --git a/cmd/serve.go b/cmd/serve.go index fd9b2ccc..e0652214 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -81,7 +81,7 @@ var serveCmd = &cobra.Command{ log.Printf("failed to write event to disk: %+v\n", err) return } - cmd := exec.Command("/proc/self/exe", "enforce", "--summary=github") + cmd := exec.Command("/proc/self/exe", "enforce", "--reporter=github") cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout cmd.Dir = cloneRepo diff --git a/internal/enforcer/enforcer.go b/internal/enforcer/enforcer.go index 4e4bb60b..9504b5d3 100644 --- a/internal/enforcer/enforcer.go +++ b/internal/enforcer/enforcer.go @@ -16,15 +16,15 @@ import ( "github.com/talos-systems/conform/internal/policy" "github.com/talos-systems/conform/internal/policy/commit" "github.com/talos-systems/conform/internal/policy/license" - "github.com/talos-systems/conform/internal/summarizer" + "github.com/talos-systems/conform/internal/reporter" yaml "gopkg.in/yaml.v2" ) // Conform is a struct that conform.yaml gets decoded into. type Conform struct { - Policies []*PolicyDeclaration `yaml:"policies"` - summarizer summarizer.Summarizer + Policies []*PolicyDeclaration `yaml:"policies"` + reporter reporter.Reporter } // PolicyDeclaration allows a user to declare an arbitrary type along with a @@ -42,18 +42,18 @@ var policyMap = map[string]policy.Policy{ } // New loads the conform.yaml file and unmarshals it into a Conform struct. -func New(s string) (*Conform, error) { +func New(r string) (*Conform, error) { c := &Conform{} - switch s { + switch r { case "github": - s, err := summarizer.NewGitHubSummarizer() + s, err := reporter.NewGitHubReporter() if err != nil { return nil, err } - c.summarizer = s + c.reporter = s default: - c.summarizer = &summarizer.Noop{} + c.reporter = &reporter.Noop{} } configBytes, err := ioutil.ReadFile(".conform.yaml") @@ -87,14 +87,14 @@ func (c *Conform) Enforce(setters ...policy.Option) error { for _, err := range check.Errors() { fmt.Fprintf(w, "%s\t%s\t%s\t%v\t\n", p.Type, check.Name(), "FAILED", err) } - if err := c.summarizer.SetStatus("failure", p.Type, check.Name(), check.Message()); err != nil { - log.Printf("WARNING: summary failed: %+v", err) + if err := c.reporter.SetStatus("failure", p.Type, check.Name(), check.Message()); err != nil { + log.Printf("WARNING: report failed: %+v", err) } pass = false } else { fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n", p.Type, check.Name(), "PASS", "") - if err := c.summarizer.SetStatus("success", p.Type, check.Name(), check.Message()); err != nil { - log.Printf("WARNING: summary failed: %+v", err) + if err := c.reporter.SetStatus("success", p.Type, check.Name(), check.Message()); err != nil { + log.Printf("WARNING: report failed: %+v", err) } } } diff --git a/internal/policy/policy.go b/internal/policy/policy.go index fd22353c..14ccae3b 100644 --- a/internal/policy/policy.go +++ b/internal/policy/policy.go @@ -4,7 +4,7 @@ package policy -// Report summarizes the compliance of a policy. +// Report reports the compliance of a policy. type Report struct { checks []Check } diff --git a/internal/summarizer/summarizer.go b/internal/reporter/reporter.go similarity index 88% rename from internal/summarizer/summarizer.go rename to internal/reporter/reporter.go index f4e8eaef..04425b22 100644 --- a/internal/summarizer/summarizer.go +++ b/internal/reporter/reporter.go @@ -2,7 +2,7 @@ * 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/. */ -package summarizer +package reporter import ( "context" @@ -20,12 +20,12 @@ import ( "github.com/talos-systems/conform/internal/git" ) -// Summarizer describes a hook for send summarized results to a remote API. -type Summarizer interface { +// Reporter describes a hook for sending summarized results to a remote API. +type Reporter interface { SetStatus(string, string, string, string) error } -// GitHub is a summarizer that summarizes policies statuses as GitHub statuses. +// GitHub is a reporter that summarizes policy statuses as GitHub statuses. type GitHub struct { token string owner string @@ -33,7 +33,7 @@ type GitHub struct { sha string } -// Noop is a summarizer that does nothing. +// Noop is a reporter that does nothing. type Noop struct { } @@ -42,9 +42,9 @@ func (n *Noop) SetStatus(state, policy, check, message string) error { return nil } -// NewGitHubSummarizer returns a summarizer that posts policy checks as +// NewGitHubReporter returns a reporter that posts policy checks as // status checks on a pull request. -func NewGitHubSummarizer() (*GitHub, error) { +func NewGitHubReporter() (*GitHub, error) { token, ok := os.LookupEnv("INPUT_TOKEN") if !ok { return nil, errors.New("missing INPUT_TOKEN")