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

Add evaluation_failure_message to ruletypes #4433

Merged
merged 8 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Copyright 2024 Stacklok, Inc
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- Adds a `short_failure_message` column to the `rule_type` table. The failure message
-- is displayed to the user when a rule evaluation fails.
ALTER TABLE rule_type ADD COLUMN short_failure_message TEXT NOT NULL DEFAULT '';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright 2024 Stacklok, Inc
eleftherias marked this conversation as resolved.
Show resolved Hide resolved
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE rule_type DROP COLUMN short_failure_message;
8 changes: 5 additions & 3 deletions database/query/rule_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ INSERT INTO rule_type (
severity_value,
subscription_id,
display_name,
release_phase
release_phase,
short_failure_message
) VALUES (
$1,
$2,
Expand All @@ -18,7 +19,8 @@ INSERT INTO rule_type (
sqlc.arg(severity_value),
sqlc.narg(subscription_id),
sqlc.arg(display_name),
sqlc.arg(release_phase)
sqlc.arg(release_phase),
sqlc.arg(short_failure_message)
) RETURNING *;

-- name: ListRuleTypesByProject :many
Expand All @@ -35,7 +37,7 @@ DELETE FROM rule_type WHERE id = $1;

-- name: UpdateRuleType :one
UPDATE rule_type
SET description = $2, definition = sqlc.arg(definition)::jsonb, severity_value = sqlc.arg(severity_value), display_name = sqlc.arg(display_name), release_phase = sqlc.arg(release_phase)
SET description = $2, definition = sqlc.arg(definition)::jsonb, severity_value = sqlc.arg(severity_value), display_name = sqlc.arg(display_name), release_phase = sqlc.arg(release_phase), short_failure_message = sqlc.arg(short_failure_message)
WHERE id = $1
RETURNING *;

Expand Down
1 change: 1 addition & 0 deletions docs/docs/ref/proto.md

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

29 changes: 15 additions & 14 deletions internal/db/models.go

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

60 changes: 36 additions & 24 deletions internal/db/rule_types.sql.go

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

36 changes: 19 additions & 17 deletions internal/ruletypes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,18 @@ func (_ *ruleTypeService) CreateRuleType(
return nil, err
}

ruleType = ruleType.WithDefaultDisplayName()
ruleType = ruleType.WithDefaultDisplayName().WithDefaultShortFailureMessage()
newDBRecord, err := qtx.CreateRuleType(ctx, db.CreateRuleTypeParams{
Name: ruleTypeName,
DisplayName: ruleType.GetDisplayName(),
ProjectID: projectID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
Guidance: ruleType.GetGuidance(),
SeverityValue: *severity,
SubscriptionID: uuid.NullUUID{UUID: subscriptionID, Valid: subscriptionID != uuid.Nil},
ReleasePhase: *releasePhase,
Name: ruleTypeName,
DisplayName: ruleType.GetDisplayName(),
ShortFailureMessage: ruleType.GetShortFailureMessage(),
ProjectID: projectID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
Guidance: ruleType.GetGuidance(),
SeverityValue: *severity,
SubscriptionID: uuid.NullUUID{UUID: subscriptionID, Valid: subscriptionID != uuid.Nil},
ReleasePhase: *releasePhase,
})
if err != nil {
return nil, fmt.Errorf("failed to create rule type: %w", err)
Expand Down Expand Up @@ -225,14 +226,15 @@ func (_ *ruleTypeService) UpdateRuleType(
return nil, err
}

ruleType = ruleType.WithDefaultDisplayName()
ruleType = ruleType.WithDefaultDisplayName().WithDefaultShortFailureMessage()
updatedRuleType, err := qtx.UpdateRuleType(ctx, db.UpdateRuleTypeParams{
ID: oldRuleType.ID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
SeverityValue: *severity,
DisplayName: ruleType.GetDisplayName(),
ReleasePhase: *releasePhase,
ID: oldRuleType.ID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
SeverityValue: *severity,
DisplayName: ruleType.GetDisplayName(),
ShortFailureMessage: ruleType.GetShortFailureMessage(),
ReleasePhase: *releasePhase,
})
if err != nil {
return nil, fmt.Errorf("failed to update rule type: %w", err)
Expand Down
Loading
Loading