gitlab-org--gitlab-foss/lib/gitlab/url_builder.rb
Stan Hu 7e204cf389 Added comment notification events to HipChat and Slack services.
Supports four different event types all bundled under the "note" event type:

- comments on a commit
- comments on an issue
- comments on a merge request
- comments on a code snippet
2015-03-06 06:54:00 -08:00

60 lines
1.7 KiB
Ruby

module Gitlab
class UrlBuilder
include Rails.application.routes.url_helpers
include GitlabRoutingHelper
def initialize(type)
@type = type
end
def build(id)
case @type
when :issue
build_issue_url(id)
when :merge_request
build_merge_request_url(id)
when :note
build_note_url(id)
end
end
private
def build_issue_url(id)
issue = Issue.find(id)
issue_url(issue, host: Gitlab.config.gitlab['url'])
end
def build_merge_request_url(id)
merge_request = MergeRequest.find(id)
merge_request_url(merge_request, host: Gitlab.config.gitlab['url'])
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,
host: Gitlab.config.gitlab['url'],
anchor: "note_#{note.id}")
elsif note.for_issue?
issue = Issue.find(note.noteable_id)
issue_url(issue,
host: Gitlab.config.gitlab['url'],
anchor: "note_#{note.id}")
elsif note.for_merge_request?
merge_request = MergeRequest.find(note.noteable_id)
merge_request_url(merge_request,
host: Gitlab.config.gitlab['url'],
anchor: "note_#{note.id}")
elsif note.for_project_snippet?
snippet = Snippet.find(note.noteable_id)
snippet_url(snippet,
host: Gitlab.config.gitlab['url'],
anchor: "note_#{note.id}")
end
end
end
end