Skip to content

Commit 02f4280

Browse files
authored
Initial commit of package version check before testing (#442)
* Initial commit of package version check before testing * add changie * Delete .changes/unreleased/Feature-20240726-150245.yaml * Apply suggestions from code review * Apply suggestions from code review * fix lint
1 parent d75138c commit 02f4280

File tree

7 files changed

+224
-8
lines changed

7 files changed

+224
-8
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 ability to create, update, list and get 'PackageVersion' checks
3+
time: 2024-07-16T11:23:44.205054-05:00

check.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var CheckCreateConstructors = map[CheckType]CheckInputConstructor{
3535
CheckTypeServiceProperty: func() any { return &CheckServicePropertyCreateInput{} },
3636
CheckTypeTagDefined: func() any { return &CheckTagDefinedCreateInput{} },
3737
CheckTypeToolUsage: func() any { return &CheckToolUsageCreateInput{} },
38+
CheckTypePackageVersion: func() any { return &CheckPackageVersionCreateInput{} },
3839
}
3940

4041
var CheckUpdateConstructors = map[CheckType]CheckInputConstructor{
@@ -56,6 +57,7 @@ var CheckUpdateConstructors = map[CheckType]CheckInputConstructor{
5657
CheckTypeServiceProperty: func() any { return &CheckServicePropertyUpdateInput{} },
5758
CheckTypeTagDefined: func() any { return &CheckTagDefinedUpdateInput{} },
5859
CheckTypeToolUsage: func() any { return &CheckToolUsageUpdateInput{} },
60+
CheckTypePackageVersion: func() any { return &CheckPackageVersionUpdateInput{} },
5961
}
6062

6163
func UnmarshalCheckCreateInput(checkType CheckType, data []byte) (any, error) {
@@ -167,6 +169,8 @@ func (client *Client) CreateCheck(input any) (*Check, error) {
167169
return client.CreateCheckTagDefined(*v)
168170
case *CheckToolUsageCreateInput:
169171
return client.CreateCheckToolUsage(*v)
172+
case *CheckPackageVersionCreateInput:
173+
return client.CreateCheckPackageVersion(*v)
170174
}
171175
return nil, fmt.Errorf("unknown input type %T", input)
172176
}
@@ -248,6 +252,8 @@ func (client *Client) UpdateCheck(input any) (*Check, error) {
248252
return client.UpdateCheckTagDefined(*v)
249253
case *CheckToolUsageUpdateInput:
250254
return client.UpdateCheckToolUsage(*v)
255+
case *CheckPackageVersionUpdateInput:
256+
return client.UpdateCheckPackageVersion(*v)
251257
}
252258
return nil, fmt.Errorf("unknown input type %T", input)
253259
}

check_package_version.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package opslevel
2+
3+
type PackageVersionCheckFragment struct {
4+
MissingPackageResult *CheckResultStatusEnum `graphql:"missingPackageResult"` // The check result if the package isn't being used by a service.
5+
PackageConstraint PackageConstraintEnum `graphql:"packageConstraint"` // The package constraint the service is to be checked for.
6+
PackageManager PackageManagerEnum `graphql:"packageManager"` // The package manager (ecosystem) this package relates to.
7+
PackageName string `graphql:"packageName"` // The name of the package to be checked.
8+
PackageNameIsRegex bool `graphql:"packageNameIsRegex"` // Whether or not the value in the package name field is a regular expression.
9+
VersionConstraintPredicate *Predicate `graphql:"versionConstraintPredicate"` // The predicate that describes the version constraint the package must satisfy.
10+
}
11+
12+
// CreateCheckPackageVersion Creates a package version check.
13+
func (client *Client) CreateCheckPackageVersion(input CheckPackageVersionCreateInput) (*Check, error) {
14+
var m struct {
15+
Payload CheckResponsePayload `graphql:"checkPackageVersionCreate(input: $input)"`
16+
}
17+
v := PayloadVariables{
18+
"input": input,
19+
}
20+
err := client.Mutate(&m, v, WithName("CheckPackageVersionCreate"))
21+
return &m.Payload.Check, HandleErrors(err, m.Payload.Errors)
22+
}
23+
24+
// UpdateCheckPackageVersion Updates a package version check.
25+
func (client *Client) UpdateCheckPackageVersion(input CheckPackageVersionUpdateInput) (*Check, error) {
26+
var m struct {
27+
Payload CheckResponsePayload `graphql:"checkPackageVersionUpdate(input: $input)"`
28+
}
29+
v := PayloadVariables{
30+
"input": input,
31+
}
32+
err := client.Mutate(&m, v, WithName("CheckPackageVersionUpdate"))
33+
return &m.Payload.Check, HandleErrors(err, m.Payload.Errors)
34+
}

check_test.go

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func BuildCheckMutation(name string, style RequestStyle) string {
114114
... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},
115115
... on TagDefinedCheck{tagKey,tagPredicate{type,value}},
116116
... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},
117-
... on HasDocumentationCheck{documentType,documentSubtype}
117+
... on HasDocumentationCheck{documentType,documentSubtype},
118+
... on PackageVersionCheck{missingPackageResult,packageConstraint,packageManager,packageName,packageNameIsRegex,versionConstraintPredicate{type,value}}
118119
},
119120
errors{message,path}
120121
}
@@ -681,9 +682,53 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
681682
return c.UpdateCheckToolUsage(*input)
682683
},
683684
},
685+
"CreatePackageVersion": {
686+
fixture: BuildCreateRequest("PackageVersion", map[string]any{
687+
"packageManager": ol.PackageManagerEnumCargo,
688+
"packageName": "cult",
689+
"packageNameIsRegex": false,
690+
"packageConstraint": ol.PackageConstraintEnumDoesNotExist,
691+
"missingPackageResult": ol.CheckResultStatusEnumPassed,
692+
"versionConstraintPredicate": predicateInput,
693+
}),
694+
body: func(c *ol.Client) (*ol.Check, error) {
695+
input := ol.NewCheckCreateInputTypeOf[ol.CheckPackageVersionCreateInput](checkCreateInput)
696+
input.PackageManager = ol.PackageManagerEnumCargo
697+
input.PackageName = "cult"
698+
input.PackageNameIsRegex = ol.RefOf(false)
699+
input.PackageConstraint = ol.PackageConstraintEnumDoesNotExist
700+
input.MissingPackageResult = ol.RefOf(ol.CheckResultStatusEnumPassed)
701+
input.VersionConstraintPredicate = predicateInput
702+
return c.CreateCheckPackageVersion(*input)
703+
},
704+
},
705+
"UpdatePackageVersion": {
706+
fixture: BuildUpdateRequest("PackageVersion", map[string]any{
707+
"packageManager": ol.PackageManagerEnumCargo,
708+
"versionConstraintPredicate": predicateUpdateInput,
709+
}),
710+
body: func(c *ol.Client) (*ol.Check, error) {
711+
input := ol.NewCheckUpdateInputTypeOf[ol.CheckPackageVersionUpdateInput](checkUpdateInput)
712+
input.PackageManager = ol.RefOf(ol.PackageManagerEnumCargo)
713+
input.VersionConstraintPredicate = predicateUpdateInput
714+
return c.UpdateCheckPackageVersion(*input)
715+
},
716+
},
717+
"UpdatePackageVersionPredicateNull": {
718+
fixture: BuildUpdateRequest("PackageVersion", map[string]any{
719+
"packageManager": ol.PackageManagerEnumCargo,
720+
"versionConstraintPredicate": nil,
721+
}),
722+
body: func(c *ol.Client) (*ol.Check, error) {
723+
input := ol.NewCheckUpdateInputTypeOf[ol.CheckPackageVersionUpdateInput](checkUpdateInput)
724+
input.PackageManager = ol.RefOf(ol.PackageManagerEnumCargo)
725+
input.VersionConstraintPredicate = &ol.PredicateUpdateInput{}
726+
return c.UpdateCheckPackageVersion(*input)
727+
},
728+
},
684729
"GetCheck": {
685730
fixture: autopilot.NewTestRequest(
686-
`query CheckGet($id:ID!){account{check(id: $id){category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype}}}}`,
731+
`query CheckGet($id:ID!){account{check(id: $id){category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype},... on PackageVersionCheck{missingPackageResult,packageConstraint,packageManager,packageName,packageNameIsRegex,versionConstraintPredicate{type,value}}}}}`,
687732
`{ "id": "Z2lkOi8vb3BzbGV2ZWwvMTIzNDU2" }`,
688733
`{ "data": { "account": { "check": { "category": { "id": "Z2lkOi8vb3BzbGV2ZWwvMTIzNDU2", "name": "Performance" }, "description": "Verifies that the service has an owner defined.", "enabled": true, "filter": null, "id": "Z2lkOi8vb3BzbGV2ZWwvMTIzNDU2", "level": { "alias": "bronze", "description": "Services in this level satisfy critical checks. This is the minimum standard to ship to production.", "id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzE3", "index": 1, "name": "Bronze" }, "name": "Owner Defined", "notes": null } } } }`,
689734
),
@@ -755,12 +800,12 @@ func TestCanUpdateNotesToNull(t *testing.T) {
755800
func TestListChecks(t *testing.T) {
756801
// Arrange
757802
testRequestOne := autopilot.NewTestRequest(
758-
`query CheckList($after:String!$first:Int!){account{rubric{checks(after: $after, first: $first){nodes{category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
803+
`query CheckList($after:String!$first:Int!){account{rubric{checks(after: $after, first: $first){nodes{category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype},... on PackageVersionCheck{missingPackageResult,packageConstraint,packageManager,packageName,packageNameIsRegex,versionConstraintPredicate{type,value}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
759804
`{{ template "pagination_initial_query_variables" }}`,
760805
`{ "data": { "account": { "rubric": { "checks": { "nodes": [ { {{ template "common_check_response" }} }, { {{ template "metrics_tool_check" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
761806
)
762807
testRequestTwo := autopilot.NewTestRequest(
763-
`query CheckList($after:String!$first:Int!){account{rubric{checks(after: $after, first: $first){nodes{category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
808+
`query CheckList($after:String!$first:Int!){account{rubric{checks(after: $after, first: $first){nodes{category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype},... on PackageVersionCheck{missingPackageResult,packageConstraint,packageManager,packageName,packageNameIsRegex,versionConstraintPredicate{type,value}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
764809
`{{ template "pagination_second_query_variables" }}`,
765810
`{ "data": { "account": { "rubric": { "checks": { "nodes": [ { {{ template "owner_defined_check" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
766811
)
@@ -782,7 +827,7 @@ func TestListChecks(t *testing.T) {
782827
func TestGetMissingCheck(t *testing.T) {
783828
// Arrange
784829
testRequest := autopilot.NewTestRequest(
785-
`query CheckGet($id:ID!){account{check(id: $id){category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype}}}}`,
830+
`query CheckGet($id:ID!){account{check(id: $id){category{id,name},description,enableOn,enabled,filter{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},id,level{alias,description,id,index,name},name,notes: rawNotes,owner{... on Team{alias,id}},type,... on AlertSourceUsageCheck{alertSourceNamePredicate{type,value},alertSourceType},... on CustomEventCheck{integration{id,name,type},passPending,resultMessage,serviceSelector,successCondition},... on HasRecentDeployCheck{days},... on ManualCheck{updateFrequency{frequencyTimeScale,frequencyValue,startingDate},updateRequiresComment},... on RepositoryFileCheck{directorySearch,filePaths,fileContentsPredicate{type,value},useAbsoluteRoot},... on RepositoryGrepCheck{directorySearch,filePaths,fileContentsPredicate{type,value}},... on RepositorySearchCheck{fileExtensions,fileContentsPredicate{type,value}},... on ServiceOwnershipCheck{requireContactMethod,contactMethod,tagKey,tagPredicate{type,value}},... on ServicePropertyCheck{serviceProperty,propertyValuePredicate{type,value}},... on TagDefinedCheck{tagKey,tagPredicate{type,value}},... on ToolUsageCheck{toolCategory,toolNamePredicate{type,value},toolUrlPredicate{type,value},environmentPredicate{type,value}},... on HasDocumentationCheck{documentType,documentSubtype},... on PackageVersionCheck{missingPackageResult,packageConstraint,packageManager,packageName,packageNameIsRegex,versionConstraintPredicate{type,value}}}}}`,
786831
`{ "id": "Z2lkOi8vb3BzbGV2ZWwvQ2hlY2tzOjpIYXNPd25lci8yNDEf" }`,
787832
`{ "data": { "account": { "check": null } } }`,
788833
)

0 commit comments

Comments
 (0)