flowdock_service.rb 1.24 KB
Newer Older
1 2 3 4 5 6 7 8
# == Schema Information
#
# Table name: services
#
#  id          :integer          not null, primary key
#  type        :string(255)
#  title       :string(255)
#  project_id  :integer          not null
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
9 10
#  created_at  :datetime
#  updated_at  :datetime
11
#  active      :boolean          default(FALSE), not null
12
#  properties  :text
13 14
#

15 16
require "flowdock-git-hook"

17
class FlowdockService < Service
18
  prop_accessor :token
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
  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
    [
      { type: 'text', name: 'token',     placeholder: '' }
    ]
  end

  def execute(push_data)
    repo_path = File.join(Gitlab.config.gitlab_shell.repos_path, "#{project.path_with_namespace}.git")
    Flowdock::Git.post(
      push_data[:ref],
      push_data[:before],
      push_data[:after],
      token: token,
      repo: repo_path,
      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