2014-06-13 06:34:15 -04:00
|
|
|
module Gitlab
|
|
|
|
class UrlBuilder
|
2015-08-25 21:42:46 -04:00
|
|
|
include Gitlab::Application.routes.url_helpers
|
2015-09-09 08:37:34 -04:00
|
|
|
include GitlabRoutingHelper
|
2014-06-13 06:34:15 -04:00
|
|
|
|
|
|
|
def initialize(type)
|
|
|
|
@type = type
|
|
|
|
end
|
|
|
|
|
|
|
|
def build(id)
|
|
|
|
case @type
|
|
|
|
when :issue
|
2015-03-03 11:01:27 -05:00
|
|
|
build_issue_url(id)
|
2015-02-24 01:50:40 -05:00
|
|
|
when :merge_request
|
2015-03-03 11:01:27 -05:00
|
|
|
build_merge_request_url(id)
|
2015-03-05 13:38:23 -05:00
|
|
|
when :note
|
|
|
|
build_note_url(id)
|
|
|
|
|
2014-06-13 06:34:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-03-03 11:01:27 -05:00
|
|
|
def build_issue_url(id)
|
2014-06-13 06:34:15 -04:00
|
|
|
issue = Issue.find(id)
|
2015-09-04 19:24:01 -04:00
|
|
|
issue_url(issue)
|
2014-06-13 06:34:15 -04:00
|
|
|
end
|
2015-02-24 01:50:40 -05:00
|
|
|
|
2015-03-03 11:01:27 -05:00
|
|
|
def build_merge_request_url(id)
|
2015-02-24 01:50:40 -05:00
|
|
|
merge_request = MergeRequest.find(id)
|
2015-09-04 19:24:01 -04:00
|
|
|
merge_request_url(merge_request)
|
2015-02-24 01:50:40 -05:00
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
|
|
|
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)
|
2015-03-07 14:47:06 -05:00
|
|
|
project_snippet_url(snippet,
|
|
|
|
anchor: "note_#{note.id}")
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
end
|
2014-06-13 06:34:15 -04:00
|
|
|
end
|
|
|
|
end
|