Skip to content

Commit

Permalink
✨ Add "Discovery" mode (#99)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam authored Jun 20, 2024
1 parent bda9527 commit 8e3a166
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
75 changes: 41 additions & 34 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,50 +112,57 @@ func main() {
if err != nil {
return
}
depAnalyzer := DepAnalyzer{}
depAnalyzer.Data = d
deps, err := depAnalyzer.Run()
if err != nil {
return
}
//
// Post report.
appAnalysis := addon.Application.Analysis(application.ID)
mark := time.Now()
analysis := &api.Analysis{}
err = appAnalysis.Create(
analysis,
binding.MIMEYAML,
issues.Reader(),
deps.Reader())
if err == nil {
addon.Activity("Analysis reported. duration: %s", time.Since(mark))
} else {
ruleErr := &RuleError{}
if errors.As(err, &ruleErr) {
ruleErr.Report()
err = nil
if !d.Mode.Discovery {
depAnalyzer := DepAnalyzer{}
depAnalyzer.Data = d
deps, dErr := depAnalyzer.Run()
if dErr != nil {
err = dErr
return
}
//
// Post report.
appAnalysis := addon.Application.Analysis(application.ID)
mark := time.Now()
analysis := &api.Analysis{}
err = appAnalysis.Create(
analysis,
binding.MIMEYAML,
issues.Reader(),
deps.Reader())
if err == nil {
addon.Activity("Analysis reported. duration: %s", time.Since(mark))
} else {
ruleErr := &RuleError{}
if errors.As(err, &ruleErr) {
ruleErr.Report()
err = nil
}
return
}
//
// Facts
facts := addon.Application.Facts(application.ID)
facts.Source(Source)
err = facts.Replace(issues.Facts())
if err == nil {
addon.Activity("Facts updated.")
} else {
return
}
return
}

//
// Tags.
if d.Tagger.Enabled {
if d.Tagger.Source == "" {
d.Tagger.Source = Source
}
err = d.Tagger.Update(application.ID, issues.Tags())
if err != nil {
return
}
}
//
// Facts
facts := addon.Application.Facts(application.ID)
facts.Source(Source)
err = facts.Replace(issues.Facts())
if err == nil {
addon.Activity("Facts updated.")
} else {
return
}

addon.Activity("Done.")

Expand Down
1 change: 1 addition & 0 deletions cmd/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

// Mode settings.
type Mode struct {
Discovery bool `json:"discovery"`
Binary bool `json:"binary"`
Artifact string `json:"artifact"`
WithDeps bool `json:"withDeps"`
Expand Down
3 changes: 2 additions & 1 deletion cmd/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var TagExp = regexp.MustCompile("(.+)(=)(.+)")

// Tagger tags an application.
type Tagger struct {
Enabled bool `json:"enabled"`
Enabled bool `json:"enabled"`
Source string `json:"source"`
}

// AddOptions adds analyzer options.
Expand Down

0 comments on commit 8e3a166

Please sign in to comment.