MCPcopy Create free account
hub / github.com/cloudbase/garm / WithEntityScaleSetFilter

Function WithEntityScaleSetFilter

database/watcher/filters.go:106–138  ·  view source on GitHub ↗

WithEntityScaleSetFilter returns true if the change payload is a scale set that belongs to the supplied Github entity.

(ghEntity params.ForgeEntity)

Source from the content-addressed store, hash-verified

104// WithEntityScaleSetFilter returns true if the change payload is a scale set that belongs to the
105// supplied Github entity.
106func WithEntityScaleSetFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc {
107 return func(payload dbCommon.ChangePayload) bool {
108 forgeType, err := ghEntity.GetForgeType()
109 if err != nil {
110 return false
111 }
112
113 // Gitea does not have scale sets.
114 if forgeType == params.GiteaEndpointType {
115 return false
116 }
117
118 switch payload.EntityType {
119 case dbCommon.ScaleSetEntityType:
120 scaleSet, ok := payload.Payload.(params.ScaleSet)
121 if !ok {
122 return false
123 }
124 switch ghEntity.EntityType {
125 case params.ForgeEntityTypeRepository:
126 return scaleSet.RepoID == ghEntity.ID
127 case params.ForgeEntityTypeOrganization:
128 return scaleSet.OrgID == ghEntity.ID
129 case params.ForgeEntityTypeEnterprise:
130 return scaleSet.EnterpriseID == ghEntity.ID
131 default:
132 return false
133 }
134 default:
135 return false
136 }
137 }
138}
139
140// WithEntityFilter returns a filter function that filters payloads by entity.
141// Change payloads that match the entity type and ID will return true.

Calls 1

GetForgeTypeMethod · 0.80