Skip to content

Commit 7fb447a

Browse files
committed
no-merges: match titles instead of labels
also don't re-add labels if they're manually removed labels are not always set atomically when opening a PR example: rust-lang/miri#3059
1 parent b53466e commit 7fb447a

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ impl AssignConfig {
105105

106106
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
107107
pub(crate) struct NoMergesConfig {
108-
/// No action will be taken on PRs with these labels.
108+
/// No action will be taken on PRs with these substrings in the title.
109109
#[serde(default)]
110-
pub(crate) exclude_labels: Vec<String>,
110+
pub(crate) exclude_titles: Vec<String>,
111111
/// Set these labels on the PR when merge commits are detected.
112112
#[serde(default)]
113113
pub(crate) labels: Vec<String>,

src/handlers/no_merges.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ pub(super) async fn parse_input(
4848
return Ok(None);
4949
}
5050

51-
// Don't trigger if the PR has any of the excluded labels.
52-
for label in event.issue.labels() {
53-
if config.exclude_labels.contains(&label.name) {
54-
return Ok(None);
55-
}
51+
// Don't trigger if the PR has any of the excluded title segments.
52+
if config
53+
.exclude_titles
54+
.iter()
55+
.any(|s| event.issue.title.contains(s))
56+
{
57+
return Ok(None);
5658
}
5759

5860
let mut merge_commits = HashSet::new();
@@ -70,12 +72,11 @@ pub(super) async fn parse_input(
7072
}
7173
}
7274

73-
let input = NoMergesInput { merge_commits };
74-
Ok(if input.merge_commits.is_empty() {
75-
None
76-
} else {
77-
Some(input)
78-
})
75+
if merge_commits.is_empty() {
76+
return Ok(None);
77+
}
78+
79+
Ok(Some(NoMergesInput { merge_commits }))
7980
}
8081

8182
const DEFAULT_MESSAGE: &str = "
@@ -102,14 +103,15 @@ pub(super) async fn handle_input(
102103
let mut client = ctx.db.get().await;
103104
let mut state: IssueData<'_, NoMergesState> =
104105
IssueData::load(&mut client, &event.issue, NO_MERGES_KEY).await?;
106+
let first_time = state.data.mentioned_merge_commits.is_empty();
105107

106108
let mut message = config
107109
.message
108110
.as_deref()
109111
.unwrap_or(DEFAULT_MESSAGE)
110112
.to_string();
111113

112-
let since_last_posted = if state.data.mentioned_merge_commits.is_empty() {
114+
let since_last_posted = if first_time {
113115
""
114116
} else {
115117
" (since this message was last posted)"
@@ -132,6 +134,22 @@ pub(super) async fn handle_input(
132134
}
133135

134136
if should_send {
137+
if !first_time {
138+
// Check if the labels are still set.
139+
// Otherwise, they were probably removed manually.
140+
let any_removed = config.labels.iter().any(|label| {
141+
// No label on the issue matches.
142+
event.issue.labels().iter().all(|l| &l.name != label)
143+
});
144+
145+
if any_removed {
146+
// Assume it was a false positive, so don't
147+
// re-add the labels or send a message this time.
148+
state.save().await?;
149+
return Ok(());
150+
}
151+
}
152+
135153
// Set labels
136154
let labels = config
137155
.labels

0 commit comments

Comments
 (0)