Skip to content

Commit

Permalink
feat(issue): add issueType count (#119)
Browse files Browse the repository at this point in the history
Co-authored-by: David Rochow <[email protected]>
  • Loading branch information
MR2011 and drochow authored Aug 7, 2024
1 parent 20b2ccd commit b9d7189
Show file tree
Hide file tree
Showing 17 changed files with 594 additions and 46 deletions.
36 changes: 28 additions & 8 deletions internal/api/graphql/graph/baseResolver/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import (
"k8s.io/utils/pointer"
)

func GetIssueListOptions(requestedFields []string) *entity.IssueListOptions {
listOptions := GetListOptions(requestedFields)
return &entity.IssueListOptions{
ListOptions: *listOptions,
ShowIssueTypeCounts: lo.Contains(requestedFields, "issueTypeCounts"),
}
}

func SingleIssueBaseResolver(app app.Heureka, ctx context.Context, parent *model.NodeParent) (*model.Issue, error) {
requestedFields := GetPreloads(ctx)
logrus.WithFields(logrus.Fields{
Expand All @@ -29,7 +37,7 @@ func SingleIssueBaseResolver(app app.Heureka, ctx context.Context, parent *model
Id: parent.ChildIds,
}

opt := &entity.ListOptions{}
opt := &entity.IssueListOptions{}

issues, err := app.ListIssues(f, opt)

Expand Down Expand Up @@ -102,7 +110,7 @@ func IssueBaseResolver(app app.Heureka, ctx context.Context, filter *model.Issue
IssueMatchTargetRemediationDate: nil, //@todo Implement
}

opt := GetListOptions(requestedFields)
opt := GetIssueListOptions(requestedFields)

issues, err := app.ListIssues(f, opt)

Expand All @@ -121,17 +129,29 @@ func IssueBaseResolver(app app.Heureka, ctx context.Context, filter *model.Issue
edges = append(edges, &edge)
}

tc := 0
totalCount := 0
if issues.TotalCount != nil {
tc = int(*issues.TotalCount)
totalCount = int(*issues.TotalCount)
}

vulnerabilityCount := 0
policiyViolationCount := 0
securityEventCount := 0

if issues.VulnerabilityCount != nil && issues.PolicyViolationCount != nil && issues.SecurityEventCount != nil {
vulnerabilityCount = int(*issues.VulnerabilityCount)
policiyViolationCount = int(*issues.PolicyViolationCount)
securityEventCount = int(*issues.SecurityEventCount)
}

connection := model.IssueConnection{
TotalCount: tc,
Edges: edges,
PageInfo: model.NewPageInfo(issues.PageInfo),
TotalCount: totalCount,
VulnerabilityCount: vulnerabilityCount,
PolicyViolationCount: policiyViolationCount,
SecurityEventCount: securityEventCount,
Edges: edges,
PageInfo: model.NewPageInfo(issues.PageInfo),
}

return &connection, nil

}
195 changes: 192 additions & 3 deletions internal/api/graphql/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions internal/api/graphql/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
after: $after
) {
totalCount
vulnerabilityCount
policyViolationCount
securityEventCount
edges {
node {
id
Expand Down
3 changes: 3 additions & 0 deletions internal/api/graphql/graph/schema/issue.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ input IssueInput {

type IssueConnection implements Connection {
totalCount: Int!
vulnerabilityCount: Int!
policyViolationCount: Int!
securityEventCount: Int!
edges: [IssueEdge]!
pageInfo: PageInfo
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type Heureka interface {
ListIssues(*entity.IssueFilter, *entity.ListOptions) (*entity.List[entity.IssueResult], error)
ListIssues(*entity.IssueFilter, *entity.IssueListOptions) (*entity.IssueList, error)
CreateIssue(*entity.Issue) (*entity.Issue, error)
UpdateIssue(*entity.Issue) (*entity.Issue, error)
DeleteIssue(int64) error
Expand Down
Loading

0 comments on commit b9d7189

Please sign in to comment.