Skip to content

Commit

Permalink
Merge pull request #41 from DataDog/juli1/add-short-description
Browse files Browse the repository at this point in the history
add short description to the rule
  • Loading branch information
juli1 authored Jul 26, 2023
2 parents 70c573b + 670b83a commit 46bb0c2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [
]

[workspace.package]
version = "0.0.5"
version = "0.0.6"

[profile.release]
lto = true
Expand Down
17 changes: 15 additions & 2 deletions cli/src/sarif/sarif_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,27 @@ impl IntoSarif for &Rule {
.decode(d.as_bytes())
.unwrap();
let text_description =
std::str::from_utf8(&decrypted_description).unwrap_or("invalid description");
std::str::from_utf8(&decrypted_description).unwrap_or("invalid full description");
let text = sarif::MultiformatMessageStringBuilder::default()
.text(std::str::from_utf8(text_description.as_bytes()).unwrap())
.build()
.unwrap();
builder.full_description(text);
}

if let Some(d) = self.short_description_base64.as_ref() {
let decrypted_description = base64::engine::general_purpose::STANDARD
.decode(d.as_bytes())
.unwrap();
let text_description =
std::str::from_utf8(&decrypted_description).unwrap_or("invalid short description");
let text = sarif::MultiformatMessageStringBuilder::default()
.text(std::str::from_utf8(text_description.as_bytes()).unwrap())
.build()
.unwrap();
builder.short_description(text);
}

builder.help_uri(self.get_url()).build().unwrap()
}
}
Expand Down Expand Up @@ -331,7 +344,7 @@ mod tests {
println!("{}", sarif_report_to_string);
assert_json_eq!(
sarif_report_to_string,
serde_json::json!({"runs":[{"results":[{"fixes":[{"artifactChanges":[{"artifactLocation":{"uri":"myfile"},"replacements":[{"deletedRegion":{"endColumn":6,"endLine":6,"startColumn":6,"startLine":6},"insertedContent":{"text":"newcontent"}}]}],"description":{"text":"myfix"}}],"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"uri":"myfile"},"region":{"endColumn":4,"endLine":3,"startColumn":2,"startLine":1}}}],"message":{"text":"violation message"},"properties":{"tags":["DATADOG_CATEGORY:BEST_PRACTICES"]},"ruleId":"my-rule","ruleIndex":0}],"tool":{"driver":{"informationUri":"https://www.datadoghq.com","name":"datadog-static-analyzer","rules":[{"fullDescription":{"text":"awesome rule"},"helpUri":"https://static-analysis.datadoghq.com/my-rule","id":"my-rule"}]}}}],"version":"2.1.0"})
serde_json::json!({"runs":[{"results":[{"fixes":[{"artifactChanges":[{"artifactLocation":{"uri":"myfile"},"replacements":[{"deletedRegion":{"endColumn":6,"endLine":6,"startColumn":6,"startLine":6},"insertedContent":{"text":"newcontent"}}]}],"description":{"text":"myfix"}}],"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"uri":"myfile"},"region":{"endColumn":4,"endLine":3,"startColumn":2,"startLine":1}}}],"message":{"text":"violation message"},"properties":{"tags":["DATADOG_CATEGORY:BEST_PRACTICES"]},"ruleId":"my-rule","ruleIndex":0}],"tool":{"driver":{"informationUri":"https://www.datadoghq.com","name":"datadog-static-analyzer","rules":[{"fullDescription":{"text":"awesome rule"},"helpUri":"https://docs.datadoghq.com/continuous_integration/static_analysis/rules/my-rule","id":"my-rule","shortDescription":{"text":"short description"}}]}}}],"version":"2.1.0"})
);

// validate the schema
Expand Down
5 changes: 4 additions & 1 deletion kernel/src/model/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ pub struct RuleInternal {

impl Rule {
pub fn get_url(&self) -> String {
format!("https://static-analysis.datadoghq.com/{}", self.name)
format!(
"https://docs.datadoghq.com/continuous_integration/static_analysis/rules/{}",
self.name
)
}

fn decode_description(&self) -> anyhow::Result<Option<String>> {
Expand Down
13 changes: 13 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
{
"0": [
{
"0.0.6": {
"windows": {
"x86_64": "https://github.com/DataDog/datadog-static-analyzer/releases/download/0.0.6/datadog-static-analyzer-x86_64-pc-windows-msvc.zip"
},
"linux": {
"x86_64": "https://github.com/DataDog/datadog-static-analyzer/releases/download/0.0.6/datadog-static-analyzer-x86_64-unknown-linux-gnu.zip",
"aarch64": "https://github.com/DataDog/datadog-static-analyzer/releases/download/0.0.6/datadog-static-analyzer-aarch64-unknown-linux-gnu.zip"
},
"macos": {
"x86_64": "https://github.com/DataDog/datadog-static-analyzer/releases/download/0.0.6/datadog-static-analyzer-x86_64-apple-darwin.zip",
"aarch64": "https://github.com/DataDog/datadog-static-analyzer/releases/download/0.0.6/datadog-static-analyzer-aarch64-apple-darwin.zip"
}
},
"0.0.5": {
"windows": {
"x86_64": "https://github.com/DataDog/datadog-static-analyzer/releases/download/0.0.5/datadog-static-analyzer-x86_64-pc-windows-msvc.zip"
Expand Down

0 comments on commit 46bb0c2

Please sign in to comment.