Commit e7382de1 authored by Binsztock Rémy's avatar Binsztock Rémy Committed by Olivier Gonzalez

Add Gemnasium Service for Gitlab

Conflicts:

	db/schema.rb
parent 490f99d4
v 6.7.0
- Add support for Gemnasium as a Project Service
v 6.6.0
- Retrieving user ssh keys publically(github style): http://__HOST__/__USERNAME__.keys
- Permissions: Developer now can manage issue tracker (modify any issue)
......
......@@ -124,6 +124,9 @@ gem "hipchat", "~> 0.14.0"
# Flowdock integration
gem "gitlab-flowdock-git-hook", "~> 0.4.2"
# Gemnasium integration
gem "gemnasium-gitlab-service", "~> 0.2"
# d3
gem "d3_rails", "~> 3.1.4"
......
......@@ -152,6 +152,8 @@ GEM
dotenv (>= 0.7)
thor (>= 0.13.6)
formatador (0.2.4)
gemnasium-gitlab-service (0.2.1)
rugged (~> 0.19)
gemoji (1.3.1)
gherkin-ruby (0.3.1)
racc
......@@ -578,6 +580,7 @@ DEPENDENCIES
fog (~> 1.3.1)
font-awesome-rails (~> 3.2)
foreman
gemnasium-gitlab-service (~> 0.2)
gemoji (~> 1.3.0)
github-markup (~> 0.7.4)!
gitlab-flowdock-git-hook (~> 0.4.2)
......
......@@ -53,6 +53,7 @@ class Project < ActiveRecord::Base
has_one :hipchat_service, dependent: :destroy
has_one :flowdock_service, dependent: :destroy
has_one :assembla_service, dependent: :destroy
has_one :gemnasium_service, dependent: :destroy
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
has_one :forked_from_project, through: :forked_project_link
......@@ -256,7 +257,7 @@ class Project < ActiveRecord::Base
end
def available_services_names
%w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push)
%w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium)
end
def gitlab_ci?
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
class AssemblaService < Service
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
class CampfireService < Service
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
class EmailsOnPushService < Service
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
require "flowdock-git-hook"
......
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# token :string(255)
# project_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# active :boolean default(FALSE), not null
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
require "gemnasium/gitlab_service"
class GemnasiumService < Service
validates :token, :api_key, presence: true, if: :activated?
def title
'Gemnasium'
end
def description
'Gemnasium monitors your project dependencies and alerts you about updates and security vulnerabilities.'
end
def to_param
'gemnasium'
end
def fields
[
{ type: 'text', name: 'api_key', placeholder: 'Your personal API KEY on gemnasium.com ' },
{ type: 'text', name: 'token', placeholder: 'The project\'s slug on gemnasium.com' }
]
end
def execute(push_data)
repo_path = File.join(Gitlab.config.gitlab_shell.repos_path, "#{project.path_with_namespace}.git")
Gemnasium::GitlabService.execute(
ref: push_data[:ref],
before: push_data[:before],
after: push_data[:after],
token: token,
api_key: api_key,
repo: repo_path
)
end
end
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
class GitlabCiService < Service
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
class HipchatService < Service
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
class PivotaltrackerService < Service
......
......@@ -13,12 +13,13 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
# To add new service you should build a class inherited from Service
# and implement a set of methods
class Service < ActiveRecord::Base
attr_accessible :title, :token, :type, :active
attr_accessible :title, :token, :type, :active, :api_key
belongs_to :project
has_one :service_hook
......
class AddApiKeyToServices < ActiveRecord::Migration
def change
add_column :services, :api_key, :string
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140209025651) do
ActiveRecord::Schema.define(version: 20140214102325) do
create_table "broadcast_messages", force: true do |t|
t.text "message", null: false
......@@ -240,6 +240,7 @@ ActiveRecord::Schema.define(version: 20140209025651) do
t.string "subdomain"
t.string "room"
t.text "recipients"
t.string "api_key"
end
add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
require 'spec_helper'
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
require 'spec_helper'
......
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# token :string(255)
# project_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# active :boolean default(FALSE), not null
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
require 'spec_helper'
describe GemnasiumService do
describe "Associations" do
it { should belong_to :project }
it { should have_one :service_hook }
end
describe "Execute" do
let(:user) { create(:user) }
let(:project) { create(:project) }
before do
@gemnasium_service = GemnasiumService.new
@gemnasium_service.stub(
project_id: project.id,
project: project,
service_hook: true,
token: 'verySecret',
api_key: 'GemnasiumUserApiKey'
)
@sample_data = GitPushService.new.sample_data(project, user)
end
it "should call Gemnasium service" do
Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once
@gemnasium_service.execute(@sample_data)
end
end
end
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
require 'spec_helper'
......
......@@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#
require 'spec_helper'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment