Skip to content

Commit

Permalink
Merge pull request #141 from siddharthvp/nobot
Browse files Browse the repository at this point in the history
Don't update reports on pages containing {{nobots}}
  • Loading branch information
legoktm authored Sep 30, 2024
2 parents 603a61d + 414748b commit 771579b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dbreps2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ pub trait Report<T: Send + Sync> {
return Ok(true);
}
}

// Pages with {{database report}} are maintained by SDZeroBot and contain the SQL queries
// directly. Skip updating the report if it has been migrated to use that template.
if contains_database_report_template(old_text) {
return Ok(false);
}
let re = Regex::new("<onlyinclude>(.*?)</onlyinclude>").unwrap();
let ts = match re.captures(old_text) {
Some(cap) => cap[1].to_string(),
Expand Down Expand Up @@ -450,6 +456,12 @@ pub fn y_m_d(input: &str) -> String {
.unwrap_or_else(|_| input.to_string())
}

pub fn contains_database_report_template(text: &str) -> bool {
Regex::new("\\{\\{[Dd]atabase report\\s*\\|")
.unwrap()
.is_match(text)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -515,4 +527,20 @@ mod tests {
"This report is updated every day at 3:00 UTC."
);
}

#[test]
fn test_contains_database_report_template() {
assert_eq!(contains_database_report_template(
"Some text here. {{database report|sql=SELECT * FROM page LIMIT 10}}"), true);
assert_eq!(
contains_database_report_template(
"Some text here. \
{{database report\
|sql=SELECT * FROM page LIMIT 10\
}}"
),
true
);
assert_eq!(contains_database_report_template("Some text here"), false);
}
}

0 comments on commit 771579b

Please sign in to comment.