Commit dabbee65 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix Slack notification URL and remove the usage of Ci::RoutesHelper

parent 0ce5fb71
module Ci
module RoutesHelper
class Base
include Gitlab::Application.routes.url_helpers
def default_url_options
{
host: Settings.gitlab['host'],
protocol: Settings.gitlab['https'] ? "https" : "http",
port: Settings.gitlab['port']
}
end
end
def url_helpers
@url_helpers ||= Base.new
end
def self.method_missing(method, *args, &block)
@url_helpers ||= Base.new
if @url_helpers.respond_to?(method)
@url_helpers.send(method, *args, &block)
else
super method, *args, &block
end
end
end
end
module Ci module Ci
class HipChatMessage class HipChatMessage
include Gitlab::Application.routes.url_helpers
attr_reader :build attr_reader :build
def initialize(build) def initialize(build)
...@@ -8,13 +10,13 @@ module Ci ...@@ -8,13 +10,13 @@ module Ci
def to_s def to_s
lines = Array.new lines = Array.new
lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_url(project)}\">#{project.name}</a> - ") lines.push("<a href=\"#{ci_project_url(project)}\">#{project.name}</a> - ")
if commit.matrix? if commit.matrix?
lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_ref_commits_url(project, commit.ref, commit.sha)}\">Commit ##{commit.id}</a></br>") lines.push("<a href=\"#{ci_project_ref_commits_url(project, commit.ref, commit.sha)}\">Commit ##{commit.id}</a></br>")
else else
first_build = commit.builds_without_retry.first first_build = commit.builds_without_retry.first
lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_build_url(project, first_build)}\">Build '#{first_build.name}' ##{first_build.id}</a></br>") lines.push("<a href=\"#{ci_project_build_url(project, first_build)}\">Build '#{first_build.name}' ##{first_build.id}</a></br>")
end end
lines.push("#{commit.short_sha} #{commit.git_author_name} - #{commit.git_commit_message}</br>") lines.push("#{commit.short_sha} #{commit.git_author_name} - #{commit.git_commit_message}</br>")
......
...@@ -2,6 +2,8 @@ require 'slack-notifier' ...@@ -2,6 +2,8 @@ require 'slack-notifier'
module Ci module Ci
class SlackMessage class SlackMessage
include Gitlab::Application.routes.url_helpers
def initialize(commit) def initialize(commit)
@commit = commit @commit = commit
end end
...@@ -27,7 +29,7 @@ module Ci ...@@ -27,7 +29,7 @@ module Ci
next unless build.failed? next unless build.failed?
fields << { fields << {
title: build.name, title: build.name,
value: "Build <#{Ci::RoutesHelper.ci_project_build_url(project, build)}|\##{build.id}> failed in #{build.duration.to_i} second(s)." value: "Build <#{ci_project_build_url(project, build)}|\##{build.id}> failed in #{build.duration.to_i} second(s)."
} }
end end
end end
...@@ -44,12 +46,12 @@ module Ci ...@@ -44,12 +46,12 @@ module Ci
attr_reader :commit attr_reader :commit
def attachment_message def attachment_message
out = "<#{Ci::RoutesHelper.ci_project_url(project)}|#{project_name}>: " out = "<#{ci_project_url(project)}|#{project_name}>: "
if commit.matrix? if commit.matrix?
out << "Commit <#{Ci::RoutesHelper.ci_project_ref_commits_url(project, commit.ref, commit.sha)}|\##{commit.id}> " out << "Commit <#{ci_project_ref_commits_url(project, commit.ref, commit.sha)}|\##{commit.id}> "
else else
build = commit.builds_without_retry.first build = commit.builds_without_retry.first
out << "Build <#{Ci::RoutesHelper.ci_project_build_path(project, build)}|\##{build.id}> " out << "Build <#{ci_project_build_url(project, build)}|\##{build.id}> "
end end
out << "(<#{commit_sha_link}|#{commit.short_sha}>) " out << "(<#{commit_sha_link}|#{commit.short_sha}>) "
out << "of <#{commit_ref_link}|#{commit.ref}> " out << "of <#{commit_ref_link}|#{commit.ref}> "
......
...@@ -88,7 +88,7 @@ class GitlabCiService < CiService ...@@ -88,7 +88,7 @@ class GitlabCiService < CiService
def build_page(sha, ref) def build_page(sha, ref)
if project.gitlab_ci_project.present? if project.gitlab_ci_project.present?
Ci::RoutesHelper.ci_project_ref_commits_path(project.gitlab_ci_project, ref, sha) ci_project_ref_commits_url(project.gitlab_ci_project, ref, sha)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment