summaryrefslogtreecommitdiff
path: root/app/models/project_services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-24 12:10:31 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-24 12:10:31 +0000
commit1f5ca81aa6e674089c9652484e5f3bb89f86703c (patch)
treeacb5e564d2005766e93b8a5d02be04d7b6107925 /app/models/project_services
parent0a35aa97051a1255e0bd8f12f30afd25ead228ff (diff)
downloadgitlab-ce-1f5ca81aa6e674089c9652484e5f3bb89f86703c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/project_services')
-rw-r--r--app/models/project_services/external_wiki_service.rb50
-rw-r--r--app/models/project_services/flowdock_service.rb50
-rw-r--r--app/models/project_services/irker_service.rb121
-rw-r--r--app/models/project_services/jira_tracker_data.rb12
-rw-r--r--app/models/project_services/packagist_service.rb65
-rw-r--r--app/models/project_services/pipelines_email_service.rb103
-rw-r--r--app/models/project_services/pivotaltracker_service.rb76
7 files changed, 0 insertions, 477 deletions
diff --git a/app/models/project_services/external_wiki_service.rb b/app/models/project_services/external_wiki_service.rb
deleted file mode 100644
index f49b008533d..00000000000
--- a/app/models/project_services/external_wiki_service.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# frozen_string_literal: true
-
-class ExternalWikiService < Integration
- include ActionView::Helpers::UrlHelper
-
- prop_accessor :external_wiki_url
- validates :external_wiki_url, presence: true, public_url: true, if: :activated?
-
- def title
- s_('ExternalWikiService|External wiki')
- end
-
- def description
- s_('ExternalWikiService|Link to an external wiki from the sidebar.')
- end
-
- def self.to_param
- 'external_wiki'
- end
-
- def fields
- [
- {
- type: 'text',
- name: 'external_wiki_url',
- title: s_('ExternalWikiService|External wiki URL'),
- placeholder: s_('ExternalWikiService|https://example.com/xxx/wiki/...'),
- help: 'Enter the URL to the external wiki.',
- required: true
- }
- ]
- end
-
- def help
- docs_link = link_to _('Learn more.'), Rails.application.routes.url_helpers.help_page_url('user/project/wiki/index', anchor: 'link-an-external-wiki'), target: '_blank', rel: 'noopener noreferrer'
-
- s_('Link an external wiki from the project\'s sidebar. %{docs_link}').html_safe % { docs_link: docs_link.html_safe }
- end
-
- def execute(_data)
- response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true)
- response.body if response.code == 200
- rescue StandardError
- nil
- end
-
- def self.supported_events
- %w()
- end
-end
diff --git a/app/models/project_services/flowdock_service.rb b/app/models/project_services/flowdock_service.rb
deleted file mode 100644
index 7aae5af7454..00000000000
--- a/app/models/project_services/flowdock_service.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# frozen_string_literal: true
-
-class FlowdockService < Integration
- include ActionView::Helpers::UrlHelper
-
- prop_accessor :token
- validates :token, presence: true, if: :activated?
-
- def title
- 'Flowdock'
- end
-
- def description
- s_('FlowdockService|Send event notifications from GitLab to Flowdock flows.')
- end
-
- def help
- docs_link = link_to _('Learn more.'), Rails.application.routes.url_helpers.help_page_url('api/services', anchor: 'flowdock'), target: '_blank', rel: 'noopener noreferrer'
- s_('FlowdockService|Send event notifications from GitLab to Flowdock flows. %{docs_link}').html_safe % { docs_link: docs_link.html_safe }
- end
-
- def self.to_param
- 'flowdock'
- end
-
- def fields
- [
- { type: 'text', name: 'token', placeholder: s_('FlowdockService|1b609b52537...'), required: true, help: 'Enter your Flowdock token.' }
- ]
- end
-
- def self.supported_events
- %w(push)
- end
-
- def execute(data)
- return unless supported_events.include?(data[:object_kind])
-
- Flowdock::Git.post(
- data[:ref],
- data[:before],
- data[:after],
- token: token,
- repo: project.repository,
- repo_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}",
- commit_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/-/commit/%s",
- diff_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/compare/%s...%s"
- )
- end
-end
diff --git a/app/models/project_services/irker_service.rb b/app/models/project_services/irker_service.rb
deleted file mode 100644
index 5cca620c659..00000000000
--- a/app/models/project_services/irker_service.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-# frozen_string_literal: true
-
-require 'uri'
-
-class IrkerService < Integration
- prop_accessor :server_host, :server_port, :default_irc_uri
- prop_accessor :recipients, :channels
- boolean_accessor :colorize_messages
- validates :recipients, presence: true, if: :validate_recipients?
-
- before_validation :get_channels
-
- def title
- 'Irker (IRC gateway)'
- end
-
- def description
- 'Send IRC messages.'
- end
-
- def self.to_param
- 'irker'
- end
-
- def self.supported_events
- %w(push)
- end
-
- def execute(data)
- return unless supported_events.include?(data[:object_kind])
-
- IrkerWorker.perform_async(project_id, channels,
- colorize_messages, data, settings)
- end
-
- def settings
- {
- server_host: server_host.presence || 'localhost',
- server_port: server_port.presence || 6659
- }
- end
-
- def fields
- [
- { type: 'text', name: 'server_host', placeholder: 'localhost',
- help: 'Irker daemon hostname (defaults to localhost)' },
- { type: 'text', name: 'server_port', placeholder: 6659,
- help: 'Irker daemon port (defaults to 6659)' },
- { type: 'text', name: 'default_irc_uri', title: 'Default IRC URI',
- help: 'A default IRC URI to prepend before each recipient (optional)',
- placeholder: 'irc://irc.network.net:6697/' },
- { type: 'textarea', name: 'recipients',
- placeholder: 'Recipients/channels separated by whitespaces', required: true,
- help: 'Recipients have to be specified with a full URI: '\
- 'irc[s]://irc.network.net[:port]/#channel. Special cases: if '\
- 'you want the channel to be a nickname instead, append ",isnick" to ' \
- 'the channel name; if the channel is protected by a secret password, ' \
- ' append "?key=secretpassword" to the URI (Note that due to a bug, if you ' \
- ' want to use a password, you have to omit the "#" on the channel). If you ' \
- ' specify a default IRC URI to prepend before each recipient, you can just ' \
- ' give a channel name.' },
- { type: 'checkbox', name: 'colorize_messages' }
- ]
- end
-
- def help
- ' NOTE: Irker does NOT have built-in authentication, which makes it' \
- ' vulnerable to spamming IRC channels if it is hosted outside of a ' \
- ' firewall. Please make sure you run the daemon within a secured network ' \
- ' to prevent abuse. For more details, read: http://www.catb.org/~esr/irker/security.html.'
- end
-
- private
-
- def get_channels
- return true unless activated?
- return true if recipients.nil? || recipients.empty?
-
- map_recipients
-
- errors.add(:recipients, 'are all invalid') if channels.empty?
- true
- end
-
- def map_recipients
- self.channels = recipients.split(/\s+/).map do |recipient|
- format_channel(recipient)
- end
- channels.reject!(&:nil?)
- end
-
- def format_channel(recipient)
- uri = nil
-
- # Try to parse the chan as a full URI
- begin
- uri = consider_uri(URI.parse(recipient))
- rescue URI::InvalidURIError
- end
-
- unless uri.present? && default_irc_uri.nil?
- begin
- new_recipient = URI.join(default_irc_uri, '/', recipient).to_s
- uri = consider_uri(URI.parse(new_recipient))
- rescue StandardError
- log_error("Unable to create a valid URL", default_irc_uri: default_irc_uri, recipient: recipient)
- end
- end
-
- uri
- end
-
- def consider_uri(uri)
- return if uri.scheme.nil?
-
- # Authorize both irc://domain.com/#chan and irc://domain.com/chan
- if uri.is_a?(URI) && uri.scheme[/^ircs?\z/] && !uri.path.nil?
- uri.to_s
- end
- end
-end
diff --git a/app/models/project_services/jira_tracker_data.rb b/app/models/project_services/jira_tracker_data.rb
index 2c145abf5c9..00b6ab6a70f 100644
--- a/app/models/project_services/jira_tracker_data.rb
+++ b/app/models/project_services/jira_tracker_data.rb
@@ -2,18 +2,6 @@
class JiraTrackerData < ApplicationRecord
include Services::DataFields
- include IgnorableColumns
-
- ignore_columns %i[
- encrypted_proxy_address
- encrypted_proxy_address_iv
- encrypted_proxy_port
- encrypted_proxy_port_iv
- encrypted_proxy_username
- encrypted_proxy_username_iv
- encrypted_proxy_password
- encrypted_proxy_password_iv
- ], remove_with: '14.0', remove_after: '2021-05-22'
attr_encrypted :url, encryption_options
attr_encrypted :api_url, encryption_options
diff --git a/app/models/project_services/packagist_service.rb b/app/models/project_services/packagist_service.rb
deleted file mode 100644
index f3ea8c64302..00000000000
--- a/app/models/project_services/packagist_service.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-# frozen_string_literal: true
-
-class PackagistService < Integration
- prop_accessor :username, :token, :server
-
- validates :username, presence: true, if: :activated?
- validates :token, presence: true, if: :activated?
-
- default_value_for :push_events, true
- default_value_for :tag_push_events, true
-
- after_save :compose_service_hook, if: :activated?
-
- def title
- 'Packagist'
- end
-
- def description
- s_('Integrations|Update your Packagist projects.')
- end
-
- def self.to_param
- 'packagist'
- end
-
- def fields
- [
- { type: 'text', name: 'username', placeholder: '', required: true },
- { type: 'text', name: 'token', placeholder: '', required: true },
- { type: 'text', name: 'server', placeholder: 'https://packagist.org', required: false }
- ]
- end
-
- def self.supported_events
- %w(push merge_request tag_push)
- end
-
- def execute(data)
- return unless supported_events.include?(data[:object_kind])
-
- service_hook.execute(data)
- end
-
- def test(data)
- begin
- result = execute(data)
- return { success: false, result: result[:message] } if result[:http_status] != 202
- rescue StandardError => error
- return { success: false, result: error }
- end
-
- { success: true, result: result[:message] }
- end
-
- def compose_service_hook
- hook = service_hook || build_service_hook
- hook.url = hook_url
- hook.save
- end
-
- def hook_url
- base_url = server.presence || 'https://packagist.org'
- "#{base_url}/api/update-package?username=#{username}&apiToken=#{token}"
- end
-end
diff --git a/app/models/project_services/pipelines_email_service.rb b/app/models/project_services/pipelines_email_service.rb
deleted file mode 100644
index 4603193ac8e..00000000000
--- a/app/models/project_services/pipelines_email_service.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-# frozen_string_literal: true
-
-class PipelinesEmailService < Integration
- include NotificationBranchSelection
-
- prop_accessor :recipients, :branches_to_be_notified
- boolean_accessor :notify_only_broken_pipelines, :notify_only_default_branch
- validates :recipients, presence: true, if: :validate_recipients?
-
- def initialize_properties
- if properties.nil?
- self.properties = {}
- self.notify_only_broken_pipelines = true
- self.branches_to_be_notified = "default"
- elsif !self.notify_only_default_branch.nil?
- # In older versions, there was only a boolean property named
- # `notify_only_default_branch`. Now we have a string property named
- # `branches_to_be_notified`. Instead of doing a background migration, we
- # opted to set a value for the new property based on the old one, if
- # users hasn't specified one already. When users edit the service and
- # selects a value for this new property, it will override everything.
-
- self.branches_to_be_notified ||= notify_only_default_branch? ? "default" : "all"
- end
- end
-
- def title
- _('Pipeline status emails')
- end
-
- def description
- _('Email the pipeline status to a list of recipients.')
- end
-
- def self.to_param
- 'pipelines_email'
- end
-
- def self.supported_events
- %w[pipeline]
- end
-
- def self.default_test_event
- 'pipeline'
- end
-
- def execute(data, force: false)
- return unless supported_events.include?(data[:object_kind])
- return unless force || should_pipeline_be_notified?(data)
-
- all_recipients = retrieve_recipients(data)
-
- return unless all_recipients.any?
-
- pipeline_id = data[:object_attributes][:id]
- PipelineNotificationWorker.new.perform(pipeline_id, recipients: all_recipients)
- end
-
- def can_test?
- project&.ci_pipelines&.any?
- end
-
- def fields
- [
- { type: 'textarea',
- name: 'recipients',
- help: _('Comma-separated list of email addresses.'),
- required: true },
- { type: 'checkbox',
- name: 'notify_only_broken_pipelines' },
- { type: 'select',
- name: 'branches_to_be_notified',
- choices: branch_choices }
- ]
- end
-
- def test(data)
- result = execute(data, force: true)
-
- { success: true, result: result }
- rescue StandardError => error
- { success: false, result: error }
- end
-
- def should_pipeline_be_notified?(data)
- notify_for_branch?(data) && notify_for_pipeline?(data)
- end
-
- def notify_for_pipeline?(data)
- case data[:object_attributes][:status]
- when 'success'
- !notify_only_broken_pipelines?
- when 'failed'
- true
- else
- false
- end
- end
-
- def retrieve_recipients(data)
- recipients.to_s.split(/[,\r\n ]+/).reject(&:empty?)
- end
-end
diff --git a/app/models/project_services/pivotaltracker_service.rb b/app/models/project_services/pivotaltracker_service.rb
deleted file mode 100644
index 6e67984591d..00000000000
--- a/app/models/project_services/pivotaltracker_service.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# frozen_string_literal: true
-
-class PivotaltrackerService < Integration
- API_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/source_commits'
-
- prop_accessor :token, :restrict_to_branch
- validates :token, presence: true, if: :activated?
-
- def title
- 'PivotalTracker'
- end
-
- def description
- s_('PivotalTrackerService|Add commit messages as comments to PivotalTracker stories.')
- end
-
- def self.to_param
- 'pivotaltracker'
- end
-
- def fields
- [
- {
- type: 'text',
- name: 'token',
- placeholder: s_('PivotalTrackerService|Pivotal Tracker API token.'),
- required: true
- },
- {
- type: 'text',
- name: 'restrict_to_branch',
- placeholder: s_('PivotalTrackerService|Comma-separated list of branches which will be ' \
- 'automatically inspected. Leave blank to include all branches.')
- }
- ]
- end
-
- def self.supported_events
- %w(push)
- end
-
- def execute(data)
- return unless supported_events.include?(data[:object_kind])
- return unless allowed_branch?(data[:ref])
-
- data[:commits].each do |commit|
- message = {
- 'source_commit' => {
- 'commit_id' => commit[:id],
- 'author' => commit[:author][:name],
- 'url' => commit[:url],
- 'message' => commit[:message]
- }
- }
- Gitlab::HTTP.post(
- API_ENDPOINT,
- body: message.to_json,
- headers: {
- 'Content-Type' => 'application/json',
- 'X-TrackerToken' => token
- }
- )
- end
- end
-
- private
-
- def allowed_branch?(ref)
- return true unless ref.present? && restrict_to_branch.present?
-
- branch = Gitlab::Git.ref_name(ref)
- allowed_branches = restrict_to_branch.split(',').map(&:strip)
-
- branch.present? && allowed_branches.include?(branch)
- end
-end