diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-02 15:06:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-02 15:06:45 +0300 |
commit | bffcdf9bca11a4d43cc40e3f382f03088d36f7c6 (patch) | |
tree | c773436393b7a59b5f6b14388b9fa6402a9bd198 /app/models | |
parent | 259c0cc0c4f8a49001b33d1bee577f4422e16d62 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_setting.rb | 2 | ||||
-rw-r--r-- | app/models/application_setting_implementation.rb | 6 | ||||
-rw-r--r-- | app/models/error_tracking/project_error_tracking_setting.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 1 | ||||
-rw-r--r-- | app/models/project_services/unify_circuit_service.rb | 60 | ||||
-rw-r--r-- | app/models/service.rb | 1 | ||||
-rw-r--r-- | app/models/snippet.rb | 12 |
7 files changed, 81 insertions, 3 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index c681d941e35..4ba0317b580 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -226,6 +226,8 @@ class ApplicationSetting < ApplicationRecord validates :push_event_activities_limit, numericality: { greater_than_or_equal_to: 0 } + validates :snippet_size_limit, numericality: { only_integer: true, greater_than: 0 } + SUPPORTED_KEY_TYPES.each do |type| validates :"#{type}_key_restriction", presence: true, key_restriction: { type: type } end diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index 7bb89f0d1e2..e1eb8d429bb 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -26,7 +26,8 @@ module ApplicationSettingImplementation '/users', '/users/confirmation', '/unsubscribes/', - '/import/github/personal_access_token' + '/import/github/personal_access_token', + '/admin/session' ].freeze class_methods do @@ -139,7 +140,8 @@ module ApplicationSettingImplementation snowplow_app_id: nil, snowplow_iglu_registry_url: nil, custom_http_clone_url_root: nil, - productivity_analytics_start_date: Time.now + productivity_analytics_start_date: Time.now, + snippet_size_limit: 50.megabytes } end diff --git a/app/models/error_tracking/project_error_tracking_setting.rb b/app/models/error_tracking/project_error_tracking_setting.rb index 5b5c1b1b56b..3af14d7eef2 100644 --- a/app/models/error_tracking/project_error_tracking_setting.rb +++ b/app/models/error_tracking/project_error_tracking_setting.rb @@ -104,7 +104,7 @@ module ErrorTracking def calculate_reactive_cache(request, opts) case request when 'list_issues' - { issues: sentry_client.list_issues(**opts.symbolize_keys) } + sentry_client.list_issues(**opts.symbolize_keys) when 'issue_details' { issue: sentry_client.issue_details(**opts.symbolize_keys) diff --git a/app/models/project.rb b/app/models/project.rb index b452f05c590..e3e10d17cc0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -170,6 +170,7 @@ class Project < ApplicationRecord has_one :microsoft_teams_service has_one :packagist_service has_one :hangouts_chat_service + has_one :unify_circuit_service has_one :root_of_fork_network, foreign_key: 'root_project_id', diff --git a/app/models/project_services/unify_circuit_service.rb b/app/models/project_services/unify_circuit_service.rb new file mode 100644 index 00000000000..06f2d10f83b --- /dev/null +++ b/app/models/project_services/unify_circuit_service.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +class UnifyCircuitService < ChatNotificationService + def title + 'Unify Circuit' + end + + def description + 'Receive event notifications in Unify Circuit' + end + + def self.to_param + 'unify_circuit' + end + + def help + 'This service sends notifications about projects events to a Unify Circuit conversation.<br /> + To set up this service: + <ol> + <li><a href="https://www.circuit.com/unifyportalfaqdetail?articleId=164448">Set up an incoming webhook for your conversation</a>. All notifications will come to this conversation.</li> + <li>Paste the <strong>Webhook URL</strong> into the field below.</li> + <li>Select events below to enable notifications.</li> + </ol>' + end + + def event_field(event) + end + + def default_channel_placeholder + end + + def self.supported_events + %w[push issue confidential_issue merge_request note confidential_note tag_push + pipeline wiki_page] + end + + def default_fields + [ + { type: 'text', name: 'webhook', placeholder: "e.g. https://circuit.com/rest/v2/webhooks/incoming/…", required: true }, + { type: 'checkbox', name: 'notify_only_broken_pipelines' }, + { type: 'select', name: 'branches_to_be_notified', choices: BRANCH_CHOICES } + ] + end + + private + + def notify(message, opts) + response = Gitlab::HTTP.post(webhook, body: { + subject: message.project_name, + text: message.pretext, + markdown: true + }.to_json) + + response if response.success? + end + + def custom_data(data) + super(data).merge(markdown: true) + end +end diff --git a/app/models/service.rb b/app/models/service.rb index 08936f7fcbd..95b7c6927cf 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -289,6 +289,7 @@ class Service < ApplicationRecord slack teamcity microsoft_teams + unify_circuit ] if Rails.env.development? diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 51ab94e6f4a..b802ea2fd59 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -46,6 +46,18 @@ class Snippet < ApplicationRecord length: { maximum: 255 } validates :content, presence: true + validates :content, + length: { + maximum: ->(_) { Gitlab::CurrentSettings.snippet_size_limit }, + message: -> (_, data) do + current_value = ActiveSupport::NumberHelper.number_to_human_size(data[:value].size) + max_size = ActiveSupport::NumberHelper.number_to_human_size(Gitlab::CurrentSettings.snippet_size_limit) + + _("is too long (%{current_value}). The maximum size is %{max_size}.") % { current_value: current_value, max_size: max_size } + end + }, + if: :content_changed? + validates :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values } # Scopes |