Skip to content

Commit d58dbeb

Browse files
fix(create-pr): skip auto-complete API call on draft PRs (#194) (#200)
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>
1 parent b0ae590 commit d58dbeb

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/safeoutputs/create_pr.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,8 +1391,9 @@ impl Executor for CreatePrResult {
13911391
}
13921392
});
13931393

1394-
// Only set autoCompleteSetBy if auto_complete is enabled
1395-
if config.auto_complete {
1394+
// Only set autoCompleteSetBy if auto_complete is enabled and PR is not a draft
1395+
// (ADO silently ignores auto-complete on draft PRs, so skip the API call)
1396+
if config.auto_complete && !config.draft {
13961397
update_body["autoCompleteSetBy"] = serde_json::json!({
13971398
"id": pr_data["createdBy"]["id"]
13981399
});
@@ -2253,4 +2254,23 @@ new file mode 100755
22532254
assert!(!paths.contains(&"/dev/null".to_string()));
22542255
}
22552256

2257+
#[test]
2258+
fn test_default_config_draft_true_autocomplete_false() {
2259+
let config = CreatePrConfig::default();
2260+
assert!(config.draft, "draft should default to true");
2261+
assert!(!config.auto_complete, "auto_complete should default to false");
2262+
}
2263+
2264+
#[test]
2265+
fn test_config_deserialize_draft_false_autocomplete_true() {
2266+
let yaml = r#"
2267+
target-branch: main
2268+
draft: false
2269+
auto-complete: true
2270+
"#;
2271+
let config: CreatePrConfig = serde_yaml::from_str(yaml).unwrap();
2272+
assert!(!config.draft);
2273+
assert!(config.auto_complete);
2274+
}
2275+
22562276
}

0 commit comments

Comments
 (0)