Skip to content

Add new_draft kind of labels in [autolabel] #2104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ pub(crate) struct AutolabelLabelConfig {
pub(crate) new_pr: bool,
#[serde(default)]
pub(crate) new_issue: bool,
#[serde(default)]
pub(crate) new_draft: bool,
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
Expand Down
30 changes: 26 additions & 4 deletions src/handlers/autolabel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,33 @@ pub(super) async fn parse_input(
}
}

let is_opened =
matches!(event.action, IssuesAction::Opened | IssuesAction::Reopened);

// Treat the following situations as a "new PR":
// 1) PRs that were (re)opened and are not draft
// 2) PRs that have been converted from a draft to being "ready for review"
let is_opened_non_draft =
matches!(event.action, IssuesAction::Opened | IssuesAction::Reopened)
&& !event.issue.draft;
let is_opened_non_draft = is_opened && !event.issue.draft;
let is_ready_for_review = event.action == IssuesAction::ReadyForReview;

// Treat the following situations as a "new draft":
// 1) PRs that were (re)opened and are draft
// 2) PRs that have been converted to a draft
let is_opened_as_draft = is_opened && event.issue.draft;
let is_converted_to_draft = event.action == IssuesAction::ConvertedToDraft;

if cfg.new_pr && (is_opened_non_draft || is_ready_for_review) {
autolabels.push(Label {
name: label.to_owned(),
});
} else if cfg.new_draft && (is_opened_as_draft || is_converted_to_draft) {
autolabels.push(Label {
name: label.to_owned(),
});
}

// If a PR is converted to draft or closed, remove all the "new PR" labels
// If a PR is converted to draft or closed, remove all the "new PR" labels.
// Same for "new draft" labels when the PR is ready for review or closed.
if cfg.new_pr
&& matches!(
event.action,
Expand All @@ -119,6 +132,15 @@ pub(super) async fn parse_input(
to_remove.push(Label {
name: label.to_owned(),
});
} else if cfg.new_draft
&& matches!(
event.action,
IssuesAction::ReadyForReview | IssuesAction::Closed
)
{
to_remove.push(Label {
name: label.to_owned(),
});
}
} else {
if cfg.new_issue && event.action == IssuesAction::Opened {
Expand Down
Loading