BigW Consortium Gitlab

flowdock_service.rb 1.67 KB
Newer Older
1 2 3 4
# == Schema Information
#
# Table name: services
#
5 6 7 8 9 10 11 12 13 14 15 16 17
#  id                    :integer          not null, primary key
#  type                  :string(255)
#  title                 :string(255)
#  project_id            :integer
#  created_at            :datetime
#  updated_at            :datetime
#  active                :boolean          default(FALSE), not null
#  properties            :text
#  template              :boolean          default(FALSE)
#  push_events           :boolean          default(TRUE)
#  issues_events         :boolean          default(TRUE)
#  merge_requests_events :boolean          default(TRUE)
#  tag_push_events       :boolean          default(TRUE)
Stan Hu committed
18
#  note_events           :boolean          default(TRUE), not null
19 20
#

21 22
require "flowdock-git-hook"

23
class FlowdockService < Service
24
  prop_accessor :token
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  validates :token, presence: true, if: :activated?

  def title
    'Flowdock'
  end

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

  def to_param
    'flowdock'
  end

  def fields
    [
41
      { type: 'text', name: 'token', placeholder: 'Flowdock Git source token' }
42 43 44
    ]
  end

45 46 47 48
  def supported_events
    %w(push)
  end

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

52
    Flowdock::Git.post(
53 54 55
      data[:ref],
      data[:before],
      data[:after],
56
      token: token,
57
      repo: project.repository.path_to_repo,
58 59 60 61 62 63
      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",
      )
  end
end