diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-26 00:09:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-26 00:09:23 +0300 |
commit | 32fd4cd5e2134511936899d6bcc4aaf18b9be6fd (patch) | |
tree | 10378ceffed52dd0e160a0d9bcf3c5ab72c18958 /app/models | |
parent | 951616a26a61e880860ad862c1d45a8e3762b4bc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build.rb | 18 | ||||
-rw-r--r-- | app/models/environment_status.rb | 14 | ||||
-rw-r--r-- | app/models/pages_domain.rb | 4 | ||||
-rw-r--r-- | app/models/project_services/chat_message/base_message.rb | 4 | ||||
-rw-r--r-- | app/models/project_services/chat_message/pipeline_message.rb | 9 | ||||
-rw-r--r-- | app/models/project_services/chat_message/push_message.rb | 2 | ||||
-rw-r--r-- | app/models/project_services/chat_notification_service.rb | 4 | ||||
-rw-r--r-- | app/models/project_services/slack_service.rb | 16 | ||||
-rw-r--r-- | app/models/project_services/slack_slash_commands_service.rb | 2 | ||||
-rw-r--r-- | app/models/snippet.rb | 2 |
10 files changed, 46 insertions, 29 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index d61f0bbfb10..f79a5682963 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -531,6 +531,7 @@ module Ci .concat(persisted_variables) .concat(scoped_variables) .concat(job_variables) + .concat(environment_changed_page_variables) .concat(persisted_environment_variables) .to_runner_variables end @@ -569,6 +570,15 @@ module Ci end end + def environment_changed_page_variables + Gitlab::Ci::Variables::Collection.new.tap do |variables| + break variables unless environment_status + + variables.append(key: 'CI_MERGE_REQUEST_CHANGED_PAGE_PATHS', value: environment_status.changed_paths.join(',')) + variables.append(key: 'CI_MERGE_REQUEST_CHANGED_PAGE_URLS', value: environment_status.changed_urls.join(',')) + end + end + def deploy_token_variables Gitlab::Ci::Variables::Collection.new.tap do |variables| break variables unless gitlab_deploy_token @@ -970,6 +980,14 @@ module Ci options&.dig(:environment, :url) || persisted_environment&.external_url end + def environment_status + strong_memoize(:environment_status) do + if has_environment? && merge_request + EnvironmentStatus.new(project, persisted_environment, merge_request, pipeline.sha) + end + end + end + # The format of the retry option changed in GitLab 11.5: Before it was # integer only, after it is a hash. New builds are created with the new # format, but builds created before GitLab 11.5 and saved in database still diff --git a/app/models/environment_status.rb b/app/models/environment_status.rb index 5fdb5af2d9b..46e41c22139 100644 --- a/app/models/environment_status.rb +++ b/app/models/environment_status.rb @@ -62,9 +62,9 @@ class EnvironmentStatus end def changes - return [] unless has_route_map? - - changed_files.map { |file| build_change(file) }.compact + strong_memoize(:changes) do + has_route_map? ? changed_files.map { |file| build_change(file) }.compact : [] + end end def changed_files @@ -72,6 +72,14 @@ class EnvironmentStatus .merge_request_diff_files.where(deleted_file: false) end + def changed_paths + changes.map { |change| change[:path] } + end + + def changed_urls + changes.map { |change| change[:external_url] } + end + def has_route_map? project.route_map_for(sha).present? end diff --git a/app/models/pages_domain.rb b/app/models/pages_domain.rb index 814c970f745..37d45c5934d 100644 --- a/app/models/pages_domain.rb +++ b/app/models/pages_domain.rb @@ -68,6 +68,10 @@ class PagesDomain < ApplicationRecord scope :instance_serverless, -> { where(wildcard: true, scope: :instance, usage: :serverless) } + def self.find_by_domain_case_insensitive(domain) + find_by("LOWER(domain) = LOWER(?)", domain) + end + def verified? !!verified_at end diff --git a/app/models/project_services/chat_message/base_message.rb b/app/models/project_services/chat_message/base_message.rb index 49151ad24cb..bdd77a919e3 100644 --- a/app/models/project_services/chat_message/base_message.rb +++ b/app/models/project_services/chat_message/base_message.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'slack-notifier' - module ChatMessage class BaseMessage RELATIVE_LINK_REGEX = /!\[[^\]]*\]\((\/uploads\/[^\)]*)\)/.freeze @@ -59,7 +57,7 @@ module ChatMessage end def format(string) - Slack::Notifier::LinkFormatter.format(format_relative_links(string)) + Slack::Messenger::Util::LinkFormatter.format(format_relative_links(string)) end def format_relative_links(string) diff --git a/app/models/project_services/chat_message/pipeline_message.rb b/app/models/project_services/chat_message/pipeline_message.rb index 46fe894cfc3..52a26f6211a 100644 --- a/app/models/project_services/chat_message/pipeline_message.rb +++ b/app/models/project_services/chat_message/pipeline_message.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require 'slack-notifier' module ChatMessage class PipelineMessage < BaseMessage @@ -98,7 +97,7 @@ module ChatMessage def failed_stages_field { title: s_("ChatMessage|Failed stage").pluralize(failed_stages.length), - value: Slack::Notifier::LinkFormatter.format(failed_stages_links), + value: Slack::Messenger::Util::LinkFormatter.format(failed_stages_links), short: true } end @@ -106,7 +105,7 @@ module ChatMessage def failed_jobs_field { title: s_("ChatMessage|Failed job").pluralize(failed_jobs.length), - value: Slack::Notifier::LinkFormatter.format(failed_jobs_links), + value: Slack::Messenger::Util::LinkFormatter.format(failed_jobs_links), short: true } end @@ -123,12 +122,12 @@ module ChatMessage fields = [ { title: ref_type == "tag" ? s_("ChatMessage|Tag") : s_("ChatMessage|Branch"), - value: Slack::Notifier::LinkFormatter.format(ref_link), + value: Slack::Messenger::Util::LinkFormatter.format(ref_link), short: true }, { title: s_("ChatMessage|Commit"), - value: Slack::Notifier::LinkFormatter.format(commit_link), + value: Slack::Messenger::Util::LinkFormatter.format(commit_link), short: true } ] diff --git a/app/models/project_services/chat_message/push_message.rb b/app/models/project_services/chat_message/push_message.rb index 41b0cbb2c4d..c8e70a69c88 100644 --- a/app/models/project_services/chat_message/push_message.rb +++ b/app/models/project_services/chat_message/push_message.rb @@ -48,7 +48,7 @@ module ChatMessage end def format(string) - Slack::Notifier::LinkFormatter.format(string) + Slack::Messenger::Util::LinkFormatter.format(string) end def commit_messages diff --git a/app/models/project_services/chat_notification_service.rb b/app/models/project_services/chat_notification_service.rb index 46c8260ab48..7bd011101dd 100644 --- a/app/models/project_services/chat_notification_service.rb +++ b/app/models/project_services/chat_notification_service.rb @@ -84,10 +84,10 @@ class ChatNotificationService < Service event_type = data[:event_type] || object_kind - channel_name = get_channel_field(event_type).presence || channel + channel_names = get_channel_field(event_type).presence || channel opts = {} - opts[:channel] = channel_name if channel_name + opts[:channel] = channel_names.split(',').map(&:strip) if channel_names opts[:username] = username if username return false unless notify(message, opts) diff --git a/app/models/project_services/slack_service.rb b/app/models/project_services/slack_service.rb index 7290964f442..6d567bb1383 100644 --- a/app/models/project_services/slack_service.rb +++ b/app/models/project_services/slack_service.rb @@ -13,18 +13,8 @@ class SlackService < ChatNotificationService 'slack' end - def help - 'This service sends notifications about projects events to Slack channels.<br /> - To set up this service: - <ol> - <li><a href="https://slack.com/apps/A0F7XDUAZ-incoming-webhooks">Add an incoming webhook</a> in your Slack team. The default channel can be overridden for each event.</li> - <li>Paste the <strong>Webhook URL</strong> into the field below.</li> - <li>Select events below to enable notifications. The <strong>Channel name</strong> and <strong>Username</strong> fields are optional.</li> - </ol>' - end - def default_channel_placeholder - "Channel name (e.g. general)" + _('Slack channels (e.g. general, development)') end def webhook_placeholder @@ -35,8 +25,8 @@ class SlackService < ChatNotificationService private def notify(message, opts) - # See https://github.com/stevenosloan/slack-notifier#custom-http-client - notifier = Slack::Notifier.new(webhook, opts.merge(http_client: HTTPClient)) + # See https://gitlab.com/gitlab-org/slack-notifier/#custom-http-client + notifier = Slack::Messenger.new(webhook, opts.merge(http_client: HTTPClient)) notifier.ping( message.pretext, diff --git a/app/models/project_services/slack_slash_commands_service.rb b/app/models/project_services/slack_slash_commands_service.rb index 6a454070fe2..01ded0495a7 100644 --- a/app/models/project_services/slack_slash_commands_service.rb +++ b/app/models/project_services/slack_slash_commands_service.rb @@ -29,6 +29,6 @@ class SlackSlashCommandsService < SlashCommandsService private def format(text) - Slack::Notifier::LinkFormatter.format(text) if text + Slack::Messenger::Util::LinkFormatter.format(text) if text end end diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 745700b1c65..8f162f17ac5 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -17,7 +17,7 @@ class Snippet < ApplicationRecord include HasRepository extend ::Gitlab::Utils::Override - ignore_column :repository_storage, remove_with: '12.10', remove_after: '2020-04-22' + ignore_column :repository_storage, remove_with: '12.10', remove_after: '2020-03-22' cache_markdown_field :title, pipeline: :single_line cache_markdown_field :description |