BigW Consortium Gitlab

flowdock_service.rb 972 Bytes
Newer Older
1 2
require "flowdock-git-hook"

3
class FlowdockService < Service
4
  prop_accessor :token
5 6 7 8 9 10 11 12 13 14
  validates :token, presence: true, if: :activated?

  def title
    'Flowdock'
  end

  def description
    'Flowdock is a collaboration web app for technical teams.'
  end

15
  def self.to_param
16 17 18 19 20
    'flowdock'
  end

  def fields
    [
21
      { type: 'text', name: 'token', placeholder: 'Flowdock Git source token' }
22 23 24
    ]
  end

25
  def self.supported_events
26 27 28
    %w(push)
  end

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

32
    Flowdock::Git.post(
33 34 35
      data[:ref],
      data[:before],
      data[:after],
36
      token: token,
37
      repo: project.repository.path_to_repo,
38 39 40
      repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}",
      commit_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/%s",
      diff_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/compare/%s...%s",
41
    )
42 43
  end
end