Skip to content

Commit b7f5d59

Browse files
authored
add CodeIssue check type (#470)
* add CodeIssue check type, more robust check testing * remove redundant assertions in check test * add CodeIssueCheckFragment, update struct docs and tests * fix types of fields in CodeIssueCheck * add CodeIssueCheck structs and tests * remove unneeded pointers
1 parent 1693731 commit b7f5d59

19 files changed

+444
-49
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Feature
2+
body: add CodeIssue check type
3+
time: 2024-10-04T12:32:07.226978-05:00

check.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type CheckInputConstructor func() any
1919

2020
var CheckCreateConstructors = map[CheckType]CheckInputConstructor{
2121
CheckTypeAlertSourceUsage: func() any { return &CheckAlertSourceUsageCreateInput{} },
22+
CheckTypeCodeIssue: func() any { return &CheckCodeIssueCreateInput{} },
2223
CheckTypeCustom: func() any { return &CheckCreateInput{} },
2324
CheckTypeGeneric: func() any { return &CheckCustomEventCreateInput{} },
2425
CheckTypeGitBranchProtection: func() any { return &CheckGitBranchProtectionCreateInput{} },
@@ -41,6 +42,7 @@ var CheckCreateConstructors = map[CheckType]CheckInputConstructor{
4142

4243
var CheckUpdateConstructors = map[CheckType]CheckInputConstructor{
4344
CheckTypeAlertSourceUsage: func() any { return &CheckAlertSourceUsageUpdateInput{} },
45+
CheckTypeCodeIssue: func() any { return &CheckCodeIssueUpdateInput{} },
4446
CheckTypeCustom: func() any { return &CheckUpdateInput{} },
4547
CheckTypeGeneric: func() any { return &CheckCustomEventUpdateInput{} },
4648
CheckTypeGitBranchProtection: func() any { return &CheckGitBranchProtectionUpdateInput{} },
@@ -140,6 +142,8 @@ func (client *Client) CreateCheck(input any) (*Check, error) {
140142
switch v := input.(type) {
141143
case *CheckAlertSourceUsageCreateInput:
142144
return client.CreateCheckAlertSourceUsage(*v)
145+
case *CheckCodeIssueCreateInput:
146+
return client.CreateCheckCodeIssue(*v)
143147
case *CheckCustomEventCreateInput:
144148
return client.CreateCheckCustomEvent(*v)
145149
case *CheckGitBranchProtectionCreateInput:
@@ -226,6 +230,8 @@ func (client *Client) UpdateCheck(input any) (*Check, error) {
226230
switch v := input.(type) {
227231
case *CheckAlertSourceUsageUpdateInput:
228232
return client.UpdateCheckAlertSourceUsage(*v)
233+
case *CheckCodeIssueUpdateInput:
234+
return client.UpdateCheckCodeIssue(*v)
229235
case *CheckCustomEventUpdateInput:
230236
return client.UpdateCheckCustomEvent(*v)
231237
case *CheckGitBranchProtectionUpdateInput:

check_alert_source_usage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package opslevel
22

33
type AlertSourceUsageCheckFragment struct {
4-
AlertSourceNamePredicate *Predicate `graphql:"alertSourceNamePredicate"`
5-
AlertSourceType AlertSourceTypeEnum `graphql:"alertSourceType"`
4+
AlertSourceNamePredicate *Predicate `graphql:"alertSourceNamePredicate"` // The condition that the alert source name should satisfy to be evaluated.
5+
AlertSourceType AlertSourceTypeEnum `graphql:"alertSourceType"` // The type of the alert source.
66
}
77

88
func (client *Client) CreateCheckAlertSourceUsage(input CheckAlertSourceUsageCreateInput) (*Check, error) {

check_code_issue.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package opslevel
2+
3+
type CodeIssueCheckFragment struct {
4+
Constraint CheckCodeIssueConstraintEnum `graphql:"constraint"` // The type of constraint used in evaluation the code issues check.
5+
IssueName string `graphql:"issueName"` // The issue name used for code issue lookup.
6+
IssueType []string `graphql:"issueType"` // The type of code issue to consider.
7+
MaxAllowed int `graphql:"maxAllowed"` // The threshold count of code issues beyond which the check starts failing.
8+
ResolutionTime CodeIssueResolutionTime `graphql:"resolutionTime"` // The resolution time recommended by the reporting source of the code issue.
9+
Severity []string `graphql:"severity"` // The severity levels of the issue.
10+
}
11+
12+
// CodeIssueResolutionTime represents how long a code issue has been detected.
13+
type CodeIssueResolutionTime struct {
14+
Unit CodeIssueResolutionTimeUnitEnum `graphql:"unit"` // The name of duration of time.
15+
Value int `graphql:"value"` // The count value of the specified unit.
16+
}
17+
18+
func (client *Client) CreateCheckCodeIssue(input CheckCodeIssueCreateInput) (*Check, error) {
19+
var m struct {
20+
Payload CheckResponsePayload `graphql:"checkCodeIssueCreate(input: $input)"`
21+
}
22+
v := PayloadVariables{
23+
"input": input,
24+
}
25+
err := client.Mutate(&m, v, WithName("CheckCodeIssueCreate"))
26+
return &m.Payload.Check, HandleErrors(err, m.Payload.Errors)
27+
}
28+
29+
func (client *Client) UpdateCheckCodeIssue(input CheckCodeIssueUpdateInput) (*Check, error) {
30+
var m struct {
31+
Payload CheckResponsePayload `graphql:"checkCodeIssueUpdate(input: $input)"`
32+
}
33+
v := PayloadVariables{
34+
"input": input,
35+
}
36+
err := client.Mutate(&m, v, WithName("CheckCodeIssueUpdate"))
37+
return &m.Payload.Check, HandleErrors(err, m.Payload.Errors)
38+
}

check_custom_event.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package opslevel
22

33
type CustomEventCheckFragment struct {
4-
Integration IntegrationId `graphql:"integration"`
5-
PassPending bool `graphql:"passPending"`
6-
ResultMessage string `graphql:"resultMessage"`
7-
ServiceSelector string `graphql:"serviceSelector"`
8-
SuccessCondition string `graphql:"successCondition"`
4+
Integration IntegrationId `graphql:"integration"` // The integration this check uses.
5+
PassPending bool `graphql:"passPending"` // True if this check should pass by default. Otherwise the default 'pending' state counts as a failure.
6+
ResultMessage string `graphql:"resultMessage"` // The check result message template.
7+
ServiceSelector string `graphql:"serviceSelector"` // A jq expression that will be ran against your payload to select the service.
8+
SuccessCondition string `graphql:"successCondition"` // A jq expression that will be ran against your payload to evaluate the check result. A truthy value will result in the check passing.
99
}
1010

1111
func (client *Client) CreateCheckCustomEvent(input CheckCustomEventCreateInput) (*Check, error) {

check_has_documentation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package opslevel
22

33
type HasDocumentationCheckFragment struct {
4-
DocumentType HasDocumentationTypeEnum `graphql:"documentType"`
5-
DocumentSubtype HasDocumentationSubtypeEnum `graphql:"documentSubtype"`
4+
DocumentSubtype HasDocumentationSubtypeEnum `graphql:"documentSubtype"` // The subtype of the document.
5+
DocumentType HasDocumentationTypeEnum `graphql:"documentType"` // The type of the document.
66
}
77

88
func (client *Client) CreateCheckHasDocumentation(input CheckHasDocumentationCreateInput) (*Check, error) {

check_has_owner.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package opslevel
22

33
type ServiceOwnershipCheckFragment struct {
4-
RequireContactMethod *bool `graphql:"requireContactMethod"`
5-
ContactMethod *ContactType `graphql:"contactMethod"`
6-
TeamTagKey string `graphql:"tagKey"`
7-
TeamTagPredicate *Predicate `graphql:"tagPredicate"`
4+
ContactMethod *ContactType `graphql:"contactMethod"` // The type of contact method that an owner should provide.
5+
RequireContactMethod *bool `graphql:"requireContactMethod"` // Whether to require a contact method for a service owner or not.
6+
TeamTagKey string `graphql:"tagKey"` // The tag key that should exist for a service owner.
7+
TeamTagPredicate *Predicate `graphql:"tagPredicate"` // The condition that should be satisfied by the tag value.
88
}
99

1010
func (client *Client) CreateCheckServiceOwnership(input CheckServiceOwnershipCreateInput) (*Check, error) {

check_has_recent_deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package opslevel
22

33
type HasRecentDeployCheckFragment struct {
4-
Days int `graphql:"days"`
4+
Days int `graphql:"days"` // The number of days to check since the last deploy.
55
}
66

77
func (client *Client) CreateCheckHasRecentDeploy(input CheckHasRecentDeployCreateInput) (*Check, error) {

check_manual.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package opslevel
33
import "github.com/relvacode/iso8601"
44

55
type ManualCheckFragment struct {
6-
UpdateFrequency *ManualCheckFrequency `graphql:"updateFrequency"`
7-
UpdateRequiresComment bool `graphql:"updateRequiresComment"`
6+
UpdateFrequency *ManualCheckFrequency `graphql:"updateFrequency"` // The minimum frequency of the updates.
7+
UpdateRequiresComment bool `graphql:"updateRequiresComment"` // Whether the check requires a comment or not.
88
}
99

1010
type ManualCheckFrequency struct {

check_repo_file.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package opslevel
22

33
type RepositoryFileCheckFragment struct {
4-
DirectorySearch bool `graphql:"directorySearch"`
5-
Filepaths []string `graphql:"filePaths"`
6-
FileContentsPredicate *Predicate `graphql:"fileContentsPredicate"`
7-
UseAbsoluteRoot bool `graphql:"useAbsoluteRoot"`
4+
DirectorySearch bool `graphql:"directorySearch"` // Whether the check looks for the existence of a directory instead of a file.
5+
FileContentsPredicate *Predicate `graphql:"fileContentsPredicate"` // Condition to match the file content.
6+
Filepaths []string `graphql:"filePaths"` // Restrict the search to certain file paths.
7+
UseAbsoluteRoot bool `graphql:"useAbsoluteRoot"` // Whether the checks looks at the absolute root of a repo or the relative root (the directory specified when attached a repo to a service).
88
}
99

1010
func (client *Client) CreateCheckRepositoryFile(input CheckRepositoryFileCreateInput) (*Check, error) {

0 commit comments

Comments
 (0)