Welcome to mirror list, hosted at ThFree Co, Russian Federation.

squash_tm.rb « integrations « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0a63b5ae6aa817d8cbebac9f1ab15a8f54c1038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true

module Integrations
  class SquashTm < Integration
    include HasWebHook

    field :url,
      placeholder: 'https://your-instance.squashcloud.io/squash/plugin/xsquash4gitlab/webhook/issue',
      title: -> { s_('SquashTmIntegration|Squash TM webhook URL') },
      exposes_secrets: true,
      required: true

    field :token,
      type: 'password',
      title: -> { s_('SquashTmIntegration|Secret token (optional)') },
      non_empty_password_title: -> { s_('ProjectService|Enter new token') },
      non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') },
      required: false

    with_options if: :activated? do
      validates :url, presence: true, public_url: true
      validates :token, length: { maximum: 255 }, allow_blank: true
    end

    def title
      'Squash TM'
    end

    def description
      s_("SquashTmIntegration|Update Squash TM requirements when GitLab issues are modified.")
    end

    def help
      docs_link = ActionController::Base.helpers.link_to(
        _('Learn more.'),
        Rails.application.routes.url_helpers.help_page_url('user/project/integrations/squash_tm'),
        target: '_blank',
        rel: 'noopener noreferrer'
      )

      Kernel.format(
        s_('SquashTmIntegration|Update Squash TM requirements when GitLab issues are modified. %{docs_link}'),
        { docs_link: docs_link.html_safe }
      ).html_safe
    end

    def self.supported_events
      %w[issue confidential_issue]
    end

    def self.to_param
      'squash_tm'
    end

    def self.default_test_event
      'issue'
    end

    def execute(data)
      return unless supported_events.include?(data[:object_kind])

      execute_web_hook!(data, "#{data[:object_kind]} Hook")
    end

    def test(data)
      result = execute_web_hook!(data, "Test Configuration Hook")

      { success: result.payload[:http_status] == 200, result: result.message }
    rescue StandardError => error
      { success: false, result: error.message }
    end

    override :hook_url
    def hook_url
      format("#{url}%s", ('?token={token}' unless token.blank?))
    end

    def url_variables
      { 'token' => token }.compact
    end
  end
end