Commit a1e5d4e8b5788087cba478530e3a0352cdef363e
Exists in
spb-stable
and in
3 other branches
Merge pull request #6382 from jvanbaarsen/contribution-guide-link
Contribution guide link
Showing
6 changed files
with
24 additions
and
4 deletions
Show diff stats
Gemfile
| ... | ... | @@ -32,7 +32,7 @@ gem 'omniauth-github' |
| 32 | 32 | |
| 33 | 33 | # Extracting information from a git repository |
| 34 | 34 | # Provide access to Gitlab::Git library |
| 35 | -gem "gitlab_git", '~> 5.4.0' | |
| 35 | +gem "gitlab_git", '~> 5.5.0' | |
| 36 | 36 | |
| 37 | 37 | # Ruby/Rack Git Smart-HTTP Server Handler |
| 38 | 38 | gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' | ... | ... |
Gemfile.lock
| ... | ... | @@ -181,7 +181,7 @@ GEM |
| 181 | 181 | charlock_holmes (~> 0.6.6) |
| 182 | 182 | escape_utils (~> 0.2.4) |
| 183 | 183 | mime-types (~> 1.19) |
| 184 | - gitlab_git (5.4.0) | |
| 184 | + gitlab_git (5.5.0) | |
| 185 | 185 | activesupport (~> 4.0.0) |
| 186 | 186 | charlock_holmes (~> 0.6.9) |
| 187 | 187 | gitlab-grit (~> 2.6.1) |
| ... | ... | @@ -590,7 +590,7 @@ DEPENDENCIES |
| 590 | 590 | gitlab-gollum-lib (~> 1.1.0) |
| 591 | 591 | gitlab-grack (~> 2.0.0.pre) |
| 592 | 592 | gitlab-linguist (~> 3.0.0) |
| 593 | - gitlab_git (~> 5.4.0) | |
| 593 | + gitlab_git (~> 5.5.0) | |
| 594 | 594 | gitlab_meta (= 6.0) |
| 595 | 595 | gitlab_omniauth-ldap (= 1.0.4) |
| 596 | 596 | gon (~> 5.0.0) | ... | ... |
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 | ... | ... |