Commit 7754ccf1 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Read the Docs integration

Closes #282

Generic GitLab does not need an Read the Docs integration, since
Read the Docs has a Gitlab integration, but Heptapod needs one.

This integration is disabled for Git repositories (not yet available
in the Web UI, but partly working on Heptapod 0.13).

Since the URL target should most of the times be under
https://readthedocs.io, the TLS verification is enabled by default.

This will send a POST to readthedocs for each named branch. We may
want to complement with some filtering later on.

--HG--
branch : heptapod-stable
parent 0f6b2b3661a2
......@@ -165,6 +165,7 @@ class Project < ApplicationRecord
has_one :pushover_service
has_one :jira_service
has_one :redmine_service
has_one :readthedocs_service
has_one :youtrack_service
has_one :custom_issue_tracker_service
has_one :bugzilla_service
......@@ -1148,7 +1149,14 @@ def find_or_initialize_services(exceptions: [])
end
def disabled_services
[]
if mercurial?
[]
else
# Heptapod Read the Doc integration is for Mercurial only (assumes
# namings of branches). On Git repos, it's not needed: Read the Docs
# has a Gitlab integration, meant for the generic GitLab outgoing webhook.
["readthedocs"]
end
end
def find_or_initialize_service(name)
......
# coding: utf-8
# frozen_string_literal: true
# Send webhook to Read the docs according to https://docs.readthedocs.io/en/stable/webhooks.html#using-the-generic-api-integration
#
# we don't use the `ServiceHook` subsystem in this integration, because
# it is meant to pass the token in query params, and Read the Docs reference
# cited above instructs to send it as form data.
class ReadthedocsService < Service
boolean_accessor :skip_tls_verification
prop_accessor :project_url, :token
validates :project_url, presence: true, public_url: true, if: :activated?
validates :token, presence: true, if: :activated?
def title
'Read the Docs'
end
def description
'Automate Read the Docs builds upon changes'
end
def self.to_param
'readthedocs'
end
def self.supported_events
%w(push)
end
def help
'This service sends notifications about branch changes to Read the Docs
to trigger new builds.
To set up this service:
- Refer to the [Read the Docs instructions](https://docs.readthedocs.io/en/stable/webhooks.html#using-the-generic-api-integration)
- Paste the **Webhook URL** and the **token** into the fields below.
'
end
def webhook_placeholder
'https://readthedocs.org/api/v2/webhook/example-project/1/'
end
def execute(push_data)
gitlab_branch = Gitlab::Git::branch_name(push_data["ref"])
begin
branch, topic = Gitlab::Mercurial::parse_gitlab_branch_for_hg(
gitlab_branch)
rescue StandardError
# bookmark, TODO yes there could be a more semantic exception for that
return
end
# We don't want to notify Read the Docs for not landed changesets
# hence we filter out topics.
# TODO we could also restrict to a given set of named branches. After
# all only those that are configured on the Read the Docs side will
# be useful. This would require a new field/property.
return unless topic.nil?
Rails.logger.info("readthedocs service/integration "\
"notifying push_data branch=#{push_data['ref']} \
url=#{project_url}")
Gitlab::HTTP.post(project_url, body: { branches: branch, token: token },
verify: !skip_tls_verification?)
end
def fields
[
{ type: 'text', name: 'project_url',
title: 'Read the Docs project webhook URL',
placeholder: webhook_placeholder,
required: true},
{ type: 'password', name: 'token',
title: 'The Read the Docs token',
required: true},
{ type: 'checkbox', name: 'skip_tls_verification',
title: 'Skip TLS/SSL verification',
}
]
end
end
......@@ -274,6 +274,7 @@ def self.available_services_names
pivotaltracker
prometheus
pushover
readthedocs
redmine
youtrack
slack_slash_commands
......
# coding: utf-8
# frozen_string_literal: true
module API
......@@ -598,6 +599,26 @@ def self.services
desc: 'The sound of the notification'
}
],
'readthedocs' => [
{
required: true,
name: :project_url,
type: String,
desc: 'The Read the Docs project webhook URL'
},
{
required: true,
name: :token,
type: String,
desc: 'The Read the Docs token'
},
{
required: false,
name: :skip_tls_verification,
type: Boolean,
desc: 'Skip TLS/SSL verification for communication'
}
],
'redmine' => [
{
required: true,
......@@ -719,6 +740,7 @@ def self.service_classes
::PivotaltrackerService,
::PrometheusService,
::PushoverService,
::ReadthedocsService,
::RedmineService,
::YoutrackService,
::SlackService,
......
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