Commit bb35c2d36f4f275cda650c1ad47595c287feba10
1 parent
4e0a2e3c
Exists in
spb-stable
and in
3 other branches
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.
Showing
4 changed files
with
21 additions
and
1 deletions
Show diff stats
app/models/repository.rb
... | ... | @@ -134,6 +134,7 @@ class Repository |
134 | 134 | Rails.cache.delete(cache_key(:commit_count)) |
135 | 135 | Rails.cache.delete(cache_key(:graph_log)) |
136 | 136 | Rails.cache.delete(cache_key(:readme)) |
137 | + Rails.cache.delete(cache_key(:contribution_guide)) | |
137 | 138 | end |
138 | 139 | |
139 | 140 | def graph_log |
... | ... | @@ -167,6 +168,12 @@ class Repository |
167 | 168 | end |
168 | 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 | 177 | def head_commit |
171 | 178 | commit(self.root_ref) |
172 | 179 | end | ... | ... |
app/models/tree.rb
1 | 1 | class Tree |
2 | - attr_accessor :entries, :readme | |
2 | + attr_accessor :entries, :readme, :contribution_guide | |
3 | 3 | |
4 | 4 | def initialize(repository, sha, path = '/') |
5 | 5 | path = '/' if path.blank? |
... | ... | @@ -10,6 +10,11 @@ class Tree |
10 | 10 | readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) |
11 | 11 | @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) |
12 | 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 | 18 | end |
14 | 19 | |
15 | 20 | def trees | ... | ... |
app/views/projects/issues/_form.html.haml
1 | 1 | %div.issue-form-holder |
2 | 2 | %h3.page-title= @issue.new_record? ? "New Issue" : "Edit Issue ##{@issue.iid}" |
3 | 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 | 8 | = form_for [@project, @issue], html: { class: 'form-horizontal issue-form' } do |f| |
5 | 9 | -if @issue.errors.any? |
6 | 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 | 5 | = form_for [@project, @merge_request], html: { class: "merge-request-form form-horizontal" } do |f| |
2 | 6 | -if @merge_request.errors.any? |
3 | 7 | .alert.alert-danger | ... | ... |