class GitLabSystemHooksReceiver::App

Private Instance Methods

add_project_hook(project_id, hook_uri) click to toggle source

POST #{GitLabURI}/projects/:id/hooks

# File lib/gitlab-system-hooks-receiver/app.rb, line 54
def add_project_hook(project_id, hook_uri)
  api_end_point_uri = URI.parse(@options[:api_end_point])
  path = File.join(api_end_point_uri.path, "projects", project_id.to_s, "hooks")
  post_request = Net::HTTP::Post.new(path)
  # push_events is enabled by default
  post_request.set_form_data("url" => hook_uri,
                             "private_token" => @options[:private_token])
  http = Net::HTTP.new(api_end_point_uri.host, api_end_point_uri.port)
  if api_end_point_uri.scheme == "https"
    http.use_ssl = true
    http.ca_path = "/etc/ssl/certs"
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    http.verify_depth = 5
  end
  response = nil
  http.start do
    response = http.request(post_request)
  end

  response
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/gitlab-system-hooks-receiver/app.rb, line 43
def method_missing(name, *args)
  if name =~ /\Aprocess_.*_event\z/
    puts name
  else
    super
  end
end
process_payload(request, response, payload) click to toggle source
# File lib/gitlab-system-hooks-receiver/app.rb, line 29
def process_payload(request, response, payload)
  event_name = payload["event_name"]
  __send__("process_#{event_name}_event", request, response, payload)
end
process_project_create_event(request, response, payload) click to toggle source
# File lib/gitlab-system-hooks-receiver/app.rb, line 34
def process_project_create_event(request, response, payload)
  # TODO notify to owner
  owner_email = payload["owner_email"]
  project_id = payload["project_id"]
  @options[:web_hooks].each do |web_hook|
    add_project_hook(project_id, web_hook)
  end
end