Commit bb35c2d36f4f275cda650c1ad47595c287feba10

Authored by Jeroen van Baarsen
1 parent 4e0a2e3c

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.
app/models/repository.rb
@@ -134,6 +134,7 @@ class Repository @@ -134,6 +134,7 @@ class Repository
134 Rails.cache.delete(cache_key(:commit_count)) 134 Rails.cache.delete(cache_key(:commit_count))
135 Rails.cache.delete(cache_key(:graph_log)) 135 Rails.cache.delete(cache_key(:graph_log))
136 Rails.cache.delete(cache_key(:readme)) 136 Rails.cache.delete(cache_key(:readme))
  137 + Rails.cache.delete(cache_key(:contribution_guide))
137 end 138 end
138 139
139 def graph_log 140 def graph_log
@@ -167,6 +168,12 @@ class Repository @@ -167,6 +168,12 @@ class Repository
167 end 168 end
168 end 169 end
169 170
  171 + def contribution_guide
  172 + Rails.cache.fetch(cache_key(:contribution_guide)) do
  173 + tree(:head).contribution_guide
  174 + end
  175 + end
  176 +
170 def head_commit 177 def head_commit
171 commit(self.root_ref) 178 commit(self.root_ref)
172 end 179 end
app/models/tree.rb
1 class Tree 1 class Tree
2 - attr_accessor :entries, :readme 2 + attr_accessor :entries, :readme, :contribution_guide
3 3
4 def initialize(repository, sha, path = '/') 4 def initialize(repository, sha, path = '/')
5 path = '/' if path.blank? 5 path = '/' if path.blank?
@@ -10,6 +10,11 @@ class Tree @@ -10,6 +10,11 @@ class Tree
10 readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) 10 readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
11 @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) 11 @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
12 end 12 end
  13 +
  14 + if contribution_tree = @entries.find(&:contribution?)
  15 + contribution_path = path == '/' ? contribution_tree.name : File.join(path, contribution_tree.name)
  16 + @contribution_guide = Gitlab::Git::Blob.find(git_repo, sha, contribution_path)
  17 + end
13 end 18 end
14 19
15 def trees 20 def trees
app/views/projects/issues/_form.html.haml
1 %div.issue-form-holder 1 %div.issue-form-holder
2 %h3.page-title= @issue.new_record? ? "New Issue" : "Edit Issue ##{@issue.iid}" 2 %h3.page-title= @issue.new_record? ? "New Issue" : "Edit Issue ##{@issue.iid}"
3 %hr 3 %hr
  4 + - if @repository.contribution_guide && !@issue.persisted?
  5 + - contribution_guide_url = project_blob_path(@project, tree_join(@repository.root_ref, @repository.contribution_guide.name))
  6 + .alert.alert-info.col-sm-10.col-sm-offset-2
  7 + ="Please review the <strong>#{link_to "guidelines for contribution", contribution_guide_url}</strong> to this repository.".html_safe
4 = form_for [@project, @issue], html: { class: 'form-horizontal issue-form' } do |f| 8 = form_for [@project, @issue], html: { class: 'form-horizontal issue-form' } do |f|
5 -if @issue.errors.any? 9 -if @issue.errors.any?
6 .alert.alert-danger 10 .alert.alert-danger
app/views/projects/merge_requests/_form.html.haml
  1 +- if @repository.contribution_guide && !@merge_request.persisted?
  2 + - contribution_guide_url = project_blob_path(@project, tree_join(@repository.root_ref, @repository.contribution_guide.name))
  3 + .alert.alert-info.col-sm-10.col-sm-offset-2
  4 + ="Please review the <strong>#{link_to "guidelines for contribution", contribution_guide_url}</strong> to this repository.".html_safe
1 = form_for [@project, @merge_request], html: { class: "merge-request-form form-horizontal" } do |f| 5 = form_for [@project, @merge_request], html: { class: "merge-request-form form-horizontal" } do |f|
2 -if @merge_request.errors.any? 6 -if @merge_request.errors.any?
3 .alert.alert-danger 7 .alert.alert-danger