summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-18 18:02:39 +0000
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-18 18:02:39 +0000
commitd03d63630494727e92553f168712d177ab4eb1cf (patch)
treebf669b6034b0dc7710becbeab989ec92e1116aed /app
parenta0c513bb4ecc5ef4d2d626c024de6916c5ef233a (diff)
parentb1b8261f56d35e471bc32b0f2050e27650b7c797 (diff)
downloadgitlab-ce-d03d63630494727e92553f168712d177ab4eb1cf.tar.gz
Merge branch 'changelog-link' into 'master'
Add changelog, license and contribution guide links to project sidebar. If the version is known, the "Version: 7.9.0pre" button links to the changelog, otherwise a "View changelog" button is shown. ![Screen_Shot_2015-03-18_at_14.22.29](https://dev.gitlab.org/gitlab/gitlabhq/uploads/747acc018ec9a188098e0f0bc4e91cc3/Screen_Shot_2015-03-18_at_14.22.29.png) See merge request !1708
Diffstat (limited to 'app')
-rw-r--r--app/helpers/projects_helper.rb37
-rw-r--r--app/models/repository.rb24
-rw-r--r--app/models/tree.rb54
-rw-r--r--app/views/projects/_issuable_form.html.haml4
-rw-r--r--app/views/projects/merge_requests/_new_submit.html.haml4
-rw-r--r--app/views/projects/show.html.haml23
6 files changed, 105 insertions, 41 deletions
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 2225b110651..a14277180c7 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -232,12 +232,45 @@ module ProjectsHelper
end
def contribution_guide_url(project)
- if project && project.repository.contribution_guide
+ if project && contribution_guide = project.repository.contribution_guide
namespace_project_blob_path(
project.namespace,
project,
tree_join(project.default_branch,
- project.repository.contribution_guide.name)
+ contribution_guide.name)
+ )
+ end
+ end
+
+ def changelog_url(project)
+ if project && changelog = project.repository.changelog
+ namespace_project_blob_path(
+ project.namespace,
+ project,
+ tree_join(project.default_branch,
+ changelog.name)
+ )
+ end
+ end
+
+ def license_url(project)
+ if project && license = project.repository.license
+ namespace_project_blob_path(
+ project.namespace,
+ project,
+ tree_join(project.default_branch,
+ license.name)
+ )
+ end
+ end
+
+ def version_url(project)
+ if project && version = project.repository.version
+ namespace_project_blob_path(
+ project.namespace,
+ project,
+ tree_join(project.default_branch,
+ version.name)
)
end
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 7addbca8fb1..c6eaa485b8a 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -122,7 +122,7 @@ class Repository
def expire_cache
%i(size branch_names tag_names commit_count graph_log
- readme version contribution_guide).each do |key|
+ readme version contribution_guide changelog license).each do |key|
cache.expire(key)
end
end
@@ -211,7 +211,27 @@ class Repository
end
def contribution_guide
- cache.fetch(:contribution_guide) { tree(:head).contribution_guide }
+ cache.fetch(:contribution_guide) do
+ tree(:head).blobs.find do |file|
+ file.contributing?
+ end
+ end
+ end
+
+ def changelog
+ cache.fetch(:changelog) do
+ tree(:head).blobs.find do |file|
+ file.name =~ /^(changelog|history)/i
+ end
+ end
+ end
+
+ def license
+ cache.fetch(:license) do
+ tree(:head).blobs.find do |file|
+ file.name =~ /^license/i
+ end
+ end
end
def head_commit
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 4f5d81f0a5e..f279e896cda 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -1,38 +1,38 @@
class Tree
include Gitlab::MarkdownHelper
- attr_accessor :entries, :readme, :contribution_guide
+ attr_accessor :repository, :sha, :path, :entries
def initialize(repository, sha, path = '/')
path = '/' if path.blank?
- git_repo = repository.raw_repository
- @entries = Gitlab::Git::Tree.where(git_repo, sha, path)
-
- available_readmes = @entries.select(&:readme?)
-
- if available_readmes.count > 0
- # If there is more than 1 readme in tree, find readme which is supported
- # by markup renderer.
- if available_readmes.length > 1
- supported_readmes = available_readmes.select do |readme|
- previewable?(readme.name)
- end
-
- # Take the first supported readme, or the first available readme, if we
- # don't support any of them
- readme_tree = supported_readmes.first || available_readmes.first
- else
- readme_tree = available_readmes.first
- end
-
- readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
- @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
- end
+
+ @repository = repository
+ @sha = sha
+ @path = path
+
+ git_repo = @repository.raw_repository
+ @entries = Gitlab::Git::Tree.where(git_repo, @sha, @path)
+ end
+
+ def readme
+ return @readme if defined?(@readme)
- if contribution_tree = @entries.find(&:contributing?)
- contribution_path = path == '/' ? contribution_tree.name : File.join(path, contribution_tree.name)
- @contribution_guide = Gitlab::Git::Blob.find(git_repo, sha, contribution_path)
+ available_readmes = blobs.select(&:readme?)
+
+ if available_readmes.count == 0
+ return @readme = nil
end
+
+ # Take the first previewable readme, or the first available readme, if we
+ # can't preview any of them
+ readme_tree = available_readmes.find do |readme|
+ previewable?(readme.name)
+ end || available_readmes.first
+
+ readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
+
+ git_repo = repository.raw_repository
+ @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
end
def trees
diff --git a/app/views/projects/_issuable_form.html.haml b/app/views/projects/_issuable_form.html.haml
index a7cd129b631..7fd5fe8a6e1 100644
--- a/app/views/projects/_issuable_form.html.haml
+++ b/app/views/projects/_issuable_form.html.haml
@@ -71,10 +71,10 @@
= link_to 'Create new label', new_namespace_project_label_path(issuable.project.namespace, issuable.project), target: :blank
.form-actions
- - if !issuable.project.empty_repo? && contribution_guide_url(issuable.project) && !issuable.persisted?
+ - if !issuable.project.empty_repo? && (guide_url = contribution_guide_url(issuable.project)) && !issuable.persisted?
%p
Please review the
- %strong #{link_to 'guidelines for contribution', contribution_guide_url(issuable.project)}
+ %strong #{link_to 'guidelines for contribution', guide_url}
to this repository.
- if issuable.new_record?
= f.submit "Submit new #{issuable.class.model_name.human.downcase}", class: 'btn btn-create'
diff --git a/app/views/projects/merge_requests/_new_submit.html.haml b/app/views/projects/merge_requests/_new_submit.html.haml
index bf80afe8785..1d8eef4e8ce 100644
--- a/app/views/projects/merge_requests/_new_submit.html.haml
+++ b/app/views/projects/merge_requests/_new_submit.html.haml
@@ -69,10 +69,10 @@
= link_to 'Create new label', new_namespace_project_label_path(@merge_request.target_project.namespace, @merge_request.target_project), target: :blank
.form-actions
- - if contribution_guide_url(@target_project)
+ - if guide_url = contribution_guide_url(@target_project)
%p
Please review the
- %strong #{link_to 'guidelines for contribution', contribution_guide_url(@target_project)}
+ %strong #{link_to 'guidelines for contribution', guide_url}
to this repository.
= f.hidden_field :source_project_id
= f.hidden_field :source_branch
diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml
index 74b07395650..822e67c5616 100644
--- a/app/views/projects/show.html.haml
+++ b/app/views/projects/show.html.haml
@@ -47,15 +47,26 @@
= link_to @project.forked_from_project.name_with_namespace, namespace_project_path(@project.namespace, @project.forked_from_project)
- unless @project.empty_repo?
- = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: @ref || @repository.root_ref), class: 'btn btn-block' do
- Compare code
-
- - if @repository.version
- - version = @repository.version
- = link_to namespace_project_blob_path(@project.namespace, @project, tree_join(@repository.root_ref, version.name)), class: 'btn btn-block' do
+ - if version = @repository.version
+ - detail_url = changelog_url(@project) || version_url(@project)
+ = link_to detail_url, class: 'btn btn-block' do
Version:
%span.count
= @repository.blob_by_oid(version.id).data
+ - elsif @repository.changelog
+ = link_to changelog_url(@project), class: 'btn btn-block' do
+ View changelog
+
+ - if @repository.contribution_guide
+ = link_to contribution_guide_url(@project), class: 'btn btn-block' do
+ View contribution guide
+
+ - if @repository.license
+ = link_to license_url(@project), class: 'btn btn-block' do
+ View license
+
+ = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: @ref || @repository.root_ref), class: 'btn btn-block' do
+ Compare code
.prepend-top-10
%p