diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-03-07 01:08:28 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-03-07 02:46:13 +0300 |
commit | 4dddaef8661c8bfb5127d5db12b91d18cfcf0b8f (patch) | |
tree | 565f40f93c24c8c188dabcc1470f7b7c6ceb40b9 /lib/gitlab/reference_extractor.rb | |
parent | 0625d68f7510a2f2203bfe2c57f5927a0121c561 (diff) |
Automatically link commit ranges to compare page.
Diffstat (limited to 'lib/gitlab/reference_extractor.rb')
-rw-r--r-- | lib/gitlab/reference_extractor.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index 7e5c991a222..5b9772de168 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -1,13 +1,13 @@ module Gitlab # Extract possible GFM references from an arbitrary String for further processing. class ReferenceExtractor - attr_accessor :users, :labels, :issues, :merge_requests, :snippets, :commits + attr_accessor :users, :labels, :issues, :merge_requests, :snippets, :commits, :commit_ranges include Markdown def initialize - @users, @labels, @issues, @merge_requests, @snippets, @commits = - [], [], [], [], [], [] + @users, @labels, @issues, @merge_requests, @snippets, @commits, @commit_ranges = + [], [], [], [], [], [], [] end def analyze(string, project) @@ -60,6 +60,16 @@ module Gitlab end.reject(&:nil?) end + def commit_ranges_for(project = nil) + commit_ranges.map do |entry| + repo = entry[:project].repository if entry[:project] + if repo && should_lookup?(project, entry[:project]) + from_id, to_id = entry[:id].split(/\.{2,3}/, 2) + [repo.commit(from_id), repo.commit(to_id)] + end + end.reject(&:nil?) + end + private def reference_link(type, identifier, project, _) |