summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-10 22:19:15 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-10 22:19:15 -0800
commit2dfd21983483bd5fd32b327edb4b02228b377c47 (patch)
treedd33319bf0cfe823c3bd7c99193b85820ec58fe7 /lib
parentc32e52706f98d577b53170d99877483ee9f1fde5 (diff)
parent3c4f7f50fa925a26553f5c6636461b6f6f7641f3 (diff)
downloadgitlab-ce-2dfd21983483bd5fd32b327edb4b02228b377c47.tar.gz
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/markdown.rb18
-rw-r--r--lib/gitlab/reference_extractor.rb11
2 files changed, 25 insertions, 4 deletions
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb
index 78627f413c2..fb0218a2778 100644
--- a/lib/gitlab/markdown.rb
+++ b/lib/gitlab/markdown.rb
@@ -92,7 +92,7 @@ module Gitlab
allowed_tags = ActionView::Base.sanitized_allowed_tags
sanitize text.html_safe,
- attributes: allowed_attributes + %w(id class),
+ attributes: allowed_attributes + %w(id class style),
tags: allowed_tags + %w(table tr td th)
end
@@ -128,6 +128,7 @@ module Gitlab
(?<prefix>\W)? # Prefix
( # Reference
@(?<user>#{NAME_STR}) # User name
+ |~(?<label>\d+) # Label ID
|(?<issue>([A-Z\-]+-)\d+) # JIRA Issue ID
|#{PROJ_STR}?\#(?<issue>([a-zA-Z\-]+-)?\d+) # Issue ID
|#{PROJ_STR}?!(?<merge_request>\d+) # MR ID
@@ -138,7 +139,7 @@ module Gitlab
(?<suffix>\W)? # Suffix
}x.freeze
- TYPES = [:user, :issue, :merge_request, :snippet, :commit].freeze
+ TYPES = [:user, :issue, :label, :merge_request, :snippet, :commit].freeze
def parse_references(text, project = @project)
# parse reference links
@@ -214,6 +215,19 @@ module Gitlab
end
end
+ def reference_label(identifier, project = @project, _ = nil)
+ if label = project.labels.find_by(id: identifier)
+ options = html_options.merge(
+ class: "gfm gfm-label #{html_options[:class]}"
+ )
+ link_to(
+ render_colored_label(label),
+ project_issues_path(project, label_name: label.name),
+ options
+ )
+ end
+ end
+
def reference_issue(identifier, project = @project, prefix_text = nil)
if project.default_issues_tracker?
if project.issue_exists? identifier
diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb
index 99165950aef..0b9177afa4f 100644
--- a/lib/gitlab/reference_extractor.rb
+++ b/lib/gitlab/reference_extractor.rb
@@ -1,12 +1,13 @@
module Gitlab
# Extract possible GFM references from an arbitrary String for further processing.
class ReferenceExtractor
- attr_accessor :users, :issues, :merge_requests, :snippets, :commits
+ attr_accessor :users, :labels, :issues, :merge_requests, :snippets, :commits
include Markdown
def initialize
- @users, @issues, @merge_requests, @snippets, @commits = [], [], [], [], []
+ @users, @labels, @issues, @merge_requests, @snippets, @commits =
+ [], [], [], [], [], []
end
def analyze(string, project)
@@ -22,6 +23,12 @@ module Gitlab
end.reject(&:nil?)
end
+ def labels_for(project = nil)
+ labels.map do |entry|
+ project.labels.where(id: entry[:id]).first
+ end.reject(&:nil?)
+ end
+
def issues_for(project = nil)
issues.map do |entry|
if should_lookup?(project, entry[:project])