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

Only consider article files when checking for conflicts #21

Merged
merged 1 commit into from
Nov 23, 2023
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
29 changes: 21 additions & 8 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ hmac = "0.12.1"
ring = "0.16.20"
async-trait = "0.1.64"
mockito = "1.2.0"
regex = "1.10.2"
28 changes: 28 additions & 0 deletions src/controller/controller_impl/tests/tests_conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,3 +875,31 @@ async fn test_only_obsolete_conflict_is_removed_incomplete_translation() {
)]
);
}

#[tokio::test]
async fn test_non_article_files_are_skipped() {
let mut server = GitHubServer::new()
.with_default_github_app()
.with_default_app_installations();

let pulls = [
server.make_pull(
"test/repo",
&["wiki/Article/en.md", "wiki/Tournaments/TEMPLATE.md"],
),
server.make_pull(
"test/repo",
&["wiki/Other_article/ru.md", "wiki/Tournaments/TEMPLATE.md"],
),
];

server = server.with_pulls("test/repo", &pulls);

let c = new_controller(&server, true).await;
for p in pulls.iter() {
c.upsert_pull("test/repo", p.clone(), false).await.unwrap();
}

assert!(c.conflicts.by_trigger("test/repo", 1).is_empty());
assert!(c.conflicts.by_trigger("test/repo", 2).is_empty());
}
24 changes: 18 additions & 6 deletions src/helpers/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,27 @@ pub fn compare_pulls(

let mut is_new_translation = false;

for incoming in new_diff
.files()
.iter()
.filter(|fp| fp.target_file.ends_with(".md"))
{
// Only consider Markdown files, and among these, exclude non-articles such as the tournament template
// (https://github.com/TicClick/observatory/issues/17)
let article_expr = regex::Regex::new(r"^(..|..-..)\.md$").unwrap();
let article_filter = |p: &&unidiff::PatchedFile| -> bool {
let parts = std::path::Path::new(&p.target_file);
if let Some(filename) = parts.file_name() {
if let Some(filename_cstr) = filename.to_str() {
article_expr.is_match(filename_cstr)
} else {
false
}
} else {
false
}
};

for incoming in new_diff.files().iter().filter(article_filter) {
let other_files: BTreeSet<_> = other_diff
.files()
.iter()
.filter(|patched| patched.target_file.ends_with(".md"))
.filter(article_filter)
.map(|patched| patched.path())
.collect();
for other in other_files.iter() {
Expand Down
Loading