Commit 2234ac52 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'auto-fsck-skip-wiki' into 'master'

Improve 'auto fsck' feature

- skip wiki repositories when they are disabled (avoids false alarms)
- more context in admin alert emails

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/15332

See merge request !3781
parents 53a1d705 1394ccfe
......@@ -8,7 +8,7 @@ class RepositoryCheckMailer < BaseMailer
mail(
to: User.admins.pluck(:email),
subject: @message
subject: "GitLab Admin | #{@message}"
)
end
end
......@@ -3,3 +3,6 @@
%p
= link_to "See the affected projects in the GitLab admin panel", admin_namespaces_projects_url(last_repository_check_failed: 1)
%p
You are receiving this message because you are a GitLab administrator for #{Gitlab.config.gitlab.url}.
#{@message}.
\
View details: #{admin_namespaces_projects_url(last_repository_check_failed: 1)}
You are receiving this message because you are a GitLab administrator
for #{Gitlab.config.gitlab.url}.
......@@ -15,10 +15,10 @@ module RepositoryCheck
private
def check(project)
repositories = [project.repository]
repositories << project.wiki.repository if project.wiki_enabled?
# Use 'map do', not 'all? do', to prevent short-circuiting
[project.repository, project.wiki.repository].map do |repository|
git_fsck(repository.path_to_repo)
end.all?
repositories.map { |repository| git_fsck(repository.path_to_repo) }.all?
end
def git_fsck(path)
......
......@@ -15,7 +15,7 @@ describe RepositoryCheckMailer do
it 'mentions the number of failed checks' do
mail = described_class.notify(3)
expect(mail).to have_subject '3 projects failed their last repository check'
expect(mail).to have_subject 'GitLab Admin | 3 projects failed their last repository check'
end
end
end
require 'spec_helper'
require 'fileutils'
describe RepositoryCheck::SingleRepositoryWorker do
subject { described_class.new }
it 'fails if the wiki repository is broken' do
project = create(:project_empty_repo, wiki_enabled: true)
project.create_wiki
# Test sanity: everything should be fine before the wiki repo is broken
subject.perform(project.id)
expect(project.reload.last_repository_check_failed).to eq(false)
destroy_wiki(project)
subject.perform(project.id)
expect(project.reload.last_repository_check_failed).to eq(true)
end
it 'skips wikis when disabled' do
project = create(:project_empty_repo, wiki_enabled: false)
# Make sure the test would fail if it checked the wiki repo
destroy_wiki(project)
subject.perform(project.id)
expect(project.reload.last_repository_check_failed).to eq(false)
end
def destroy_wiki(project)
FileUtils.rm_rf(project.wiki.repository.path_to_repo)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment