diff options
author | Robert Speicher <robert@gitlab.com> | 2016-06-17 19:14:43 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-06-17 19:14:43 +0000 |
commit | 1db4fd3ae7cd3a4fa2f356a4c252820e26783a27 (patch) | |
tree | c55ec6f6e8013bd64321d4f6221da2bb0f22da99 | |
parent | bb4a1ef6c1ed4d367e6126ad64033e0286da6f15 (diff) | |
parent | d9f6d5dd59281a8efcd6cb7b392b1ef3bafa778d (diff) | |
download | gitlab-ce-1db4fd3ae7cd3a4fa2f356a4c252820e26783a27.tar.gz |
Merge branch 'repo-check-require-push-events' into 'master'
Do not check repos without push events
Reduce false positives from automatic repository checks by skipping
projects without push events.
See merge request !4684
-rw-r--r-- | app/workers/repository_check/single_repository_worker.rb | 6 | ||||
-rw-r--r-- | spec/workers/repository_check/single_repository_worker_spec.rb | 29 |
2 files changed, 34 insertions, 1 deletions
diff --git a/app/workers/repository_check/single_repository_worker.rb b/app/workers/repository_check/single_repository_worker.rb index f2d12ba5a7d..98ddf5d0688 100644 --- a/app/workers/repository_check/single_repository_worker.rb +++ b/app/workers/repository_check/single_repository_worker.rb @@ -15,7 +15,7 @@ module RepositoryCheck private def check(project) - if !git_fsck(project.repository) + if has_pushes?(project) && !git_fsck(project.repository) false elsif project.wiki_enabled? # Historically some projects never had their wiki repos initialized; @@ -44,5 +44,9 @@ module RepositoryCheck false end end + + def has_pushes?(project) + Project.with_push.exists?(project.id) + end end end diff --git a/spec/workers/repository_check/single_repository_worker_spec.rb b/spec/workers/repository_check/single_repository_worker_spec.rb index 5a03bb77ebd..05e07789dac 100644 --- a/spec/workers/repository_check/single_repository_worker_spec.rb +++ b/spec/workers/repository_check/single_repository_worker_spec.rb @@ -4,6 +4,26 @@ require 'fileutils' describe RepositoryCheck::SingleRepositoryWorker do subject { described_class.new } + it 'passes when the project has no push events' do + project = create(:project_empty_repo, wiki_enabled: false) + project.events.destroy_all + break_repo(project) + + subject.perform(project.id) + + expect(project.reload.last_repository_check_failed).to eq(false) + end + + it 'fails when the project has push events and a broken repository' do + project = create(:project_empty_repo) + create_push_event(project) + break_repo(project) + + subject.perform(project.id) + + expect(project.reload.last_repository_check_failed).to eq(true) + end + it 'fails if the wiki repository is broken' do project = create(:project_empty_repo, wiki_enabled: true) project.create_wiki @@ -39,6 +59,7 @@ describe RepositoryCheck::SingleRepositoryWorker do it 'does not create a wiki if the main repo does not exist at all' do project = create(:project_empty_repo) + create_push_event(project) FileUtils.rm_rf(project.repository.path_to_repo) FileUtils.rm_rf(wiki_path(project)) @@ -54,4 +75,12 @@ describe RepositoryCheck::SingleRepositoryWorker do def wiki_path(project) project.wiki.repository.path_to_repo end + + def create_push_event(project) + project.events.create(action: Event::PUSHED, author_id: create(:user).id) + end + + def break_repo(project) + FileUtils.rm_rf(File.join(project.repository.path_to_repo, 'objects')) + end end |