gitlab_ci_service.rb 885 Bytes
Newer Older
1
2
3
4
# == Schema Information
#
# Table name: services
#
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
5
6
7
8
9
10
11
12
13
#  id          :integer          not null, primary key
#  type        :string(255)
#  title       :string(255)
#  token       :string(255)
#  project_id  :integer          not null
#  created_at  :datetime         not null
#  updated_at  :datetime         not null
#  active      :boolean          default(FALSE), not null
#  project_url :string(255)
14
15
16
17
18
#

class GitlabCiService < Service
  attr_accessible :project_url

19
20
  validates :project_url, presence: true, if: :activated?
  validates :token, presence: true, if: :activated?
21
22
23

  delegate :execute, to: :service_hook, prefix: nil

24
25
26
27
28
  after_save :compose_service_hook, if: :activated?

  def activated?
    active
  end
29
30
31
32
33
34
35

  def compose_service_hook
    hook = service_hook || build_service_hook
    hook.url = [project_url, "/build", "?token=#{token}"].join("")
    hook.save
  end
end