Class: HipchatService

Inherits:
Service
  • Object
show all
Defined in:
app/models/project_services/hipchat_service.rb

Overview

Schema Information

Table name: services

id                    :integer          not null, primary key
type                  :string
title                 :string
project_id            :integer
created_at            :datetime         not null
updated_at            :datetime         not null
active                :boolean          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)
note_events           :boolean          default(TRUE), not null
build_events          :boolean          default(FALSE), not null
category              :string           default("common"), not null
default               :boolean          default(FALSE)
wiki_page_events      :boolean          default(TRUE)

Constant Summary collapse

MAX_COMMITS =
3

Instance Method Summary collapse

Methods inherited from Service

#activated?, #async_execute, available_services_names, boolean_accessor, #can_test?, #category, create_from_template, #help, #issue_tracker?, prop_accessor, #reset_updated_properties, #template?, #updated_properties

Instance Method Details

#descriptionObject


43
44
45
# File 'app/models/project_services/hipchat_service.rb', line 43

def description
  'Private group chat and IM'
end

#execute(data) ⇒ Object


69
70
71
72
73
74
# File 'app/models/project_services/hipchat_service.rb', line 69

def execute(data)
  return unless supported_events.include?(data[:object_kind])
  message = create_message(data)
  return unless message.present?
  gate[room].send('GitLab', message, message_options)
end

#fieldsObject


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/project_services/hipchat_service.rb', line 51

def fields
  [
    { type: 'text', name: 'token',     placeholder: 'Room token' },
    { type: 'text', name: 'room',      placeholder: 'Room name or ID' },
    { type: 'checkbox', name: 'notify' },
    { type: 'select', name: 'color', choices: ['yellow', 'red', 'green', 'purple', 'gray', 'random'] },
    { type: 'text', name: 'api_version',
      placeholder: 'Leave blank for default (v2)' },
    { type: 'text', name: 'server',
      placeholder: 'Leave blank for default. https://hipchat.example.com' },
    { type: 'checkbox', name: 'notify_only_broken_builds' },
  ]
end

#initialize_propertiesObject


32
33
34
35
36
37
# File 'app/models/project_services/hipchat_service.rb', line 32

def initialize_properties
  if properties.nil?
    self.properties = {}
    self.notify_only_broken_builds = true
  end
end

#supported_eventsObject


65
66
67
# File 'app/models/project_services/hipchat_service.rb', line 65

def supported_events
  %w(push issue merge_request note tag_push build)
end

#test(data) ⇒ Object


76
77
78
79
80
81
82
83
84
# File 'app/models/project_services/hipchat_service.rb', line 76

def test(data)
  begin
    result = execute(data)
  rescue StandardError => error
    return { success: false, result: error }
  end

  { success: true, result: result }
end

#titleObject


39
40
41
# File 'app/models/project_services/hipchat_service.rb', line 39

def title
  'HipChat'
end

#to_paramObject


47
48
49
# File 'app/models/project_services/hipchat_service.rb', line 47

def to_param
  'hipchat'
end