Commit 16c4f14b authored by Kirill Smelkov's avatar Kirill Smelkov

Sync with upstream 8-5-stable

* origin/8-5-stable:
  Remove "(unreleased)" from 8.5.4 release notes
  Merge branch 'fix/invalidate-builds-badge-cache' into 'master'
  Version 8.5.3
  Merge branch 'renaming-repository-caching' into 'master'
parents 1bfb586a 145f7dda
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.6.0 (unreleased)
- Contributions to forked projects are included in calendar
- Improve the formatting for the user page bio (Connor Shea)
- Fix issue when pushing to projects ending in .wiki
- Fix avatar stretching by providing a cropping feature (Johann Pardanaud)
- Don't load all of GitLab in mail_room
- Strip leading and trailing spaces in URL validator (evuez)
- Return empty array instead of 404 when commit has no statuses in commit status API
- Update documentation to reflect Guest role not being enforced on internal projects
- Allow search for logged out users
- Don't show Issues/MRs from archived projects in Groups view
- Increase the notes polling timeout over time (Roberto Dip)
v 8.5.4
- Do not cache requests for badges (including builds badge)
v 8.5.3
- Flush repository caches before renaming projects
v 8.5.2 v 8.5.2
- Fix sidebar overlapping content when screen width was below 1200px - Fix sidebar overlapping content when screen width was below 1200px
- Don't repeat labels listed on Labels tab - Don't repeat labels listed on Labels tab
......
8.5.2 8.5.3
\ No newline at end of file \ No newline at end of file
class Projects::BadgesController < Projects::ApplicationController class Projects::BadgesController < Projects::ApplicationController
before_action :set_no_cache
def build def build
respond_to do |format| respond_to do |format|
format.html { render_404 } format.html { render_404 }
...@@ -8,4 +10,15 @@ class Projects::BadgesController < Projects::ApplicationController ...@@ -8,4 +10,15 @@ class Projects::BadgesController < Projects::ApplicationController
end end
end end
end end
private
def set_no_cache
expires_now
# Add some deprecated headers for older agents
#
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
end
end end
...@@ -711,6 +711,8 @@ class Project < ActiveRecord::Base ...@@ -711,6 +711,8 @@ class Project < ActiveRecord::Base
old_path_with_namespace = File.join(namespace_dir, path_was) old_path_with_namespace = File.join(namespace_dir, path_was)
new_path_with_namespace = File.join(namespace_dir, path) new_path_with_namespace = File.join(namespace_dir, path)
expire_caches_before_rename(old_path_with_namespace)
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace) if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
# If repository moved successfully we need to send update instructions to users. # If repository moved successfully we need to send update instructions to users.
# However we cannot allow rollback since we moved repository # However we cannot allow rollback since we moved repository
...@@ -739,6 +741,22 @@ class Project < ActiveRecord::Base ...@@ -739,6 +741,22 @@ class Project < ActiveRecord::Base
Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.path) Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.path)
end end
# Expires various caches before a project is renamed.
def expire_caches_before_rename(old_path)
repo = Repository.new(old_path, self)
wiki = Repository.new("#{old_path}.wiki", self)
if repo.exists?
repo.expire_cache
repo.expire_emptiness_caches
end
if wiki.exists?
wiki.expire_cache
wiki.expire_emptiness_caches
end
end
def hook_attrs def hook_attrs
{ {
name: name, name: name,
......
...@@ -20,3 +20,8 @@ Feature: Project Badges Build ...@@ -20,3 +20,8 @@ Feature: Project Badges Build
And project has another build that is running And project has another build that is running
When I display builds badge for a master branch When I display builds badge for a master branch
Then I should see a build running badge Then I should see a build running badge
Scenario: I want to see a fresh badge on each request
Given recent build is successful
When I display builds badge for a master branch
Then I should see a badge that has not been cached
...@@ -20,6 +20,10 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps ...@@ -20,6 +20,10 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps
expect_badge('running') expect_badge('running')
end end
step 'I should see a badge that has not been cached' do
expect(page.response_headers).to include('Cache-Control' => 'no-cache')
end
def expect_badge(status) def expect_badge(status)
svg = Nokogiri::XML.parse(page.body) svg = Nokogiri::XML.parse(page.body)
expect(page.response_headers).to include('Content-Type' => 'image/svg+xml') expect(page.response_headers).to include('Content-Type' => 'image/svg+xml')
......
...@@ -102,7 +102,7 @@ describe Project, models: true do ...@@ -102,7 +102,7 @@ describe Project, models: true do
expect(project2.errors[:limit_reached].first).to match(/Your project limit is 0/) expect(project2.errors[:limit_reached].first).to match(/Your project limit is 0/)
end end
end end
describe 'project token' do describe 'project token' do
it 'should set an random token if none provided' do it 'should set an random token if none provided' do
project = FactoryGirl.create :empty_project, runners_token: '' project = FactoryGirl.create :empty_project, runners_token: ''
...@@ -524,30 +524,30 @@ describe Project, models: true do ...@@ -524,30 +524,30 @@ describe Project, models: true do
context 'for shared runners disabled' do context 'for shared runners disabled' do
let(:shared_runners_enabled) { false } let(:shared_runners_enabled) { false }
it 'there are no runners available' do it 'there are no runners available' do
expect(project.any_runners?).to be_falsey expect(project.any_runners?).to be_falsey
end end
it 'there is a specific runner' do it 'there is a specific runner' do
project.runners << specific_runner project.runners << specific_runner
expect(project.any_runners?).to be_truthy expect(project.any_runners?).to be_truthy
end end
it 'there is a shared runner, but they are prohibited to use' do it 'there is a shared runner, but they are prohibited to use' do
shared_runner shared_runner
expect(project.any_runners?).to be_falsey expect(project.any_runners?).to be_falsey
end end
it 'checks the presence of specific runner' do it 'checks the presence of specific runner' do
project.runners << specific_runner project.runners << specific_runner
expect(project.any_runners? { |runner| runner == specific_runner }).to be_truthy expect(project.any_runners? { |runner| runner == specific_runner }).to be_truthy
end end
end end
context 'for shared runners enabled' do context 'for shared runners enabled' do
let(:shared_runners_enabled) { true } let(:shared_runners_enabled) { true }
it 'there is a shared runner' do it 'there is a shared runner' do
shared_runner shared_runner
expect(project.any_runners?).to be_truthy expect(project.any_runners?).to be_truthy
...@@ -583,4 +583,67 @@ describe Project, models: true do ...@@ -583,4 +583,67 @@ describe Project, models: true do
end end
end end
describe '#rename_repo' do
let(:project) { create(:project) }
let(:gitlab_shell) { Gitlab::Shell.new }
before do
# Project#gitlab_shell returns a new instance of Gitlab::Shell on every
# call. This makes testing a bit easier.
allow(project).to receive(:gitlab_shell).and_return(gitlab_shell)
end
it 'renames a repository' do
allow(project).to receive(:previous_changes).and_return('path' => ['foo'])
ns = project.namespace_dir
expect(gitlab_shell).to receive(:mv_repository).
ordered.
with("#{ns}/foo", "#{ns}/#{project.path}").
and_return(true)
expect(gitlab_shell).to receive(:mv_repository).
ordered.
with("#{ns}/foo.wiki", "#{ns}/#{project.path}.wiki").
and_return(true)
expect_any_instance_of(SystemHooksService).
to receive(:execute_hooks_for).
with(project, :rename)
expect_any_instance_of(Gitlab::UploadsTransfer).
to receive(:rename_project).
with('foo', project.path, ns)
expect(project).to receive(:expire_caches_before_rename)
project.rename_repo
end
end
describe '#expire_caches_before_rename' do
let(:project) { create(:project) }
let(:repo) { double(:repo, exists?: true) }
let(:wiki) { double(:wiki, exists?: true) }
it 'expires the caches of the repository and wiki' do
allow(Repository).to receive(:new).
with('foo', project).
and_return(repo)
allow(Repository).to receive(:new).
with('foo.wiki', project).
and_return(wiki)
expect(repo).to receive(:expire_cache)
expect(repo).to receive(:expire_emptiness_caches)
expect(wiki).to receive(:expire_cache)
expect(wiki).to receive(:expire_emptiness_caches)
project.expire_caches_before_rename('foo')
end
end
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