diff --git a/cmd/main.go b/cmd/main.go index 8a0e0de..b607378 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -6,6 +6,7 @@ import ( "time" "github.com/gin-gonic/gin/binding" + "github.com/konveyor/tackle2-addon-analyzer/builder" "github.com/konveyor/tackle2-addon/ssh" hub "github.com/konveyor/tackle2-hub/addon" "github.com/konveyor/tackle2-hub/api" @@ -115,31 +116,11 @@ func main() { // RuleError ruleErr := issues.RuleError() ruleErr.Report() - if !d.Mode.Discovery { - // - // 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 { - return - } - addon.Activity("Analysis reported. duration: %s", time.Since(mark)) - // - // Facts - facts := addon.Application.Facts(application.ID) - facts.Source(Source) - err = facts.Replace(issues.Facts()) - if err == nil { - addon.Activity("Facts updated.") - } else { - return - } + // + // Update application. + err = updateApplication(d, application.ID, issues, deps) + if err != nil { + return } // // Tags. @@ -158,3 +139,44 @@ func main() { return }) } + +// updateApplication creates analysis report and updates +// the application facts and tags. +func updateApplication(d *Data, appId uint, issues *builder.Issues, deps *builder.Deps) (err error) { + // + // Tags. + if d.Tagger.Enabled { + if d.Tagger.Source == "" { + d.Tagger.Source = Source + } + err = d.Tagger.Update(appId, issues.Tags()) + if err != nil { + return + } + } + if d.Mode.Discovery { + return + } + // + // Analysis. + appAnalysis := addon.Application.Analysis(appId) + mark := time.Now() + analysis := &api.Analysis{} + err = appAnalysis.Create( + analysis, + binding.MIMEYAML, + issues.Reader(), + deps.Reader()) + if err != nil { + return + } + addon.Activity("Analysis reported. duration: %s", time.Since(mark)) + // Facts. + facts := addon.Application.Facts(appId) + facts.Source(Source) + err = facts.Replace(issues.Facts()) + if err == nil { + addon.Activity("Facts updated.") + } + return +}