From b7aab19cb41220762839fc7ad16ee5d9a0b33c55 Mon Sep 17 00:00:00 2001 From: Tim Clifford Date: Wed, 13 Oct 2021 17:41:05 +0100 Subject: [PATCH] fixing duplicate facts bug --- cmd/gather.go | 10 ++++------ gatherers/DrushPMLGatherer.go | 16 +++++++++------- gatherers/defs.go | 4 ++-- gatherers/graphql.go | 2 ++ 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd/gather.go b/cmd/gather.go index aa6c674..5e4f105 100644 --- a/cmd/gather.go +++ b/cmd/gather.go @@ -69,14 +69,12 @@ var gatherCmd = &cobra.Command{ log.Println(err.Error()) continue } - if verbose := viper.Get("verbose"); verbose == true { - for _, f := range gatheredFacts { - if f.Value != "" { - log.Printf("Registering %s", f.Name) - facts = append(facts, gatheredFacts...) - } + for _, f := range gatheredFacts { + if verbose := viper.Get("verbose"); verbose == true { + log.Printf("Registering %s", f.Name) } } + facts = append(facts, gatheredFacts...) } } } diff --git a/gatherers/DrushPMLGatherer.go b/gatherers/DrushPMLGatherer.go index e9cbc63..7d22575 100644 --- a/gatherers/DrushPMLGatherer.go +++ b/gatherers/DrushPMLGatherer.go @@ -40,13 +40,15 @@ func (p *drushPmlGatherer) AppliesToEnvironment() bool { } for key, element := range result { - p.GatheredFacts = append(p.GatheredFacts, GatheredFact{ - Name: key, - Value: fmt.Sprintf("%v", element.Version), - Source: "drush_pml", - Description: "Drupal " + element.Type + " status: " + element.Status, - Category: Drupal, - }) + if element.Version != nil { + p.GatheredFacts = append(p.GatheredFacts, GatheredFact{ + Name: key, + Value: fmt.Sprintf("%v", element.Version), + Source: "drush_pml", + Description: "Status: " + element.Status, + Category: Drupal, + }) + } } return true diff --git a/gatherers/defs.go b/gatherers/defs.go index 7eefbe5..8a270dc 100644 --- a/gatherers/defs.go +++ b/gatherers/defs.go @@ -7,7 +7,7 @@ type GatheredFact struct { Source string `json:"source"` Environment int `json:"environment"` Description string `json:"description"` - Category FactCategory `json:"-"` //`json:"category,omitempty"` + Category FactCategory `json:"-"` // `json:"category,omitempty"` } const ( @@ -17,7 +17,7 @@ const ( type Gatherer interface { GetGathererCmdType() string - AppliesToEnvironment() bool //Whether this gatherer can run in the local environment + AppliesToEnvironment() bool // Whether this gatherer can run in the local environment GatherFacts() ([]GatheredFact, error) } diff --git a/gatherers/graphql.go b/gatherers/graphql.go index 86a323c..63f48f1 100644 --- a/gatherers/graphql.go +++ b/gatherers/graphql.go @@ -46,8 +46,10 @@ func Writefacts(projectName string, environmentName string, facts []GatheredFact client, err := getGraphqlClient() if err != nil { + log.Println(err) return err } + var addFactMutation struct { AddFacts []struct { Id int