Skip to content

Commit e1decff

Browse files
committed
Remove new_pr labels when converting to draft
1 parent 5b1ca24 commit e1decff

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/handlers/autolabel.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ pub(super) async fn parse_input(
3939
// synchronize may be straddling a rebase, which will break diff generation.
4040
if matches!(
4141
event.action,
42-
IssuesAction::Opened | IssuesAction::Synchronize | IssuesAction::ReadyForReview
42+
IssuesAction::Opened
43+
| IssuesAction::Synchronize
44+
| IssuesAction::ReadyForReview
45+
| IssuesAction::ConvertedToDraft
4346
) {
4447
let mut db = ctx.db.get().await;
4548
let mut state: IssueData<'_, AutolabelState> =
@@ -55,7 +58,9 @@ pub(super) async fn parse_input(
5558
log::error!("failed to fetch diff: {:?}", e);
5659
})
5760
.unwrap_or_default();
61+
5862
let mut autolabels = Vec::new();
63+
let mut to_remove = Vec::new();
5964

6065
'outer: for (label, cfg) in config.labels.iter() {
6166
let exclude_patterns: Vec<glob::Pattern> = cfg
@@ -108,6 +113,14 @@ pub(super) async fn parse_input(
108113
});
109114
state.data.new_pr_labels_applied = true;
110115
}
116+
117+
// If a PR is converted to draft remove all the "new PR" labels
118+
if cfg.new_pr && event.action == IssuesAction::ConvertedToDraft {
119+
to_remove.push(Label {
120+
name: label.to_owned(),
121+
});
122+
state.data.new_pr_labels_applied = false;
123+
}
111124
} else {
112125
if cfg.new_issue && event.action == IssuesAction::Opened {
113126
autolabels.push(Label {
@@ -119,10 +132,10 @@ pub(super) async fn parse_input(
119132

120133
state.save().await.map_err(|e| e.to_string())?;
121134

122-
if !autolabels.is_empty() {
135+
if !autolabels.is_empty() || !to_remove.is_empty() {
123136
return Ok(Some(AutolabelInput {
124137
add: autolabels,
125-
remove: vec![],
138+
remove: to_remove,
126139
}));
127140
}
128141
}

0 commit comments

Comments
 (0)