Skip to content

Commit f8d45c0

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 9ea655c commit f8d45c0

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-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: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ 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.exclude_titles.iter().any(|s| event.issue.title.contains(s)) {
53+
return Ok(None);
5654
}
5755

5856
let mut merge_commits = HashSet::new();
@@ -70,12 +68,11 @@ pub(super) async fn parse_input(
7068
}
7169
}
7270

73-
let input = NoMergesInput { merge_commits };
74-
Ok(if input.merge_commits.is_empty() {
75-
None
76-
} else {
77-
Some(input)
78-
})
71+
if merge_commits.is_empty() {
72+
return Ok(None);
73+
}
74+
75+
Ok(Some(NoMergesInput { merge_commits }))
7976
}
8077

8178
const DEFAULT_MESSAGE: &str = "
@@ -102,14 +99,15 @@ pub(super) async fn handle_input(
10299
let mut client = ctx.db.get().await;
103100
let mut state: IssueData<'_, NoMergesState> =
104101
IssueData::load(&mut client, &event.issue, NO_MERGES_KEY).await?;
102+
let first_time = state.data.mentioned_merge_commits.is_empty();
105103

106104
let mut message = config
107105
.message
108106
.as_deref()
109107
.unwrap_or(DEFAULT_MESSAGE)
110108
.to_string();
111109

112-
let since_last_posted = if state.data.mentioned_merge_commits.is_empty() {
110+
let since_last_posted = if first_time {
113111
""
114112
} else {
115113
" (since this message was last posted)"
@@ -132,6 +130,17 @@ pub(super) async fn handle_input(
132130
}
133131

134132
if should_send {
133+
if !first_time {
134+
// Check if the labels are already set.
135+
// Otherwise, they were probably removed manually.
136+
if !event.issue.labels().iter().all(|label| config.labels.contains(&label.name)) {
137+
// Assume it was a false positive, so don't
138+
// re-add the labels or send a message this time.
139+
state.save().await?;
140+
return Ok(());
141+
}
142+
}
143+
135144
// Set labels
136145
let labels = config
137146
.labels

0 commit comments

Comments
 (0)