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
47 changes: 31 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ anyhow = "1"
hex = "0.4"
parser = { path = "parser" }
rust_team_data = { git = "https://github.com/rust-lang/team" }
glob = "0.3.0"
toml = "0.8.20"
axum = "0.8.4"
hyper = { version = "1.6", features = ["server", "http1"] }
Expand Down Expand Up @@ -53,6 +52,7 @@ pulldown-cmark-escape = "0.11.0"
axum-extra = { version = "0.10.1", default-features = false }
unicode-segmentation = "1.12.0"
secrecy = { version = "0.10", features = ["serde"] }
globset = { version = "0.4.18", default-features = false }

[dependencies.serde]
version = "1"
Expand Down
75 changes: 43 additions & 32 deletions src/handlers/autolabel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,29 @@ pub(super) async fn parse_input(
let mut to_remove = Vec::new();

'outer: for (label, cfg) in &config.labels {
let exclude_patterns: Vec<glob::Pattern> = cfg
.exclude_labels
.iter()
.filter_map(|label| match glob::Pattern::new(label) {
Ok(exclude_glob) => Some(exclude_glob),
Err(error) => {
log::error!("Invalid glob pattern: {error}");
None
}
})
.collect();
let exclude_patterns =
cfg.exclude_labels
.iter()
.filter_map(|label| match globset::Glob::new(label) {
Ok(exclude_glob) => Some(exclude_glob),
Err(error) => {
log::error!("invalid glob pattern: {error}");
None
}
});

let exclude_patterns = match globset::GlobSet::new(exclude_patterns) {
Ok(exclude_patterns) => exclude_patterns,
Err(err) => {
log::error!("failed to create a glob set: {err:?}");
continue;
}
};

for label in event.issue.labels() {
for pat in &exclude_patterns {
if pat.matches(&label.name) {
// If we hit an excluded label, ignore this autolabel and check the next
continue 'outer;
}
if exclude_patterns.is_match(&label.name) {
// If we hit an excluded label, ignore this autolabel and check the next
continue 'outer;
}
}

Expand Down Expand Up @@ -161,24 +166,30 @@ pub(super) async fn parse_input(
let applied_label = &label.name;

'outer: for (label, config) in config.get_by_trigger(applied_label) {
let exclude_patterns: Vec<glob::Pattern> = config
.exclude_labels
.iter()
.filter_map(|label| match glob::Pattern::new(label) {
Ok(exclude_glob) => Some(exclude_glob),
Err(error) => {
log::error!("Invalid glob pattern: {error}");
None
}
})
.collect();
let exclude_patterns =
config
.exclude_labels
.iter()
.filter_map(|label| match globset::Glob::new(label) {
Ok(exclude_glob) => Some(exclude_glob),
Err(error) => {
log::error!("invalid glob pattern: {error}");
None
}
});

let exclude_patterns = match globset::GlobSet::new(exclude_patterns) {
Ok(exclude_patterns) => exclude_patterns,
Err(err) => {
log::error!("failed to create a glob set: {err:?}");
continue;
}
};

for label in event.issue.labels() {
for pat in &exclude_patterns {
if pat.matches(&label.name) {
// If we hit an excluded label, ignore this autolabel and check the next
continue 'outer;
}
if exclude_patterns.is_match(&label.name) {
// If we hit an excluded label, ignore this autolabel and check the next
continue 'outer;
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/handlers/check_commits/validate_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! changes are a valid configuration file.

use crate::{
config::CONFIG_FILE_NAME,
config::{CONFIG_FILE_NAME, MentionsEntryConfig, MentionsEntryType},
github::FileDiff,
handlers::{Context, IssuesEvent},
};
Expand Down Expand Up @@ -68,6 +68,20 @@ pub(super) async fn validate_config(
));
}

// Error if one the mentions entry is not a valid glob.
if let Some(mentions) = config.mentions {
for (entry, MentionsEntryConfig { type_, .. }) in mentions.entries {
if type_ == MentionsEntryType::Filename
&& let Err(err) = globset::Glob::new(&entry)
{
return Ok(Some(format!(
"Invalid `triagebot.toml`:\n\
`[mentions.\"{entry}\"]` has an invalid glob syntax: {err}"
)));
}
}
}

Ok(None)
}
}
Expand Down
Loading