Skip to content
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
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ impl AssignConfig {

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
pub(crate) struct NoMergesConfig {
/// No action will be taken on PRs with these labels.
/// No action will be taken on PRs with these substrings in the title.
#[serde(default)]
pub(crate) exclude_labels: Vec<String>,
pub(crate) exclude_titles: Vec<String>,
/// Set these labels on the PR when merge commits are detected.
#[serde(default)]
pub(crate) labels: Vec<String>,
Expand Down
42 changes: 30 additions & 12 deletions src/handlers/no_merges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ pub(super) async fn parse_input(
return Ok(None);
}

// Don't trigger if the PR has any of the excluded labels.
for label in event.issue.labels() {
if config.exclude_labels.contains(&label.name) {
return Ok(None);
}
// Don't trigger if the PR has any of the excluded title segments.
if config
.exclude_titles
.iter()
.any(|s| event.issue.title.contains(s))
Comment on lines +52 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to not make this case-insensitive? Seems like making it insensitive could make it a little less likely to have false-positives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously it makes the implementation more complicated, but the real reason is that it reduces specificity.

Capitalization can be used to disambiguate. For example, on rust-clippy, using the capitalized "Rustup" disambiguates between PRs updating from rust and ones just mentioning "rustup"

Since only the first letter in a word is capitalized, generally it only takes a couple more entries to exclude the various combinations if so desired.

{
return Ok(None);
}

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

let input = NoMergesInput { merge_commits };
Ok(if input.merge_commits.is_empty() {
None
} else {
Some(input)
})
if merge_commits.is_empty() {
return Ok(None);
}

Ok(Some(NoMergesInput { merge_commits }))
}

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

let mut message = config
.message
.as_deref()
.unwrap_or(DEFAULT_MESSAGE)
.to_string();

let since_last_posted = if state.data.mentioned_merge_commits.is_empty() {
let since_last_posted = if first_time {
""
} else {
" (since this message was last posted)"
Expand All @@ -132,6 +134,22 @@ pub(super) async fn handle_input(
}

if should_send {
if !first_time {
// Check if the labels are still set.
// Otherwise, they were probably removed manually.
let any_removed = config.labels.iter().any(|label| {
// No label on the issue matches.
event.issue.labels().iter().all(|l| &l.name != label)
});

if any_removed {
// Assume it was a false positive, so don't
// re-add the labels or send a message this time.
state.save().await?;
return Ok(());
}
}

// Set labels
let labels = config
.labels
Expand Down