Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
Merged opf/openproject/refs/tags/v5.0.16 into opf/openproject-ce/rele…
Browse files Browse the repository at this point in the history
…ase/5.0
  • Loading branch information
openprojectci committed Mar 8, 2016
2 parents 1cd0816 + 08c021c commit 36b4b77
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ GIT

GIT
remote: https://github.com/opf/openproject-translations.git
revision: c5146cc45b62d11cc83329ce5e9ac6caf98f510e
revision: 48de77103ac4ce2e20b26e3867c00d7053eb13b9
branch: stable/5
specs:
openproject-translations (5.0.15)
openproject-translations (5.0.16)
crowdin-api (~> 0.4.0)
mixlib-shellout (~> 2.1.0)
rails (~> 4.2.3)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ def find_repository

# Prepare checkout instructions
# available on all pages (even empty!)
@instructions = ::Scm::CheckoutInstructionsService.new(@repository)
@path = params[:path] || ''
@instructions = ::Scm::CheckoutInstructionsService.new(@repository, path: @path)

# Asserts repository availability, or renders an appropriate error
@repository.scm.check_availability!

@path = params[:path] || ''
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
@rev_to = params[:rev_to]

Expand Down
21 changes: 15 additions & 6 deletions app/helpers/work_packages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module WorkPackagesHelper
# link_to_work_package(package, subject_only: true) # => This is the subject (as link)
# link_to_work_package(package, status: true) # => #6 New (if #id => true)
def link_to_work_package(package, options = {})
only_path = options.fetch(:only_path) { true }
if options[:subject_only]
options.merge!(type: false,
subject: true,
Expand Down Expand Up @@ -119,20 +120,28 @@ def link_to_work_package(package, options = {})
title = parts[:title].join(' ')
css_class = parts[:css_class].join(' ')

# Determine path or url
work_package_link =
if only_path
work_package_path(package)
else
work_package_url(package)
end

text = if options[:all_link]
link_text = [prefix, link].reject(&:empty?).join(' - ')
link_text = [link_text, suffix].reject(&:empty?).join(': ')
link_text = [hidden_link, link_text].reject(&:empty?).join('')

link_to(link_text.html_safe,
work_package_path(package),
work_package_link,
title: title,
class: css_class)
else
link_text = [hidden_link, link].reject(&:empty?).join('')

html_link = link_to(link_text.html_safe,
work_package_path(package),
work_package_link,
title: title,
class: css_class)

Expand All @@ -141,7 +150,7 @@ def link_to_work_package(package, options = {})
end.html_safe
end

def work_package_quick_info(work_package)
def work_package_quick_info(work_package, only_path: true)
changed_dates = {}

journals = work_package.journals.where(['created_at >= ?', Date.today.to_time - 7.day])
Expand All @@ -159,7 +168,7 @@ def work_package_quick_info(work_package)
end
end

link = link_to_work_package(work_package, status: true)
link = link_to_work_package(work_package, status: true, only_path: only_path)
link += " #{work_package.start_date.nil? ? '[?]' : work_package.start_date.to_s}"
link += changed_dates['start_date']
link += " – #{work_package.due_date.nil? ? '[?]' : work_package.due_date.to_s}"
Expand All @@ -168,10 +177,10 @@ def work_package_quick_info(work_package)
link
end

def work_package_quick_info_with_description(work_package, lines = 3)
def work_package_quick_info_with_description(work_package, lines = 3, only_path: true)
description = truncated_work_package_description(work_package, lines)

link = work_package_quick_info(work_package)
link = work_package_quick_info(work_package, only_path: only_path)

attributes = info_user_attributes(work_package)

Expand Down
11 changes: 7 additions & 4 deletions app/services/scm/checkout_instructions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@
##
# Implements a repository service for building checkout instructions if supported
class Scm::CheckoutInstructionsService
attr_reader :repository, :user
attr_reader :repository, :user, :path

def initialize(repository, user: User.current)
def initialize(repository, path: nil, user: User.current)
@repository = repository
@user = user
@path = path
end

##
# Retrieve the checkout URL using the repository vendor information
# It may additionally set a path parameter, if the repository supports subtree checkout
def checkout_url(path = nil)
repository.scm.checkout_url(repository, checkout_base_url, path)
def checkout_url(with_path = false)
repository.scm.checkout_url(repository,
checkout_base_url,
with_path ? @path : nil)
end

##
Expand Down
2 changes: 1 addition & 1 deletion app/views/repositories/_repository_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ See doc/COPYRIGHT.rdoc for more details.
</div>
<input id="repository-checkout-url"
type="text" class="-clickable" size="40"
value="<%= @instructions.checkout_url %>"
value="<%= @instructions.checkout_url(true) %>"
onclick="this.focus(); this.select();"
readonly>
<button class="toolbar-input--affix toolbar-input-group--affix -append"
Expand Down
4 changes: 2 additions & 2 deletions lib/open_project/text_formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def parse_redmine_links(text, project, obj, attr, only_path, options)
.includes(:status)
.references(:statuses)
.find_by(id: oid)
link = work_package_quick_info(work_package)
link = work_package_quick_info(work_package, only_path: only_path)
end
elsif sep == '###'
oid = identifier.to_i
Expand All @@ -350,7 +350,7 @@ def parse_redmine_links(text, project, obj, attr, only_path, options)
.references(:statuses)
.find_by(id: oid)
if work_package && obj && !(attr == :description && obj.id == work_package.id)
link = work_package_quick_info_with_description(work_package)
link = work_package_quick_info_with_description(work_package, only_path: only_path)
end
elsif sep == ':'
# removes the double quotes if any
Expand Down
27 changes: 27 additions & 0 deletions spec/controllers/repositories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,33 @@
end
end
end

describe 'checkout path' do
render_views

let(:role) { FactoryGirl.create(:role, permissions: [:browse_repository]) }
let(:checkout_hash) {
{
'subversion' => { 'enabled' => '1',
'text' => 'foo',
'base_url' => 'http://localhost'
}
}
}

before do
allow(Setting).to receive(:repository_checkout_data).and_return(checkout_hash)
get :show, project_id: project.identifier, path: 'subversion_test'
end

it 'renders an empty warning view' do
expected_path = "http://localhost/#{project.identifier}/subversion_test"

expect(response.code).to eq('200')
expect(response).to render_template partial: 'repositories/_checkout_instructions'
expect(response.body).to have_selector("#repository-checkout-url[value='#{expected_path}']")
end
end
end
end
end
12 changes: 8 additions & 4 deletions spec/services/scm/checkout_instructions_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
}

let(:base_url) { 'http://example.org/svn/' }
let(:path) { nil }
let(:text) { 'foo' }
let(:checkout_hash) {
{
Expand All @@ -51,7 +52,7 @@
}
}

subject(:service) { Scm::CheckoutInstructionsService.new(repository, user: user) }
subject(:service) { Scm::CheckoutInstructionsService.new(repository, user: user, path: path) }

before do
allow(Setting).to receive(:repository_checkout_data).and_return(checkout_hash)
Expand All @@ -64,9 +65,12 @@
.to eq(URI("http://example.org/svn/#{project.identifier}"))
end

it 'builds a subpath' do
expect(service.checkout_url('foo/bar'))
.to eq(URI("http://example.org/svn/#{project.identifier}/foo/bar"))
context 'with a subpath' do
let(:path) { 'foo/bar' }
it do
expect(service.checkout_url('foo/bar'))
.to eq(URI("http://example.org/svn/#{project.identifier}/foo/bar"))
end
end
end

Expand Down

0 comments on commit 36b4b77

Please sign in to comment.