Codeminer42/cm42-central

View on GitHub
lib/gitlab_api/create_hook.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module GitlabApi
  class CreateHook
    SUCCESS_RESPONSE_CODE = 201

    def initialize(api_url, private_token, project_id, params)
      @project_id = project_id
      @gitlab_api = GitlabApi::Client.new(api_url, private_token, SUCCESS_RESPONSE_CODE)
      @params = params
    end

    def perform
      @gitlab_api.post do |req|
        req.url path
        req.body = @params.to_json
      end
    end

    private

    def path
      "projects/#{@project_id}/hooks"
    end
  end
end