Class: BuildkiteService

Inherits:
CiService show all
Defined in:
app/models/project_services/buildkite_service.rb

Constant Summary collapse

ENDPOINT =
"https://buildkite.com"

Instance Method Summary collapse

Methods inherited from CiService

#commit_page, #merge_request_page, #merge_request_status, #valid_token?

Methods inherited from Service

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

Instance Method Details

#build_page(sha, ref) ⇒ Object


72
73
74
# File 'app/models/project_services/buildkite_service.rb', line 72

def build_page(sha, ref)
  "#{project_url}/builds?commit=#{sha}"
end

#commit_status(sha, ref) ⇒ Object


58
59
60
61
62
63
64
65
66
# File 'app/models/project_services/buildkite_service.rb', line 58

def commit_status(sha, ref)
  response = HTTParty.get(commit_status_path(sha), verify: false)

  if response.code == 200 && response['status']
    response['status']
  else
    :error
  end
end

#commit_status_path(sha) ⇒ Object


68
69
70
# File 'app/models/project_services/buildkite_service.rb', line 68

def commit_status_path(sha)
  "#{buildkite_endpoint('gitlab')}/status/#{status_token}.json?commit=#{sha}"
end

#compose_service_hookObject


41
42
43
44
45
46
# File 'app/models/project_services/buildkite_service.rb', line 41

def compose_service_hook
  hook = service_hook || build_service_hook
  hook.url = webhook_url
  hook.enable_ssl_verification = !!enable_ssl_verification
  hook.save
end

#descriptionObject


80
81
82
# File 'app/models/project_services/buildkite_service.rb', line 80

def description
  'Continuous integration and deployments'
end

#execute(data) ⇒ Object


52
53
54
55
56
# File 'app/models/project_services/buildkite_service.rb', line 52

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

  service_hook.execute(data)
end

#fieldsObject


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/project_services/buildkite_service.rb', line 88

def fields
  [
    { type: 'text',
      name: 'token',
      placeholder: 'Buildkite project GitLab token' },

    { type: 'text',
      name: 'project_url',
      placeholder: "#{ENDPOINT}/example/project" },

    { type: 'checkbox',
      name: 'enable_ssl_verification',
      title: "Enable SSL verification" }
  ]
end

#supported_eventsObject


48
49
50
# File 'app/models/project_services/buildkite_service.rb', line 48

def supported_events
  %w(push)
end

#titleObject


76
77
78
# File 'app/models/project_services/buildkite_service.rb', line 76

def title
  'Buildkite'
end

#to_paramObject


84
85
86
# File 'app/models/project_services/buildkite_service.rb', line 84

def to_param
  'buildkite'
end

#webhook_urlObject


37
38
39
# File 'app/models/project_services/buildkite_service.rb', line 37

def webhook_url
  "#{buildkite_endpoint('webhook')}/deliver/#{webhook_token}"
end