Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(report): Sorting the report order #14

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions cmd/summary/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func reportIDHandler(w http.ResponseWriter, r *http.Request) {
return
}

// Sort the report resources.
report.SortResources()

rep = report

type PageData struct {
Expand Down
36 changes: 36 additions & 0 deletions pkg/entities/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package entities
import (
"log/slog"
"path/filepath"
"sort"
"time"
)

Expand Down Expand Up @@ -117,3 +118,38 @@ func (n *PuppetReport) ReportFilePath() string {
n.YamlFile = path
return path
}

func (n *PuppetReport) SortResources() {
// Sort the resources.
n.sortResource(n.ResourcesFailed)
n.sortResource(n.ResourcesChanged)
n.sortResource(n.ResourcesSkipped)
n.sortResource(n.ResourcesOK)
}

func (n *PuppetReport) sortResource(resources []*PuppetResource) {
sort.Slice(resources, func(i, j int) bool {
// Sort by resource file.
if resources[i].File != resources[j].File {
return resources[i].File < resources[j].File
}

// Sort by resource line.
if resources[i].Line != resources[j].Line {
return resources[i].Line < resources[j].Line
}

// Sort by resource type.
if resources[i].Type != resources[j].Type {
return resources[i].Type < resources[j].Type
}

// Sort by resource name.
if resources[i].Name != resources[j].Name {
return resources[i].Name < resources[j].Name
}

// Resources are equal.
return false
})
}
Loading