Skip to content

Commit 522fb6d

Browse files
committed
Add new_draft kind of labels in [autolabel]
1 parent 2aaad35 commit 522fb6d

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ pub(crate) struct AutolabelLabelConfig {
282282
pub(crate) new_pr: bool,
283283
#[serde(default)]
284284
pub(crate) new_issue: bool,
285+
#[serde(default)]
286+
pub(crate) new_draft: bool,
285287
}
286288

287289
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]

src/handlers/autolabel.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,33 @@ pub(super) async fn parse_input(
9696
}
9797
}
9898

99+
let is_opened =
100+
matches!(event.action, IssuesAction::Opened | IssuesAction::Reopened);
101+
99102
// Treat the following situations as a "new PR":
100103
// 1) PRs that were (re)opened and are not draft
101104
// 2) PRs that have been converted from a draft to being "ready for review"
102-
let is_opened_non_draft =
103-
matches!(event.action, IssuesAction::Opened | IssuesAction::Reopened)
104-
&& !event.issue.draft;
105+
let is_opened_non_draft = is_opened && !event.issue.draft;
105106
let is_ready_for_review = event.action == IssuesAction::ReadyForReview;
107+
108+
// Treat the following situations as a "new draft":
109+
// 1) PRs that were (re)opened and are draft
110+
// 2) PRs that have been converted to a draft
111+
let is_opened_as_draft = is_opened && event.issue.draft;
112+
let is_converted_to_draft = event.action == IssuesAction::ConvertedToDraft;
113+
106114
if cfg.new_pr && (is_opened_non_draft || is_ready_for_review) {
107115
autolabels.push(Label {
108116
name: label.to_owned(),
109117
});
118+
} else if cfg.new_draft && (is_opened_as_draft || is_converted_to_draft) {
119+
autolabels.push(Label {
120+
name: label.to_owned(),
121+
});
110122
}
111123

112-
// If a PR is converted to draft or closed, remove all the "new PR" labels
124+
// If a PR is converted to draft or closed, remove all the "new PR" labels.
125+
// Same for "new draft" labels when the PR is ready for review or closed.
113126
if cfg.new_pr
114127
&& matches!(
115128
event.action,
@@ -119,6 +132,15 @@ pub(super) async fn parse_input(
119132
to_remove.push(Label {
120133
name: label.to_owned(),
121134
});
135+
} else if cfg.new_draft
136+
&& matches!(
137+
event.action,
138+
IssuesAction::ReadyForReview | IssuesAction::Closed
139+
)
140+
{
141+
to_remove.push(Label {
142+
name: label.to_owned(),
143+
});
122144
}
123145
} else {
124146
if cfg.new_issue && event.action == IssuesAction::Opened {

0 commit comments

Comments
 (0)