summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2014-02-22 16:37:10 +0100
committerJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2014-02-22 16:37:10 +0100
commitbb35c2d36f4f275cda650c1ad47595c287feba10 (patch)
tree2499f330737de0e26ecc5b4a744b7a3a218a173a
parent4e0a2e3c968cd6be218577b3a615b888822c99cf (diff)
downloadgitlab-ce-bb35c2d36f4f275cda650c1ad47595c287feba10.tar.gz
Added the contribution guide notice
This is shown at the creation of new issues and new merge requests, when the repository has a contribution guide file.
-rw-r--r--app/models/repository.rb7
-rw-r--r--app/models/tree.rb7
-rw-r--r--app/views/projects/issues/_form.html.haml4
-rw-r--r--app/views/projects/merge_requests/_form.html.haml4
4 files changed, 21 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 99d908b5d81..009f5edd1df 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -134,6 +134,7 @@ class Repository
Rails.cache.delete(cache_key(:commit_count))
Rails.cache.delete(cache_key(:graph_log))
Rails.cache.delete(cache_key(:readme))
+ Rails.cache.delete(cache_key(:contribution_guide))
end
def graph_log
@@ -167,6 +168,12 @@ class Repository
end
end
+ def contribution_guide
+ Rails.cache.fetch(cache_key(:contribution_guide)) do
+ tree(:head).contribution_guide
+ end
+ end
+
def head_commit
commit(self.root_ref)
end
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 4f866f1a33d..f1077772ea9 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -1,5 +1,5 @@
class Tree
- attr_accessor :entries, :readme
+ attr_accessor :entries, :readme, :contribution_guide
def initialize(repository, sha, path = '/')
path = '/' if path.blank?
@@ -10,6 +10,11 @@ class Tree
readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
@readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
end
+
+ if contribution_tree = @entries.find(&:contribution?)
+ contribution_path = path == '/' ? contribution_tree.name : File.join(path, contribution_tree.name)
+ @contribution_guide = Gitlab::Git::Blob.find(git_repo, sha, contribution_path)
+ end
end
def trees
diff --git a/app/views/projects/issues/_form.html.haml b/app/views/projects/issues/_form.html.haml
index f725db57ad1..dd091302c8e 100644
--- a/app/views/projects/issues/_form.html.haml
+++ b/app/views/projects/issues/_form.html.haml
@@ -1,6 +1,10 @@
%div.issue-form-holder
%h3.page-title= @issue.new_record? ? "New Issue" : "Edit Issue ##{@issue.iid}"
%hr
+ - if @repository.contribution_guide && !@issue.persisted?
+ - contribution_guide_url = project_blob_path(@project, tree_join(@repository.root_ref, @repository.contribution_guide.name))
+ .alert.alert-info.col-sm-10.col-sm-offset-2
+ ="Please review the <strong>#{link_to "guidelines for contribution", contribution_guide_url}</strong> to this repository.".html_safe
= form_for [@project, @issue], html: { class: 'form-horizontal issue-form' } do |f|
-if @issue.errors.any?
.alert.alert-danger
diff --git a/app/views/projects/merge_requests/_form.html.haml b/app/views/projects/merge_requests/_form.html.haml
index 9502ff95d8e..6d96b405e74 100644
--- a/app/views/projects/merge_requests/_form.html.haml
+++ b/app/views/projects/merge_requests/_form.html.haml
@@ -1,3 +1,7 @@
+- if @repository.contribution_guide && !@merge_request.persisted?
+ - contribution_guide_url = project_blob_path(@project, tree_join(@repository.root_ref, @repository.contribution_guide.name))
+ .alert.alert-info.col-sm-10.col-sm-offset-2
+ ="Please review the <strong>#{link_to "guidelines for contribution", contribution_guide_url}</strong> to this repository.".html_safe
= form_for [@project, @merge_request], html: { class: "merge-request-form form-horizontal" } do |f|
-if @merge_request.errors.any?
.alert.alert-danger