Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 58 additions & 27 deletions builder/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,91 @@ var (
addon = hub.Addon
)

// NewIssues returns a new issues builder.
func NewIssues(path string) (b *Issues, err error) {
b = &Issues{}
// NewInsights returns a new insights builder.
func NewInsights(path string) (b *Insights, err error) {
b = &Insights{}
err = b.read(path)
return
}

// Issues builds issues and facts.
type Issues struct {
// Insights builds insights and facts.
type Insights struct {
ruleErr RuleError
facts []api.Fact
input []output.RuleSet
}

// RuleError returns the rule error.
func (b *Issues) RuleError() (r *RuleError) {
func (b *Insights) RuleError() (r *RuleError) {
for _, ruleset := range b.input {
b.ruleErr.Append(ruleset)
}
return &b.ruleErr
}

// Write issues section.
func (b *Issues) Write(writer io.Writer) (err error) {
// Write insights section.
func (b *Insights) Write(writer io.Writer) (err error) {
encoder := yaml.NewEncoder(writer)
_, _ = writer.Write([]byte(api.BeginIssuesMarker))
_, _ = writer.Write([]byte(api.BeginInsightsMarker))
_, _ = writer.Write([]byte{'\n'})
if err != nil {
return
}
for _, ruleset := range b.input {
for ruleid, v := range ruleset.Violations {
issue := api.Issue{
insight := api.Insight{
RuleSet: ruleset.Name,
Rule: ruleid,
Description: v.Description,
Labels: v.Labels,
}
if v.Category != nil {
issue.Category = string(*v.Category)
insight.Category = string(*v.Category)
}
if v.Effort != nil {
issue.Effort = *v.Effort
insight.Effort = *v.Effort
}
insight.Links = []api.Link{}
for _, l := range v.Links {
insight.Links = append(
insight.Links,
api.Link{
URL: l.URL,
Title: l.Title,
})
}
insight.Incidents = []api.Incident{}
for _, i := range v.Incidents {
incident := api.Incident{
File: b.fileRef(i.URI),
Line: pointer.IntDeref(i.LineNumber, 0),
Message: i.Message,
CodeSnip: i.CodeSnip,
Facts: i.Variables,
}
insight.Incidents = append(
insight.Incidents,
incident)
}
err = encoder.Encode(&insight)
if err != nil {
return
}
}
for ruleid, v := range ruleset.Insights {
insight := api.Insight{
RuleSet: ruleset.Name,
Rule: ruleid,
Description: v.Description,
Labels: v.Labels,
}
issue.Links = []api.Link{}
insight.Links = []api.Link{}
for _, l := range v.Links {
issue.Links = append(
issue.Links,
insight.Links = append(
insight.Links,
api.Link{
URL: l.URL,
Title: l.Title,
})
}
issue.Incidents = []api.Incident{}
insight.Incidents = []api.Incident{}
for _, i := range v.Incidents {
incident := api.Incident{
File: b.fileRef(i.URI),
Expand All @@ -81,23 +112,23 @@ func (b *Issues) Write(writer io.Writer) (err error) {
CodeSnip: i.CodeSnip,
Facts: i.Variables,
}
issue.Incidents = append(
issue.Incidents,
insight.Incidents = append(
insight.Incidents,
incident)
}
err = encoder.Encode(&issue)
err = encoder.Encode(&insight)
if err != nil {
return
}
}
}
_, _ = writer.Write([]byte(api.EndIssuesMarker))
_, _ = writer.Write([]byte(api.EndInsightsMarker))
_, _ = writer.Write([]byte{'\n'})
return
}

// read ruleSets.
func (b *Issues) read(path string) (err error) {
func (b *Insights) read(path string) (err error) {
b.input = []output.RuleSet{}
f, err := os.Open(path)
if err != nil {
Expand All @@ -112,7 +143,7 @@ func (b *Issues) read(path string) (err error) {
}

// fileRef returns the file (relative) path.
func (b *Issues) fileRef(in uri.URI) (s string) {
func (b *Insights) fileRef(in uri.URI) (s string) {
s = string(in)
u, err := url.Parse(s)
if err == nil {
Expand All @@ -122,15 +153,15 @@ func (b *Issues) fileRef(in uri.URI) (s string) {
}

// Tags builds tags.
func (b *Issues) Tags() (tags []string) {
func (b *Insights) Tags() (tags []string) {
for _, r := range b.input {
tags = append(tags, r.Tags...)
}
return
}

// Facts builds facts.
func (b *Issues) Facts() (facts api.Map) {
func (b *Insights) Facts() (facts api.Map) {
return
}

Expand Down
4 changes: 2 additions & 2 deletions builder/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Manifest file.
type Manifest struct {
Analysis api.Analysis
Issues *Issues
Insights *Insights
Deps *Deps
Path string
}
Expand All @@ -34,7 +34,7 @@ func (m *Manifest) Write() (err error) {
}
_, _ = file.Write([]byte(api.EndMainMarker))
_, _ = file.Write([]byte{'\n'})
err = m.Issues.Write(file)
err = m.Insights.Write(file)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type Analyzer struct {
}

// Run analyzer.
func (r *Analyzer) Run() (issues *builder.Issues, deps *builder.Deps, err error) {
output := path.Join(Dir, "issues.yaml")
func (r *Analyzer) Run() (insights *builder.Insights, deps *builder.Deps, err error) {
output := path.Join(Dir, "insights.yaml")
depOutput := path.Join(Dir, "deps.yaml")
cmd := command.New(AnalyzerBin)
cmd.Options, err = r.options(output, depOutput)
Expand Down Expand Up @@ -56,7 +56,7 @@ func (r *Analyzer) Run() (issues *builder.Issues, deps *builder.Deps, err error)
addon.Attach(f)
}
}
issues, err = builder.NewIssues(output)
insights, err = builder.NewInsights(output)
if err != nil {
return
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ func main() {
// Run the analyzer.
analyzer := Analyzer{}
analyzer.Data = d
issues, deps, err := analyzer.Run()
insights, deps, err := analyzer.Run()
if err != nil {
return
}
//
// RuleError
ruleErr := issues.RuleError()
ruleErr := insights.RuleError()
ruleErr.Report()
//
// Update application.
err = updateApplication(d, application.ID, issues, deps)
err = updateApplication(d, application.ID, insights, deps)
if err != nil {
return
}
Expand All @@ -131,14 +131,14 @@ func main() {

// 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) {
func updateApplication(d *Data, appId uint, insights *builder.Insights, 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())
err = d.Tagger.Update(appId, insights.Tags())
if err != nil {
return
}
Expand All @@ -150,7 +150,7 @@ func updateApplication(d *Data, appId uint, issues *builder.Issues, deps *builde
// Analysis.
manifest := builder.Manifest{
Analysis: api.Analysis{},
Issues: issues,
Insights: insights,
Deps: deps,
}
if d.Mode.Repository != nil {
Expand All @@ -173,7 +173,7 @@ func updateApplication(d *Data, appId uint, issues *builder.Issues, deps *builde
// Facts.
facts := addon.Application.Facts(appId)
facts.Source(Source)
err = facts.Replace(issues.Facts())
err = facts.Replace(insights.Facts())
if err == nil {
addon.Activity("Facts updated.")
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ require (
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
)

replace github.com/konveyor/tackle2-hub => github.com/jortel/tackle2-hub v0.0.0-20250708154344-8e3a804a6004

require (
github.com/Nerzal/gocloak/v13 v13.9.0 // indirect
github.com/PaesslerAG/gval v1.2.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jortel/go-utils v0.1.4 h1:DzrID+gI9urEGkOoXYGYIKA/bozEIxmcYV/4cdVjW58=
github.com/jortel/go-utils v0.1.4/go.mod h1:7vzFYbnb91+ltjjAmCv2jVL4CKX7Onz1i2EQPAvw9Cs=
github.com/jortel/tackle2-hub v0.0.0-20250708154344-8e3a804a6004 h1:ZUFa4gRYxZxL2XTWgX/pbuzPEtGeq1sKnjr4OVjiwsg=
github.com/jortel/tackle2-hub v0.0.0-20250708154344-8e3a804a6004/go.mod h1:RdQChIneyr3sRRg9X9r2f+EYGLVKXVPiFApOSy3Nq0U=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand All @@ -153,8 +155,6 @@ github.com/konveyor/analyzer-lsp v0.7.0-alpha.2.0.20250528164516-ec5a199590bf h1
github.com/konveyor/analyzer-lsp v0.7.0-alpha.2.0.20250528164516-ec5a199590bf/go.mod h1:/7nwwqN27iODJy/PBai9W16KH91LrPGx1nwu21+rCOg=
github.com/konveyor/tackle2-addon v0.7.0-rc.1.0.20250604115244-17140aad3dd4 h1:cXh9HGpCMFnmUMdO6/5rbC28pFrhMps5fVyqBqYQk9Y=
github.com/konveyor/tackle2-addon v0.7.0-rc.1.0.20250604115244-17140aad3dd4/go.mod h1:mITXAU1o/8ZdBoGacaTZxXORfFe1q2S74W9RfTHHm7A=
github.com/konveyor/tackle2-hub v0.7.0-alpha.2.0.20250613230242-66dbfe5a9563 h1:LAcvID6gNNVQlFeiNTvLley0+yYfb+tjZTGQdXSGzYg=
github.com/konveyor/tackle2-hub v0.7.0-alpha.2.0.20250613230242-66dbfe5a9563/go.mod h1:RdQChIneyr3sRRg9X9r2f+EYGLVKXVPiFApOSy3Nq0U=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down
Loading