mirror of
https://github.com/modrinth/code.git
synced 2026-09-03 05:25:58 +00:00
flatten input context
This commit is contained in:
@@ -64,7 +64,7 @@
|
|||||||
<div v-else class="mt-3 grid gap-3 md:grid-cols-2">
|
<div v-else class="mt-3 grid gap-3 md:grid-cols-2">
|
||||||
<div class="min-w-0">
|
<div class="min-w-0">
|
||||||
<p class="m-0 mb-2 text-xs font-semibold uppercase tracking-wide text-secondary">
|
<p class="m-0 mb-2 text-xs font-semibold uppercase tracking-wide text-secondary">
|
||||||
Input (<code>input</code>)
|
Context
|
||||||
</p>
|
</p>
|
||||||
<pre
|
<pre
|
||||||
class="m-0 overflow-x-auto rounded-lg bg-surface-1 p-3 text-xs leading-relaxed text-contrast"
|
class="m-0 overflow-x-auto rounded-lg bg-surface-1 p-3 text-xs leading-relaxed text-contrast"
|
||||||
@@ -428,7 +428,7 @@ import type { Component } from 'vue'
|
|||||||
|
|
||||||
import IssueDetailPath from '~/components/ui/moderation/IssueDetailPath.vue'
|
import IssueDetailPath from '~/components/ui/moderation/IssueDetailPath.vue'
|
||||||
|
|
||||||
const DEFAULT_RULE = `input.trace.issue_type == "OBFUSCATED_NAMES"
|
const DEFAULT_RULE = `trace.issue_type == "OBFUSCATED_NAMES"
|
||||||
? {"severity": "low"}
|
? {"severity": "low"}
|
||||||
: null`
|
: null`
|
||||||
const RULE_EDITOR_OPTIONS: Partial<Ace.EditorOptions> = {
|
const RULE_EDITOR_OPTIONS: Partial<Ace.EditorOptions> = {
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ pub struct DelphiRuleSchemaResponse {
|
|||||||
pub components: BTreeMap<String, serde_json::Value>,
|
pub components: BTreeMap<String, serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the schemas for the CEL input and output values.
|
/// Get the schemas for the CEL context and output values.
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
context_path = "/moderation/tech-review",
|
context_path = "/moderation/tech-review",
|
||||||
tag = "moderation",
|
tag = "moderation",
|
||||||
@@ -800,12 +800,24 @@ async fn insert_materialized_effects(
|
|||||||
|
|
||||||
pub(super) fn evaluate_rule(
|
pub(super) fn evaluate_rule(
|
||||||
program: &cel::Program,
|
program: &cel::Program,
|
||||||
input: impl Serialize,
|
input: &RuleInput,
|
||||||
) -> Result<Option<DelphiRuleEffect>> {
|
) -> Result<Option<DelphiRuleEffect>> {
|
||||||
let mut context = cel::Context::default();
|
let mut context = cel::Context::default();
|
||||||
context
|
context
|
||||||
.add_variable("input", input)
|
.add_variable("schema_version", input.schema_version)
|
||||||
.wrap_err("failed to build cel input")?;
|
.wrap_err("failed to add `schema_version` to cel context")?;
|
||||||
|
context
|
||||||
|
.add_variable("trace", &input.trace)
|
||||||
|
.wrap_err("failed to add `trace` to cel context")?;
|
||||||
|
context
|
||||||
|
.add_variable("scan", &input.scan)
|
||||||
|
.wrap_err("failed to add `scan` to cel context")?;
|
||||||
|
context
|
||||||
|
.add_variable("artifact", &input.artifact)
|
||||||
|
.wrap_err("failed to add `artifact` to cel context")?;
|
||||||
|
context
|
||||||
|
.add_variable("scope", &input.scope)
|
||||||
|
.wrap_err("failed to add `scope` to cel context")?;
|
||||||
|
|
||||||
let value = program
|
let value = program
|
||||||
.execute(&context)
|
.execute(&context)
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use cel::{Context, Program};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
const EFFECT_RULE: &str = r#"
|
const EFFECT_RULE: &str = r#"
|
||||||
input.trace.issue_type == "OBFUSCATED_NAMES"
|
trace.issue_type == "OBFUSCATED_NAMES"
|
||||||
&& input.trace.severity == "high"
|
&& trace.severity == "high"
|
||||||
&& "confidence" in input.trace.data
|
&& "confidence" in trace.data
|
||||||
&& input.trace.data.confidence >= 0.9
|
&& trace.data.confidence >= 0.9
|
||||||
? {
|
? {
|
||||||
"severity": "low"
|
"severity": "low"
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,11 @@ fn evaluate_rule(
|
|||||||
input: &RuleInput,
|
input: &RuleInput,
|
||||||
) -> Result<Option<RuleEffect>, Box<dyn Error>> {
|
) -> Result<Option<RuleEffect>, Box<dyn Error>> {
|
||||||
let mut context = Context::default();
|
let mut context = Context::default();
|
||||||
context.add_variable("input", input)?;
|
context.add_variable("schema_version", input.schema_version)?;
|
||||||
|
context.add_variable("trace", &input.trace)?;
|
||||||
|
context.add_variable("scan", &input.scan)?;
|
||||||
|
context.add_variable("artifact", &input.artifact)?;
|
||||||
|
context.add_variable("scope", &input.scope)?;
|
||||||
|
|
||||||
let value = Program::compile(expression)?.execute(&context)?;
|
let value = Program::compile(expression)?.execute(&context)?;
|
||||||
let json = value
|
let json = value
|
||||||
|
|||||||
Reference in New Issue
Block a user