Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -45,8 +45,9 @@ export const CombinationsTable: React.FC<{
([key, value]) => ({
type: "metadata",
key,
value,
operator: "equals",
...(value != null
? { value, operator: "equals" }
: { operator: "null" }),
}),
),
}),
Expand Down
6 changes: 3 additions & 3 deletions packages/validators/src/conditions/metadata-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type NullCondition = z.infer<typeof nullCondition>;
export const equalsCondition = z.object({
type: z.literal("metadata"),
key: z.string().min(1),
value: z.string().min(1),
value: z.string(),
operator: z.literal("equals").optional(),
});

Expand All @@ -21,7 +21,7 @@ export type EqualCondition = z.infer<typeof equalsCondition>;
export const regexCondition = z.object({
type: z.literal("metadata"),
key: z.string().min(1),
value: z.string().min(1),
value: z.string(),
operator: z.literal("regex"),
});

Expand All @@ -30,7 +30,7 @@ export type RegexCondition = z.infer<typeof regexCondition>;
export const likeCondition = z.object({
type: z.literal("metadata"),
key: z.string().min(1),
value: z.string().min(1),
value: z.string(),
operator: z.literal("like"),
});

Expand Down
2 changes: 1 addition & 1 deletion packages/validators/src/jobs/conditions/job-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const isValidJobCondition = (condition: JobCondition): boolean => {
if (isMetadataCondition(condition)) {
if (condition.operator === MetadataOperator.Null)
return condition.value == null && condition.key.length > 0;
return condition.value.length > 0 && condition.key.length > 0;
return condition.key.length > 0;
}
return condition.value.length > 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const isValidReleaseCondition = (
if (isMetadataCondition(condition)) {
if (condition.operator === ReleaseOperator.Null)
return condition.value == null && condition.key.length > 0;
return condition.value.length > 0 && condition.key.length > 0;
return condition.key.length > 0;
}
return false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const isValidTargetCondition = (
if (isMetadataCondition(condition)) {
if (condition.operator === ResourceOperator.Null)
return condition.value == null && condition.key.length > 0;
return condition.value.length > 0 && condition.key.length > 0;
return condition.key.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Similar changes needed in job and release conditions

The verification revealed that the same validation pattern exists in other condition validators:

  • packages/validators/src/jobs/conditions/job-condition.ts
  • packages/validators/src/releases/conditions/release-condition.ts

These files still enforce non-empty values for metadata conditions, which is inconsistent with the change being made in resource conditions. This could lead to inconsistent behavior across different condition types.

🔗 Analysis chain

LGTM! Verify impact on downstream consumers.

The change correctly implements the requirement to allow empty strings for metadata condition values while maintaining proper validation for the key. This aligns with the PR objective.

Let's verify the impact on downstream consumers:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct usage of isValidTargetCondition to identify potential impacts
rg -A 3 "isValidTargetCondition" --type typescript

# Search for metadata condition value usage patterns
ast-grep --pattern 'condition.value.length'

Length of output: 476


Script:

#!/bin/bash
# Let's search for the usage context of these conditions with more lines of context
rg -B 3 -A 5 "condition\.value\.length" .

# Also search for imports or references to resource-condition
rg -l "resource-condition" .

Length of output: 2121

}
return condition.value.length > 0;
};
Loading