Skip to content

Commit 8b64cbd

Browse files
jamesadevineCopilot
andcommitted
feat(ir): wire SonarQubePublish@8 builder into task-step validation
Integrates the SonarQubePublish@8 typed builder with the front-matter task-step advisory validation added in #1096: derives Deserialize keyed on the ADO pollingTimeoutSec input (deny_unknown_fields, flex str/int) and registers it in parse.rs VALIDATORS. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6af919d commit 8b64cbd

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/compile/ir/tasks/parse.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use super::{
3737
helm_installer, java_tool_installer, manual_validation, maven, maven_authenticate, node_tool,
3838
npm, npm_authenticate, nuget_authenticate, nuget_command, pip_authenticate, powershell,
3939
publish_build_artifacts, publish_code_coverage_results, publish_pipeline_artifact,
40-
publish_test_results, python_script, twine_authenticate, universal_packages, use_dotnet,
41-
use_node, use_python_version, use_ruby_version, vs_build, vstest,
40+
publish_test_results, python_script, sonar_qube_publish, twine_authenticate, universal_packages,
41+
use_dotnet, use_node, use_python_version, use_ruby_version, vs_build, vstest,
4242
};
4343

4444
/// Registry mapping an ADO task id (`"CopyFiles@2"`) to a validator that checks
@@ -93,6 +93,7 @@ const VALIDATORS: &[(&str, fn(Value) -> Result<(), String>)] = &[
9393
validate_by_deserialize::<publish_pipeline_artifact::PublishPipelineArtifact>,
9494
),
9595
("PublishTestResults@2", validate_by_deserialize::<publish_test_results::PublishTestResults>),
96+
("SonarQubePublish@8", validate_by_deserialize::<sonar_qube_publish::SonarQubePublish>),
9697
("TwineAuthenticate@1", validate_by_deserialize::<twine_authenticate::TwineAuthenticate>),
9798
("UseDotNet@2", validate_by_deserialize::<use_dotnet::UseDotNet>),
9899
("UseNode@1", validate_by_deserialize::<use_node::UseNode>),
@@ -690,6 +691,29 @@ mod tests {
690691
assert!(err.contains("NodeTool@0"), "got: {err}");
691692
}
692693

694+
#[test]
695+
fn roundtrip_sonar_qube_publish() {
696+
assert_roundtrips(sonar_qube_publish::SonarQubePublish::new().into_step());
697+
assert_roundtrips(
698+
sonar_qube_publish::SonarQubePublish::new()
699+
.polling_timeout_sec(600)
700+
.into_step(),
701+
);
702+
}
703+
704+
#[test]
705+
fn sonar_qube_publish_unknown_input_warns() {
706+
let step = yaml(
707+
r#"
708+
task: SonarQubePublish@8
709+
inputs:
710+
bogusInput: nope
711+
"#,
712+
);
713+
let err = validate_task_step(&step).expect("recognized").unwrap_err();
714+
assert!(err.contains("SonarQubePublish@8"), "got: {err}");
715+
}
716+
693717
#[test]
694718
fn registry_has_no_duplicate_task_ids() {
695719
let mut ids: Vec<&str> = VALIDATORS.iter().map(|(id, _)| *id).collect();

src/compile/ir/tasks/sonar_qube_publish.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Typed builder for `SonarQubePublish@8`.
22
33
use crate::compile::ir::step::TaskStep;
4+
use serde::Deserialize;
45

56
/// Builder for a [`TaskStep`] invoking `SonarQubePublish@8`.
67
///
@@ -13,9 +14,16 @@ use crate::compile::ir::step::TaskStep;
1314
///
1415
/// ADO task reference:
1516
/// <https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/sonar-qube-publish-v8-task>
16-
#[derive(Debug, Clone)]
17+
#[derive(Debug, Clone, Deserialize)]
18+
#[serde(deny_unknown_fields)]
1719
pub struct SonarQubePublish {
18-
polling_timeout_sec: Option<u32>,
20+
#[serde(
21+
rename = "pollingTimeoutSec",
22+
default,
23+
deserialize_with = "super::common::de_opt_str_or_int"
24+
)]
25+
polling_timeout_sec: Option<String>,
26+
#[serde(skip)]
1927
display_name: Option<String>,
2028
}
2129

@@ -35,7 +43,7 @@ impl SonarQubePublish {
3543
/// `pollingTimeoutSec` — maximum seconds to wait for the Quality Gate
3644
/// result. ADO default is `300`.
3745
pub fn polling_timeout_sec(mut self, secs: u32) -> Self {
38-
self.polling_timeout_sec = Some(secs);
46+
self.polling_timeout_sec = Some(secs.to_string());
3947
self
4048
}
4149

@@ -53,7 +61,7 @@ impl SonarQubePublish {
5361
.unwrap_or_else(|| "Publish Quality Gate Result".into()),
5462
);
5563
if let Some(secs) = self.polling_timeout_sec {
56-
t = t.with_input("pollingTimeoutSec", secs.to_string());
64+
t = t.with_input("pollingTimeoutSec", secs);
5765
}
5866
t
5967
}

0 commit comments

Comments
 (0)