diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-04-21 18:06:26 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-04-25 14:41:06 -0400 |
commit | 6bac823ad4e7de25d478a96097386ecde3b1dc3b (patch) | |
tree | c92b9816cc4ced7c08408fea6bd46b355c3fb050 /lib | |
parent | a8e6656481fecce33339ab1e9ad42a6b9f0ed1bf (diff) | |
download | gitlab-ce-6bac823ad4e7de25d478a96097386ecde3b1dc3b.tar.gz |
Update CommitRangeReferenceFilter to use CommitRange class
Also matches CommitReferenceFilter's new behavior of always using short
SHAs in the link text.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/markdown/commit_range_reference_filter.rb | 43 |
1 files changed, 10 insertions, 33 deletions
diff --git a/lib/gitlab/markdown/commit_range_reference_filter.rb b/lib/gitlab/markdown/commit_range_reference_filter.rb index 5e5e7adc238..c37bb9463bd 100644 --- a/lib/gitlab/markdown/commit_range_reference_filter.rb +++ b/lib/gitlab/markdown/commit_range_reference_filter.rb @@ -32,11 +32,8 @@ module Gitlab # Pattern used to extract commit range references from text # - # The beginning and ending SHA1 sums can be between 6 and 40 hex - # characters, and the range selection can be double- or triple-dot. - # # This pattern supports cross-project references. - COMMIT_RANGE_PATTERN = /(#{PROJECT_PATTERN}@)?(?<commit_range>\h{6,40}\.{2,3}\h{6,40})/ + COMMIT_RANGE_PATTERN = /(#{PROJECT_PATTERN}@)?(?<commit_range>#{CommitRange::PATTERN})/ def call replace_text_nodes_matching(COMMIT_RANGE_PATTERN) do |content| @@ -53,54 +50,34 @@ module Gitlab # links have `gfm` and `gfm-commit_range` class names attached for # styling. def commit_range_link_filter(text) - self.class.references_in(text) do |match, commit_range, project_ref| + self.class.references_in(text) do |match, id, project_ref| project = self.project_from_ref(project_ref) - from_id, to_id = split_commit_range(commit_range) + range = CommitRange.new(id, project) - if valid_range?(project, from_id, to_id) - push_result(:commit_range, [commit(from_id), commit(to_id)]) + if range.valid_commits? + push_result(:commit_range, range.to_a) - url = url_for_commit_range(project, from_id, to_id) + url = url_for_commit_range(project, range) - title = "Commits #{from_id} through #{to_id}" + title = range.reference_title klass = reference_class(:commit_range) project_ref += '@' if project_ref %(<a href="#{url}" title="#{title}" - class="#{klass}">#{project_ref}#{commit_range}</a>) + class="#{klass}">#{project_ref}#{range}</a>) else match end end end - def split_commit_range(range) - from_id, to_id = range.split(/\.{2,3}/, 2) - from_id << "^" if range !~ /\.{3}/ - - [from_id, to_id] - end - - def commit(id) - unless @commit_map[id] - @commit_map[id] = project.commit(id) - end - - @commit_map[id] - end - - def valid_range?(project, from_id, to_id) - project && project.valid_repo? && commit(from_id) && commit(to_id) - end - - def url_for_commit_range(project, from_id, to_id) + def url_for_commit_range(project, range) h = Rails.application.routes.url_helpers h.namespace_project_compare_url(project.namespace, project, - from: from_id, to: to_id, - only_path: context[:only_path]) + range.to_param.merge(only_path: context[:only_path])) end end end |