debian-mirror-gitlab/lib/gitlab/url_builder.rb

57 lines
1.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module Gitlab
class UrlBuilder
2015-09-25 12:07:36 +05:30
include Gitlab::Application.routes.url_helpers
2015-04-26 12:48:37 +05:30
include GitlabRoutingHelper
2014-09-02 18:07:02 +05:30
def initialize(type)
@type = type
end
def build(id)
case @type
when :issue
2015-04-26 12:48:37 +05:30
build_issue_url(id)
when :merge_request
build_merge_request_url(id)
when :note
build_note_url(id)
2014-09-02 18:07:02 +05:30
end
end
private
2015-04-26 12:48:37 +05:30
def build_issue_url(id)
2014-09-02 18:07:02 +05:30
issue = Issue.find(id)
2015-09-25 12:07:36 +05:30
issue_url(issue)
2015-04-26 12:48:37 +05:30
end
def build_merge_request_url(id)
merge_request = MergeRequest.find(id)
2015-09-25 12:07:36 +05:30
merge_request_url(merge_request)
2015-04-26 12:48:37 +05:30
end
def build_note_url(id)
note = Note.find(id)
if note.for_commit?
namespace_project_commit_url(namespace_id: note.project.namespace,
id: note.commit_id,
project_id: note.project,
anchor: "note_#{note.id}")
elsif note.for_issue?
issue = Issue.find(note.noteable_id)
issue_url(issue,
anchor: "note_#{note.id}")
elsif note.for_merge_request?
merge_request = MergeRequest.find(note.noteable_id)
merge_request_url(merge_request,
anchor: "note_#{note.id}")
elsif note.for_project_snippet?
snippet = Snippet.find(note.noteable_id)
project_snippet_url(snippet,
anchor: "note_#{note.id}")
end
2014-09-02 18:07:02 +05:30
end
end
end