Class: Readiness::GitLab::ProjectWebhooks

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/gitlab/project_webhooks.rb

Overview

Author:

  • Jason Colyer

Since:

  • 1.0.124

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Constructor Details

#initialize(object = {}) ⇒ ProjectWebhooks

Creates a new Readiness::GitLab::ProjectWebhooks instance

Examples:

require 'support_readiness'
Readiness::GitLab::ProjectWebhooks.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.124



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 30

def initialize(object = {})
  @alert_status = object['alert_status']
  @branch_filter_strategy = object['branch_filter_strategy']
  @confidential_issues_events = object['confidential_issues_events']
  @confidential_note_events = object['confidential_note_events']
  @created_at = object['created_at']
  @custom_headers = object['custom_headers']
  @custom_webhook_template = object['custom_webhook_template']
  @deployment_events = object['deployment_events']
  @description = object['description']
  @disabled_until = object['disabled_until']
  @enable_ssl_verification = object['enable_ssl_verification']
  @feature_flag_events = object['feature_flag_events']
  @id = object['id']
  @issues_events = object['issues_events']
  @job_events = object['job_events']
  @merge_requests_events = object['merge_requests_events']
  @name = object['name']
  @note_events = object['note_events']
  @pipeline_events = object['pipeline_events']
  @project_id = object['project_id']
  @push_events = object['push_events']
  @push_events_branch_filter = object['push_events_branch_filter']
  @releases_events = object['releases_events']
  @repository_update_events = object['repository_update_events']
  @resource_access_token_events = object['resource_access_token_events']
  @tag_push_events = object['tag_push_events']
  @token = object['token']
  @url = object['url']
  @url_variables = object['url_variables']
  @wiki_page_events = object['wiki_page_events']
end

Instance Attribute Details

#alert_statusObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def alert_status
  @alert_status
end

#branch_filter_strategyObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def branch_filter_strategy
  @branch_filter_strategy
end

#confidential_issues_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def confidential_issues_events
  @confidential_issues_events
end

#confidential_note_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def confidential_note_events
  @confidential_note_events
end

#created_atObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def created_at
  @created_at
end

#custom_headersObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def custom_headers
  @custom_headers
end

#custom_webhook_templateObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def custom_webhook_template
  @custom_webhook_template
end

#deployment_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def deployment_events
  @deployment_events
end

#descriptionObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def description
  @description
end

#disabled_untilObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def disabled_until
  @disabled_until
end

#enable_ssl_verificationObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def enable_ssl_verification
  @enable_ssl_verification
end

#feature_flag_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def feature_flag_events
  @feature_flag_events
end

#idObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def id
  @id
end

#issues_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def issues_events
  @issues_events
end

#job_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def job_events
  @job_events
end

#merge_requests_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def merge_requests_events
  @merge_requests_events
end

#nameObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def name
  @name
end

#note_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def note_events
  @note_events
end

#pipeline_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def pipeline_events
  @pipeline_events
end

#project_idObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def project_id
  @project_id
end

#push_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def push_events
  @push_events
end

#push_events_branch_filterObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def push_events_branch_filter
  @push_events_branch_filter
end

#releases_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def releases_events
  @releases_events
end

#repository_update_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def repository_update_events
  @repository_update_events
end

#resource_access_token_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def resource_access_token_events
  @resource_access_token_events
end

#tag_push_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def tag_push_events
  @tag_push_events
end

#tokenObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def token
  @token
end

#urlObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def url
  @url
end

#url_variablesObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def url_variables
  @url_variables
end

#wiki_page_eventsObject

Since:

  • 1.0.124



19
20
21
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 19

def wiki_page_events
  @wiki_page_events
end

Class Method Details

.create!(client, hook) ⇒ Object

Creates a project webhook within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
hook = Readiness::GitLab::ProjectWebhooks.new
hook.url = 'http://example.com/hook'
hook.name = 'Hook name'
hook.description = 'Hook description'
hook.project_id = 1083469
hook.push_events = true
hook.custom_webhook_template = '{ "event": "{{object_kind}}" }'
hook.custom_headers = [
  'Authorization'
]
new_hook = Readiness::GitLab::ProjectWebhooks.create!(client, hook)
pp new_hook.id
# => 1

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.124



216
217
218
219
220
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 216

def self.create!(client, hook)
  response = client.connection.post "projects/#{hook.project_id}/hooks", to_clean_json(hook)
  handle_request_error(1, 'GitLab', response.status, { action: 'Create webhook', id: hook.project_id }) unless response.status == 200
  ProjectWebhooks.new(Oj.load(response.body))
end

.delete!(client, hook) ⇒ Boolean

Deletes a project webhook within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
hook = Readiness::GitLab::ProjectWebhooks.find(client, project, 1)
delete = Readiness::GitLab::ProjectWebhooks.delete!(client, hook)
pp delete
# => true

Parameters:

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.124



268
269
270
271
272
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 268

def self.delete!(client, hook)
  response = client.connection.delete "projects/#{hook.project_id}/hooks/#{hook.id}"
  handle_request_error(1, 'GitLab', response.status, { action: 'Delete webhook', id: "#{hook.project_id}##{hook.id}" }) unless response.status == 2204
  true
end

.events(client, hook, status = false) ⇒ Array

Lists project webhook events. Does not stop until it ends or the page limit is hit. This method can take a long time to run depending on the parameters used.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
hooks = Readiness::GitLab::ProjectWebhooks.find!(client, project, 1)
events = Readiness::GitLab::ProjectWebhooks.events(client, hook)
pp events.first['trigger']
# => "push_hooks"
require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
hooks = Readiness::GitLab::ProjectWebhooks.find!(client, project, 1)
events = Readiness::GitLab::ProjectWebhooks.events(client, hook, 200)
pp events.first['trigger']
# => "push_hooks"

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)
  • status (Various) (defaults to: false)

    Response status code of the events (see docs for more info). Omit to get all events

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.124



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 169

def self.events(client, hook, status = false)
  root_url = if status
               "projects/#{hook.project_id}/hooks/#{hood.id}/events?status=#{status}"
             else
               "projects/#{hook.project_id}/hooks/#{hood.id}/events?"
             end
  array = []
  page = 1
  loop do
    response = client.connection.get "#{root_url}&per_page=100&page=#{page}"
    handle_request_error(0, 'GitLab', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body
    break if body.count < 100

    page += 1
  end
  array
end

.find(client, project, hook_id) ⇒ Hash

Locates a project webhook within GitLab. This will not exit on error (except Authentication errors)

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
hook = Readiness::GitLab::Issues.find(client, project, 1)
pp hook.name
# => "Hook name"

Parameters:

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.124



107
108
109
110
111
112
113
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 107

def self.find(client, project, hook_id)
  response = client.connection.get ""
  handle_request_error(0, 'GitLab', response.status,  { action: 'get', id: hook_id }) unless response.status == 200
  return ProjectWebhooks.new(Oj.load(response.body)) if response.status == 200

  Oj.load(response.body)
end

.find!(client, project, hook_id) ⇒ Hash

Locates a project webhook within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
hook = Readiness::GitLab::Issues.find!(client, project, 1)
pp hook.name
# => "Hook name"

Parameters:

Returns:

  • (Hash)

See Also:

Since:

  • 1.0.124



132
133
134
135
136
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 132

def self.find!(client, project, hook_id)
  response = client.connection.get ""
  handle_request_error(1, 'GitLab', response.status, { action: 'Find webhook', id: "#{project.id}##{hook_id}" }) unless response.status == 200
  ProjectWebhooks.new(Oj.load(response.body))
end

.list(client, project) ⇒ Array

Lists webhooks for a project.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
hooks = Readiness::GitLab::ProjectWebhooks.list(client, project)
pp hooks.first.url
# => "Hook name"

Parameters:

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.124



81
82
83
84
85
86
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 81

def self.list(client, project)
  response = client.connection.get "projects/#{project.id}/hooks"
  handle_request_error(0, 'GitLab', response.status) unless response.status == 200
  body = Oj.load(response.body)
  body.map { |p| ProjectWebhooks.new(p) }
end

.update!(client, hook) ⇒ Object

Updates a project webhook within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
hook = Readiness::GitLab::ProjectWebhooks.find(client, project, 1)
hook.url = 'http://example.com/hook2'
hook.name = 'Hook name v2'
update = Readiness::GitLab::ProjectWebhooks.update!(client, hook)
pp update.name
# => "Hook name v2"

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.124



243
244
245
246
247
# File 'lib/support_readiness/gitlab/project_webhooks.rb', line 243

def self.update!(client, hook)
  response = client.connection.put "project/#{hook.project_id}/hooks/#{hook.id}", to_clean_json(hook)
  handle_request_error(1, 'GitLab', response.status, { action: 'Update webhook', id: "#{hook.project_id}##{hook.id}" }) unless response.status == 200
  ProjectWebhooks.new(Oj.load(response.body))
end