From 2c127be3549399b9a665a6028b3420480fc5736a Mon Sep 17 00:00:00 2001 From: James Devine Date: Tue, 14 Apr 2026 21:35:02 +0100 Subject: [PATCH] fix(create-pr): skip auto-complete API call on draft PRs (#194) When both draft: true and auto-complete: true are configured, skip the autoCompleteSetBy API call since ADO silently ignores auto-complete on draft PRs. The existing warning is preserved so operators are aware of the conflict. This prevents a pointless API call and avoids silent behavior loss when draft: true became the default in PR #155. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/safeoutputs/create_pr.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/safeoutputs/create_pr.rs b/src/safeoutputs/create_pr.rs index 54d7ef9..206fe77 100644 --- a/src/safeoutputs/create_pr.rs +++ b/src/safeoutputs/create_pr.rs @@ -1391,8 +1391,9 @@ impl Executor for CreatePrResult { } }); - // Only set autoCompleteSetBy if auto_complete is enabled - if config.auto_complete { + // Only set autoCompleteSetBy if auto_complete is enabled and PR is not a draft + // (ADO silently ignores auto-complete on draft PRs, so skip the API call) + if config.auto_complete && !config.draft { update_body["autoCompleteSetBy"] = serde_json::json!({ "id": pr_data["createdBy"]["id"] }); @@ -2253,4 +2254,23 @@ new file mode 100755 assert!(!paths.contains(&"/dev/null".to_string())); } + #[test] + fn test_default_config_draft_true_autocomplete_false() { + let config = CreatePrConfig::default(); + assert!(config.draft, "draft should default to true"); + assert!(!config.auto_complete, "auto_complete should default to false"); + } + + #[test] + fn test_config_deserialize_draft_false_autocomplete_true() { + let yaml = r#" + target-branch: main + draft: false + auto-complete: true + "#; + let config: CreatePrConfig = serde_yaml::from_str(yaml).unwrap(); + assert!(!config.draft); + assert!(config.auto_complete); + } + }