diff --git a/app/helpers/git_helper.rb b/app/helpers/git_helper.rb index a1782ecbd..bc60c1f08 100644 --- a/app/helpers/git_helper.rb +++ b/app/helpers/git_helper.rb @@ -1,6 +1,23 @@ # -*- encoding : utf-8 -*- module GitHelper + def submodule_url(node, treeish) + # node.url(treeish) looks like: + # - http://0.0.0.0:3000/abf/git@abf.rosalinux.ru:abf/rhel-scripts.git + # - git://github.com/avokhmin/mdv-scripts.git + url = node.url(treeish).gsub(/.git$/, '') + if url =~ /^git:/ + url.gsub!(/^git/, 'http') + else + str = /git@.*:.*/.match(url)[0].gsub(/^git@/, '') + domen = str.gsub(/:.*/, '') + owner = str.gsub(/^#{domen}:/, '').gsub(/\/.*/, '') + project = str.gsub(/.*\//, '') + url = "http://#{domen}/#{owner}/#{project}" + end + url + end + def render_path # TODO: Looks ugly, rewrite with clear mind. if @path.present? diff --git a/app/views/projects/git/trees/_show.html.haml b/app/views/projects/git/trees/_show.html.haml index 3a5feb259..4e7571e91 100644 --- a/app/views/projects/git/trees/_show.html.haml +++ b/app/views/projects/git/trees/_show.html.haml @@ -26,7 +26,7 @@ - if node.is_a? Grit::Submodule .pic= image_tag 'folder-submodule.png' .name - - url = node.url(@treeish).gsub(/^git/, 'http').gsub(/.git$/, '') + - url = submodule_url node, @treeish = link_to(node.name, url, :class => 'files-see') = '@' = link_to(node.id[0..6], "#{url}/tree/#{node.id}", :class => 'files-see')