debian-mirror-gitlab/app/models/project_services/external_wiki_service.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2021-06-08 01:23:25 +05:30
class ExternalWikiService < Integration
2021-04-29 21:17:54 +05:30
include ActionView::Helpers::UrlHelper
2021-06-08 01:23:25 +05:30
2015-04-26 12:48:37 +05:30
prop_accessor :external_wiki_url
2018-11-08 19:23:39 +05:30
validates :external_wiki_url, presence: true, public_url: true, if: :activated?
2015-04-26 12:48:37 +05:30
def title
2021-04-29 21:17:54 +05:30
s_('ExternalWikiService|External wiki')
2015-04-26 12:48:37 +05:30
end
def description
2021-04-29 21:17:54 +05:30
s_('ExternalWikiService|Link to an external wiki from the sidebar.')
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
def self.to_param
2015-04-26 12:48:37 +05:30
'external_wiki'
end
def fields
[
2020-03-13 15:44:24 +05:30
{
type: 'text',
name: 'external_wiki_url',
2021-04-29 21:17:54 +05:30
title: s_('ExternalWikiService|External wiki URL'),
placeholder: s_('ExternalWikiService|https://example.com/xxx/wiki/...'),
help: 'Enter the URL to the external wiki.',
2020-03-13 15:44:24 +05:30
required: true
}
2015-04-26 12:48:37 +05:30
]
end
2021-04-29 21:17:54 +05:30
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
2015-04-26 12:48:37 +05:30
def execute(_data)
2021-07-02 01:05:55 +05:30
response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true, use_read_total_timeout: true)
2020-03-13 15:44:24 +05:30
response.body if response.code == 200
2021-06-08 01:23:25 +05:30
rescue StandardError
2020-03-13 15:44:24 +05:30
nil
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
def self.supported_events
%w()
end
2015-04-26 12:48:37 +05:30
end