Commit e7382de1084f75bc8cfb2a5135412fdbd81f3b25

Authored by Binsztock Rémy
Committed by Olivier Gonzalez
1 parent 490f99d4

Add Gemnasium Service for Gitlab

Conflicts:

	db/schema.rb
CHANGELOG
  1 +v 6.7.0
  2 + - Add support for Gemnasium as a Project Service
  3 +
1 4 v 6.6.0
2 5 - Retrieving user ssh keys publically(github style): http://__HOST__/__USERNAME__.keys
3 6 - Permissions: Developer now can manage issue tracker (modify any issue)
... ...
Gemfile
... ... @@ -124,6 +124,9 @@ gem "hipchat", "~> 0.14.0"
124 124 # Flowdock integration
125 125 gem "gitlab-flowdock-git-hook", "~> 0.4.2"
126 126  
  127 +# Gemnasium integration
  128 +gem "gemnasium-gitlab-service", "~> 0.2"
  129 +
127 130 # d3
128 131 gem "d3_rails", "~> 3.1.4"
129 132  
... ...
Gemfile.lock
... ... @@ -152,6 +152,8 @@ GEM
152 152 dotenv (>= 0.7)
153 153 thor (>= 0.13.6)
154 154 formatador (0.2.4)
  155 + gemnasium-gitlab-service (0.2.1)
  156 + rugged (~> 0.19)
155 157 gemoji (1.3.1)
156 158 gherkin-ruby (0.3.1)
157 159 racc
... ... @@ -578,6 +580,7 @@ DEPENDENCIES
578 580 fog (~> 1.3.1)
579 581 font-awesome-rails (~> 3.2)
580 582 foreman
  583 + gemnasium-gitlab-service (~> 0.2)
581 584 gemoji (~> 1.3.0)
582 585 github-markup (~> 0.7.4)!
583 586 gitlab-flowdock-git-hook (~> 0.4.2)
... ...
app/models/project.rb
... ... @@ -53,6 +53,7 @@ class Project < ActiveRecord::Base
53 53 has_one :hipchat_service, dependent: :destroy
54 54 has_one :flowdock_service, dependent: :destroy
55 55 has_one :assembla_service, dependent: :destroy
  56 + has_one :gemnasium_service, dependent: :destroy
56 57 has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
57 58 has_one :forked_from_project, through: :forked_project_link
58 59  
... ... @@ -256,7 +257,7 @@ class Project < ActiveRecord::Base
256 257 end
257 258  
258 259 def available_services_names
259   - %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push)
  260 + %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium)
260 261 end
261 262  
262 263 def gitlab_ci?
... ...
app/models/project_services/assembla_service.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 class AssemblaService < Service
... ...
app/models/project_services/campfire_service.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 class CampfireService < Service
... ...
app/models/project_services/emails_on_push_service.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 class EmailsOnPushService < Service
... ...
app/models/project_services/flowdock_service.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 require "flowdock-git-hook"
... ...
app/models/project_services/gemnasium_service.rb 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: services
  4 +#
  5 +# id :integer not null, primary key
  6 +# type :string(255)
  7 +# title :string(255)
  8 +# token :string(255)
  9 +# project_id :integer not null
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +# active :boolean default(FALSE), not null
  13 +# project_url :string(255)
  14 +# subdomain :string(255)
  15 +# room :string(255)
  16 +# api_key :string(255)
  17 +#
  18 +
  19 +require "gemnasium/gitlab_service"
  20 +
  21 +class GemnasiumService < Service
  22 + validates :token, :api_key, presence: true, if: :activated?
  23 +
  24 + def title
  25 + 'Gemnasium'
  26 + end
  27 +
  28 + def description
  29 + 'Gemnasium monitors your project dependencies and alerts you about updates and security vulnerabilities.'
  30 + end
  31 +
  32 + def to_param
  33 + 'gemnasium'
  34 + end
  35 +
  36 + def fields
  37 + [
  38 + { type: 'text', name: 'api_key', placeholder: 'Your personal API KEY on gemnasium.com ' },
  39 + { type: 'text', name: 'token', placeholder: 'The project\'s slug on gemnasium.com' }
  40 + ]
  41 + end
  42 +
  43 + def execute(push_data)
  44 + repo_path = File.join(Gitlab.config.gitlab_shell.repos_path, "#{project.path_with_namespace}.git")
  45 + Gemnasium::GitlabService.execute(
  46 + ref: push_data[:ref],
  47 + before: push_data[:before],
  48 + after: push_data[:after],
  49 + token: token,
  50 + api_key: api_key,
  51 + repo: repo_path
  52 + )
  53 + end
  54 +end
... ...
app/models/project_services/gitlab_ci_service.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 class GitlabCiService < Service
... ...
app/models/project_services/hipchat_service.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 class HipchatService < Service
... ...
app/models/project_services/pivotaltracker_service.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 class PivotaltrackerService < Service
... ...
app/models/service.rb
... ... @@ -13,12 +13,13 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 # To add new service you should build a class inherited from Service
19 20 # and implement a set of methods
20 21 class Service < ActiveRecord::Base
21   - attr_accessible :title, :token, :type, :active
  22 + attr_accessible :title, :token, :type, :active, :api_key
22 23  
23 24 belongs_to :project
24 25 has_one :service_hook
... ...
db/migrate/20140214102325_add_api_key_to_services.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class AddApiKeyToServices < ActiveRecord::Migration
  2 + def change
  3 + add_column :services, :api_key, :string
  4 + end
  5 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(version: 20140209025651) do
  14 +ActiveRecord::Schema.define(version: 20140214102325) do
15 15  
16 16 create_table "broadcast_messages", force: true do |t|
17 17 t.text "message", null: false
... ... @@ -240,6 +240,7 @@ ActiveRecord::Schema.define(version: 20140209025651) do
240 240 t.string "subdomain"
241 241 t.string "room"
242 242 t.text "recipients"
  243 + t.string "api_key"
243 244 end
244 245  
245 246 add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree
... ...
spec/models/assembla_service_spec.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 require 'spec_helper'
... ...
spec/models/flowdock_service_spec.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 require 'spec_helper'
... ...
spec/models/gemnasium_service_spec.rb 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: services
  4 +#
  5 +# id :integer not null, primary key
  6 +# type :string(255)
  7 +# title :string(255)
  8 +# token :string(255)
  9 +# project_id :integer not null
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +# active :boolean default(FALSE), not null
  13 +# project_url :string(255)
  14 +# subdomain :string(255)
  15 +# room :string(255)
  16 +# api_key :string(255)
  17 +#
  18 +
  19 +require 'spec_helper'
  20 +
  21 +describe GemnasiumService do
  22 + describe "Associations" do
  23 + it { should belong_to :project }
  24 + it { should have_one :service_hook }
  25 + end
  26 +
  27 + describe "Execute" do
  28 + let(:user) { create(:user) }
  29 + let(:project) { create(:project) }
  30 +
  31 + before do
  32 + @gemnasium_service = GemnasiumService.new
  33 + @gemnasium_service.stub(
  34 + project_id: project.id,
  35 + project: project,
  36 + service_hook: true,
  37 + token: 'verySecret',
  38 + api_key: 'GemnasiumUserApiKey'
  39 + )
  40 + @sample_data = GitPushService.new.sample_data(project, user)
  41 + end
  42 + it "should call Gemnasium service" do
  43 + Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once
  44 + @gemnasium_service.execute(@sample_data)
  45 + end
  46 + end
  47 +end
... ...
spec/models/gitlab_ci_service_spec.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 require 'spec_helper'
... ...
spec/models/service_spec.rb
... ... @@ -13,6 +13,7 @@
13 13 # project_url :string(255)
14 14 # subdomain :string(255)
15 15 # room :string(255)
  16 +# api_key :string(255)
16 17 #
17 18  
18 19 require 'spec_helper'
... ...