gemnasium-gitlab-service-0.2.6/0000755000175600017570000000000012627536641015457 5ustar pravipravigemnasium-gitlab-service-0.2.6/spec/0000755000175600017570000000000012627536641016411 5ustar pravipravigemnasium-gitlab-service-0.2.6/spec/gemnasium/0000755000175600017570000000000012627536641020376 5ustar pravipravigemnasium-gitlab-service-0.2.6/spec/gemnasium/gitlab_service/0000755000175600017570000000000012627536641023360 5ustar pravipravigemnasium-gitlab-service-0.2.6/spec/gemnasium/gitlab_service/pusher_spec.rb0000644000175600017570000000561112627536641026230 0ustar pravipravirequire 'spec_helper' require 'tmpdir' # Pusher integration test: it relies on Rugged and loads an existing git repo. # The client is stubbed (or mocked) and there's no network connection. # describe Gemnasium::GitlabService::Pusher do let(:client) { double('client').stub(:upload_files) } let(:options) do { repo: repo_path, after: commit_sha, ref: 'refs/heads/dev', token: 'gemnasium-user/the-project', client: client } end let(:pusher) { described_class.new(options) } let(:gemfile_content) do <<-EOS source 'https://rubygems.org' gem 'jasmine' gem 'juicer' gem 'json' EOS end let(:lockfile_content) do <<-EOS GEM remote: https://rubygems.org/ specs: addressable (2.3.2) childprocess (0.3.5) ffi (~> 1.0, >= 1.0.6) diff-lcs (1.1.3) ffi (1.1.5) jasmine (1.2.1) jasmine-core (>= 1.2.0) rack (~> 1.0) rspec (>= 1.3.1) selenium-webdriver (>= 0.1.3) jasmine-core (1.2.0) json (1.7.5) libwebsocket (0.1.5) addressable multi_json (1.3.6) rack (1.4.1) rspec (2.11.0) rspec-core (~> 2.11.0) rspec-expectations (~> 2.11.0) rspec-mocks (~> 2.11.0) rspec-core (2.11.1) rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.2) rubyzip (0.9.9) selenium-webdriver (2.25.0) childprocess (>= 0.2.5) libwebsocket (~> 0.1.3) multi_json (~> 1.0) rubyzip PLATFORMS ruby DEPENDENCIES jasmine json EOS end let(:repo_path) { Dir.mktmpdir } let(:commit_sha) do repo = Rugged::Repository.init_at(repo_path) index = repo.index repo.write(gemfile_content, :blob).tap do |oid| index.add(path: "depfiles/Gemfile", :oid => oid, :mode => 0100644) end repo.write(lockfile_content, :blob).tap do |oid| index.add(path: "depfiles/Gemfile.lock", :oid => oid, :mode => 0100644) end options = {} options[:tree] = index.write_tree(repo) options[:author] = { :email => "fcat@github.com", :name => 'Fabien Catteau', :time => Time.now } options[:committer] = { :email => "fcat@github.com", :name => 'Fabien Catteau', :time => Time.now } options[:message] ||= "Add some Ruby dependency files" options[:parents] = [] options[:update_ref] = 'HEAD' Rugged::Commit.create(repo, options).to_s end after do FileUtils.rm_rf repo_path end describe "#call" do it "pushes the dependency files" do file_class = described_class::DependencyFile expect(client).to receive(:upload_files).with( [ file_class.new('depfiles/Gemfile', "68609d16b77711fd079668539a07a648fe837c84", gemfile_content), file_class.new('depfiles/Gemfile.lock', "c6d0eedc76b94d6412a9ab9741a10782116c1c47", lockfile_content), ], 'gemnasium-user/the-project', 'dev', commit_sha, ) pusher.call end end end gemnasium-gitlab-service-0.2.6/spec/gemnasium/gitlab_service/connection_spec.rb0000644000175600017570000000216712627536641027064 0ustar pravipravirequire 'spec_helper' describe Gemnasium::GitlabService::Connection do before do stub_requests end let(:connection) { Gemnasium::GitlabService::Connection.new({api_key: "secret_api_key"}) } describe 'initialize' do it 'initializes a Net::HTTP object' do connection.instance_variable_get('@connection').should be_kind_of(Net::HTTP) end end describe 'get' do before { connection.get('test_path') } it 'issues a GET request' do expect(WebMock).to have_requested(:get, api_url('test_path')) .with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent' => "Gemnasium Gitlab Service - v#{Gemnasium::GitlabService::VERSION}"}) end end describe 'post' do before { connection.post('test_path', { foo: 'bar' }.to_json) } it 'issues a POST request' do expect(WebMock).to have_requested(:post, api_url('test_path')) .with(:body => {"foo"=>"bar"}, :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent' => "Gemnasium Gitlab Service - v#{Gemnasium::GitlabService::VERSION}"}) end end end gemnasium-gitlab-service-0.2.6/spec/gemnasium/gitlab_service/client_spec.rb0000644000175600017570000000304612627536641026200 0ustar pravipravirequire 'spec_helper' describe Gemnasium::GitlabService::Client do before do stub_requests end let(:client) { Gemnasium::GitlabService::Client.new({api_key: "secret_api_key"}) } describe 'initialize' do it 'initializes a Connection object' do client.instance_variable_get('@connection').should be_kind_of(Gemnasium::GitlabService::Connection) end end describe 'upload_files' do let(:files) do [ double('Gemfile', path: 'Gemfile', sha: 'sha of Gemfile', content: 'content of Gemfile'), double('Gemfile.lock', path: 'Gemfile.lock', sha: 'sha of Gemfile.lock', content: 'content of Gemfile.lock'), ] end before do client.upload_files( files, 'project_slug', 'branch_name', 'commit_sha' ) end it 'issues a POST request' do expected_payload = JSON.generate [ { 'path' => 'Gemfile', 'sha' => 'sha of Gemfile', 'content' => "Y29udGVudCBvZiBHZW1maWxl\n", }, { 'path' => 'Gemfile.lock', 'sha' => 'sha of Gemfile.lock', 'content' => "Y29udGVudCBvZiBHZW1maWxlLmxvY2s=\n", }, ] expect(WebMock).to have_requested(:post, api_url("projects/project_slug/dependency_files")). with( :body => expected_payload, :headers => { 'Accept'=>'application/json', 'Content-Type'=>'application/json', 'X-Gms-Branch'=> 'branch_name', 'X-Gms-Revision'=> 'commit_sha', } ) end end end gemnasium-gitlab-service-0.2.6/spec/gemnasium/gitlab_service_spec.rb0000644000175600017570000000226212627536641024721 0ustar pravipravirequire 'spec_helper' describe Gemnasium::GitlabService do describe 'execute' do let(:options) do { token: "project_token", ref: "refs/heads/master", repo: 'ignore', after: 'ignore' } end let(:client) { double(:client).as_null_object } let(:dependency_files) { [] } before do Rugged::Repository.stub :new Gemnasium::GitlabService::Client.stub(:new).and_return(client) Gemnasium::GitlabService::Pusher.any_instance.stub(:dependency_files).and_return(dependency_files) end context "when there's no dependency file" do let(:dependency_file) { [] } it 'does nothing' do expect(client).not_to receive(:upload_files) Gemnasium::GitlabService.execute options end end context "when repo has dependency files" do let(:dependency_file) do [{ "filename" => "Gemfile", "sha" => "sha1", "content" => "some content"}] end it 'send them to gemnasium.com' do expect(client).not_to receive(:upload_files). with('project_token', 'master', dependency_files) Gemnasium::GitlabService.execute options end end end end gemnasium-gitlab-service-0.2.6/spec/spec_helper.rb0000644000175600017570000000030612627536641021226 0ustar pravipravirequire 'gemnasium/gitlab_service' require 'rspec' require 'webmock/rspec' # Load support files Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } WebMock.disable_net_connect! gemnasium-gitlab-service-0.2.6/spec/support/0000755000175600017570000000000012627536641020125 5ustar pravipravigemnasium-gitlab-service-0.2.6/spec/support/gemnasium_helper.rb0000644000175600017570000000157312627536641024004 0ustar pravipravidef api_url(path) "https://X:secret_api_key@api.gemnasium.com/v1/#{path}" end def stub_requests request_headers = { 'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent' => "Gemnasium Gitlab Service - v#{Gemnasium::GitlabService::VERSION}" } response_headers = {'Content-Type'=>'application/json'} stub_request(:post, api_url("projects/project_slug/dependency_files")) .with(:headers => request_headers) .to_return(:status => 200, :body => '{ "added": ["new_gemspec.gemspec"], "updated": ["modified_lockfile.lockfile"], "unchanged": [], "unsupported": [] }', :headers => response_headers) # Connection model's test requests stub_request(:get, api_url('test_path')) .with(:headers => request_headers) stub_request(:post, api_url('test_path')) .with(:body => {"foo"=>"bar"}, :headers => request_headers) end gemnasium-gitlab-service-0.2.6/LICENSE0000644000175600017570000000206012627536641016462 0ustar pravipraviCopyright (c) 2014 Tech-Angels LLC MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gemnasium-gitlab-service-0.2.6/.travis.yml0000644000175600017570000000007212627536641017567 0ustar pravipravilanguage: ruby rvm: - 2.0 - 2.1 - 2.2 - ruby-head gemnasium-gitlab-service-0.2.6/README.md0000644000175600017570000000250712627536641016742 0ustar pravipravi# Gemnasium Gitlab Service [![Dependency Status](https://gemnasium.com/gemnasium/gemnasium-gitlab-service.png)](https://gemnasium.com/gemnasium/gemnasium-gitlab-service) [![Build Status](https://travis-ci.org/gemnasium/gemnasium-gitlab-service.png?branch=master)](https://travis-ci.org/gemnasium/gemnasium-gitlab-service) This gem integrates with Gitlab's project services to automatically push your dependency files to [Gemnasium](https://gemnasium.com/) to track your project's dependencies and get notified about updates and security advisories. Supported dependency files are: * Ruby: `Gemfile`, `Gemfile.lock` and `*.gemspec` * NPM: `package.json` and `npm-shrinkwrap.json` * Pyton: `requirements.txt`, `setup.py` and `requires.txt` * PHP Composer: `composer.json` and `composer.lock` ## Install Gitlab provides the Gemnasium service out of the box. Just go to your project settings, under the "Services" section, and enable "Gemnasium"". To set up your service, you need to grab your [Gemnasium API KEY](https://gemnasium.com/settings) and the project's token on [gemnasium.com](https://gemnasium.com) ## Troubleshooting If you encounter any issue, please contact [Gemnasium support](http://support.gemnasium.com). ## Contributing 1. Fork the project. 2. Make your feature or bug fix. 3. Test it. 4. Commit. 5. Create new pull request. gemnasium-gitlab-service-0.2.6/CHANGELOG.md0000644000175600017570000000152712627536641017275 0ustar pravipravi# 0.2.6 / 2015-03-27 * Fix compatible issue, make it compatible with Ruby 2.0 # 0.2.5 / 2015-03-04 * Push branch name to Gemnasium # 0.2.4 / 2015-02-25 * Bump vulnerable dependency rugged # 0.2.3 / 2014-12-02 * Connect to new [Gemnasium API](https://api.gemnasium.com) v1 * Push the git revision; don't push the branch name anymore * Update regexp of supported paths: add `bower.json`, `requirements*txt` and `requirements.pip` # 0.2.2 / 2014-04-28 * Fix encoding errors # 0.2.1 / 2014-02-21 * Fix require # 0.2.0 / 2014-02-21 **Yanked** * Replace gitlab_git with rugged * Do a full repo scan to match all use cases # 0.1.2 / 2014-02-19 * Increase range of compatible versions for gitlab_git dependency (again) # 0.1.1 / 2014-02-19 * Increase range of compatible versions for gitlab_git dependency # 0.1.0 / 2014-02-19 Initial release gemnasium-gitlab-service-0.2.6/Gemfile0000644000175600017570000000013612627536641016752 0ustar pravipravisource 'https://rubygems.org' # Specify your gem's dependencies in gemnasium.gemspec gemspec gemnasium-gitlab-service-0.2.6/.ruby-version0000644000175600017570000000001312627536641020116 0ustar pravipraviruby-2.1.5 gemnasium-gitlab-service-0.2.6/gemnasium-gitlab-service.gemspec0000644000175600017570000000204512627536641023710 0ustar pravipravirequire './lib/gemnasium/gitlab_service/version' Gem::Specification.new do |gem| gem.authors = ["Tech-Angels"] gem.email = ["contact@tech-angels.com"] gem.description = "Add Gemnasium support to Gitlab as a Project Service. It uploads the dependency files to https://api.gemnasium.com whenever a new commit is pushed to your repository." gem.summary = "Gemnasium service for Gitlab" gem.homepage = "https://github.com/gemnasium/gemnasium-gitlab-service" gem.license = 'MIT' gem.files = `git ls-files`.split($\) gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = "gemnasium-gitlab-service" gem.require_paths = ["lib"] gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) } gem.version = Gemnasium::GitlabService::VERSION gem.add_runtime_dependency "rugged", '~> 0.21' gem.add_development_dependency 'rake', '~> 10.0' gem.add_development_dependency 'rspec', '~> 2.14' gem.add_development_dependency 'webmock', '~> 1.17' end gemnasium-gitlab-service-0.2.6/.ruby-gemset0000644000175600017570000000003012627536641017714 0ustar pravipravigemnasium-gitlab-servicegemnasium-gitlab-service-0.2.6/metadata.yml0000644000175600017570000000656612627536641017777 0ustar pravipravi--- !ruby/object:Gem::Specification name: gemnasium-gitlab-service version: !ruby/object:Gem::Version version: 0.2.6 platform: ruby authors: - Tech-Angels autorequire: bindir: bin cert_chain: [] date: 2015-03-27 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rugged requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.21' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.21' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '2.14' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '2.14' - !ruby/object:Gem::Dependency name: webmock requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.17' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.17' description: |- Add Gemnasium support to Gitlab as a Project Service. It uploads the dependency files to https://api.gemnasium.com whenever a new commit is pushed to your repository. email: - contact@tech-angels.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".ruby-gemset" - ".ruby-version" - ".travis.yml" - CHANGELOG.md - Gemfile - LICENSE - README.md - Rakefile - gemnasium-gitlab-service.gemspec - lib/gemnasium/gitlab_service.rb - lib/gemnasium/gitlab_service/client.rb - lib/gemnasium/gitlab_service/connection.rb - lib/gemnasium/gitlab_service/errors.rb - lib/gemnasium/gitlab_service/pusher.rb - lib/gemnasium/gitlab_service/version.rb - spec/gemnasium/gitlab_service/client_spec.rb - spec/gemnasium/gitlab_service/connection_spec.rb - spec/gemnasium/gitlab_service/pusher_spec.rb - spec/gemnasium/gitlab_service_spec.rb - spec/spec_helper.rb - spec/support/gemnasium_helper.rb homepage: https://github.com/gemnasium/gemnasium-gitlab-service licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: Gemnasium service for Gitlab test_files: - spec/gemnasium/gitlab_service/client_spec.rb - spec/gemnasium/gitlab_service/connection_spec.rb - spec/gemnasium/gitlab_service/pusher_spec.rb - spec/gemnasium/gitlab_service_spec.rb - spec/spec_helper.rb - spec/support/gemnasium_helper.rb gemnasium-gitlab-service-0.2.6/lib/0000755000175600017570000000000012627536641016225 5ustar pravipravigemnasium-gitlab-service-0.2.6/lib/gemnasium/0000755000175600017570000000000012627536641020212 5ustar pravipravigemnasium-gitlab-service-0.2.6/lib/gemnasium/gitlab_service.rb0000644000175600017570000000034712627536641023525 0ustar pravipravirequire 'gemnasium/gitlab_service/errors' require 'gemnasium/gitlab_service/pusher' module Gemnasium module GitlabService class << self def execute(options) Pusher.new(options).call end end end end gemnasium-gitlab-service-0.2.6/lib/gemnasium/gitlab_service/0000755000175600017570000000000012627536641023174 5ustar pravipravigemnasium-gitlab-service-0.2.6/lib/gemnasium/gitlab_service/errors.rb0000644000175600017570000000141112627536641025032 0ustar pravipravimodule Gemnasium module GitlabService class InvalidApiKeyError < StandardError def message 'Your API key is invalid. Please double check it on https://gemnasium.com/settings/api_access' end end class DeprecatedApiVersionError < StandardError; end class MalformedRequestError < StandardError; end class MissingParamsError < StandardError; end class NonBillableUserError < StandardError; end class NoSlotsAvailableError < StandardError; end class ProjectNotFoundError < StandardError; end class ProjectNotOfflineError < StandardError; end class ProjectParamMissingError < StandardError; end class UnsupportedDependencyFilesError < StandardError; end class BranchNotFoundError < StandardError; end end end gemnasium-gitlab-service-0.2.6/lib/gemnasium/gitlab_service/connection.rb0000644000175600017570000000262412627536641025664 0ustar pravipravirequire 'gemnasium/gitlab_service/version' require 'net/https' module Gemnasium module GitlabService class Connection DEFAULT_ENDPOINT = 'api.gemnasium.com' DEFAULT_API_VERSION = 'v1' DEFAULT_SSL = true DEFAULT_AGENT = "Gemnasium Gitlab Service - v#{Gemnasium::GitlabService::VERSION}" def initialize(options = {}) use_ssl = options.fetch(:use_ssl){ DEFAULT_SSL } host = options.fetch(:host){ DEFAULT_ENDPOINT } port = options.fetch(:port){ use_ssl ? 443 : 80 } api_version = options.fetch(:api_version){ DEFAULT_API_VERSION }.to_s @connection = Net::HTTP.new(host, port) @connection.use_ssl = use_ssl @api_key = options.fetch(:api_key) @base_url = "/#{ api_version }/" end def post(path, body, headers = {}) request = Net::HTTP::Post.new(@base_url + path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => DEFAULT_AGENT)) request.basic_auth('X', @api_key) request.body = body @connection.request(request) end def get(path, headers = {}) request = Net::HTTP::Get.new(@base_url + path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => DEFAULT_AGENT)) request.basic_auth('X', @api_key) @connection.request(request) end end end end gemnasium-gitlab-service-0.2.6/lib/gemnasium/gitlab_service/version.rb0000644000175600017570000000011012627536641025176 0ustar pravipravimodule Gemnasium module GitlabService VERSION = "0.2.6" end end gemnasium-gitlab-service-0.2.6/lib/gemnasium/gitlab_service/pusher.rb0000644000175600017570000000460412627536641025033 0ustar pravipravirequire 'gemnasium/gitlab_service/client' require 'rugged' module Gemnasium module GitlabService # Push all dependency files of a git repo to Gemnasium. # class Pusher DependencyFile = Struct.new(:path, :sha, :content) attr_reader :repo_path, :commit_sha, :branch_name attr_reader :project_slug, :client def initialize(options = {}) @repo_path = options.fetch(:repo) @commit_sha = options.fetch(:after) @branch_name = options.fetch(:ref).to_s.sub(/\Arefs\/(heads|tags)\//, '') @project_slug = options.fetch(:token) @client ||= options.fetch(:client){ Gemnasium::GitlabService::Client.new(options) } end # Push all dependency files # def call if dependency_files.any? client.upload_files( dependency_files, project_slug, branch_name, commit_sha ) end end private # Return the dependency files as an array # def dependency_files @dependency_files = ( walker.inject([]) do |files, entry| files << convert_entry(entry) if is_entry_supported?(entry) files end ) end # Return a Rugged::Walker that goes through the entries of the commit # def walker repo.lookup(commit_sha).tree.walk(:postorder) end # Return a Rugged::Repository # def repo @repo ||= Rugged::Repository.new(repo_path) end # Convert a commit entry for the Gemnasium client # def convert_entry(entry) path = path_for_entry entry blob = repo.lookup entry.last[:oid] DependencyFile.new path, blob.oid, blob.text end # Tell whether or not a commit entry is a supported dependency file # def is_entry_supported?(entry) path_for_entry(entry).match supported_path_regexp end # Extract file path from a git entry # def path_for_entry(entry) entry[0..-2].join('/') + entry.last[:name] end # Return regexp that matches the path of a supported dependency file # def supported_path_regexp /(Gemfile|Gemfile\.lock|.*\.gemspec|package\.json|npm-shrinkwrap\.json|setup\.py|requires\.txt|requirements\.txt|requirements\.pip|requirements.*\.txt|composer\.json|composer\.lock|bower\.json)$/ end end end end gemnasium-gitlab-service-0.2.6/lib/gemnasium/gitlab_service/client.rb0000644000175600017570000000376212627536641025007 0ustar pravipravirequire "gemnasium/gitlab_service/connection" require 'json' module Gemnasium module GitlabService class Client def initialize(options={}) @connection = Gemnasium::GitlabService::Connection.new(options) end # Updates or creates the dependency files. # # @params project [String] Identifier of the project # files [Hash] files to upload; a file respond to :path, :sha and :content def upload_files(files, project_slug, branch_name, commit_sha) payload = files.map do |f| { "path" => f.path, "sha" => f.sha, "content" => Base64.encode64(f.content) } end extra_headers = { 'X-Gms-Branch' => branch_name, 'X-Gms-Revision' => commit_sha } request(:post, "projects/#{ project_slug }/dependency_files", payload, extra_headers) end private # Issue a HTTP request # # @params method [String] Method of the request # path [String] Path of the request # payload [Hash] payload of a POST request # extra_headers [Hash] extra HTTP headers # def request(method, path, payload = {}, extra_headers = {}) case method when :get response = @connection.get(path) when :post response = @connection.post(path, JSON.generate(payload), extra_headers) end raise Gemnasium::GitlabService::InvalidApiKeyError if response.code.to_i == 401 response_body = JSON.parse(response.body) if response.code.to_i / 100 == 2 return {} if response_body.empty? result = response_body else if error = "#{response_body['error']}_error".split('_').collect(&:capitalize).join raise Gemnasium::GitlabService.const_get(error), response_body['message'] else raise 'An unknown error has been returned by the server. Please contact Gemnasium support : http://support.gemnasium.com' end end end end end end gemnasium-gitlab-service-0.2.6/Rakefile0000644000175600017570000000016612627536641017127 0ustar pravipravirequire "bundler/gem_tasks" require 'rspec/core/rake_task' RSpec::Core::RakeTask.new('spec') task :default => :spec gemnasium-gitlab-service-0.2.6/.gitignore0000644000175600017570000000024312627536641017446 0ustar pravipravi*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp .DS_Store