Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't update reports on pages containing {{database report}} #141

Merged
merged 3 commits into from
Sep 30, 2024
Merged
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
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);
}
siddharthvp marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}