Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNikita Verkhovin <vernik91@gmail.com>2015-02-07 14:14:55 +0300
committerNikita Verkhovin <vernik91@gmail.com>2015-02-08 19:35:41 +0300
commit8681cb3137511e51e19f76aef9839be28f8fcd6a (patch)
treef2d5a929763d77b12c4248cc1bb50a01766bcbfe /lib
parent0a34f2dcb562098c481140246f7ac22683b38d76 (diff)
Add labels notes
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])