Commit e7382de1084f75bc8cfb2a5135412fdbd81f3b25
Committed by
Olivier Gonzalez
1 parent
490f99d4
Exists in
spb-stable
and in
3 other branches
Add Gemnasium Service for Gitlab
Conflicts: db/schema.rb
Showing
20 changed files
with
132 additions
and
3 deletions
Show diff stats
CHANGELOG
1 | +v 6.7.0 | ||
2 | + - Add support for Gemnasium as a Project Service | ||
3 | + | ||
1 | v 6.6.0 | 4 | v 6.6.0 |
2 | - Retrieving user ssh keys publically(github style): http://__HOST__/__USERNAME__.keys | 5 | - Retrieving user ssh keys publically(github style): http://__HOST__/__USERNAME__.keys |
3 | - Permissions: Developer now can manage issue tracker (modify any issue) | 6 | - Permissions: Developer now can manage issue tracker (modify any issue) |
Gemfile
@@ -124,6 +124,9 @@ gem "hipchat", "~> 0.14.0" | @@ -124,6 +124,9 @@ gem "hipchat", "~> 0.14.0" | ||
124 | # Flowdock integration | 124 | # Flowdock integration |
125 | gem "gitlab-flowdock-git-hook", "~> 0.4.2" | 125 | gem "gitlab-flowdock-git-hook", "~> 0.4.2" |
126 | 126 | ||
127 | +# Gemnasium integration | ||
128 | +gem "gemnasium-gitlab-service", "~> 0.2" | ||
129 | + | ||
127 | # d3 | 130 | # d3 |
128 | gem "d3_rails", "~> 3.1.4" | 131 | gem "d3_rails", "~> 3.1.4" |
129 | 132 |
Gemfile.lock
@@ -152,6 +152,8 @@ GEM | @@ -152,6 +152,8 @@ GEM | ||
152 | dotenv (>= 0.7) | 152 | dotenv (>= 0.7) |
153 | thor (>= 0.13.6) | 153 | thor (>= 0.13.6) |
154 | formatador (0.2.4) | 154 | formatador (0.2.4) |
155 | + gemnasium-gitlab-service (0.2.1) | ||
156 | + rugged (~> 0.19) | ||
155 | gemoji (1.3.1) | 157 | gemoji (1.3.1) |
156 | gherkin-ruby (0.3.1) | 158 | gherkin-ruby (0.3.1) |
157 | racc | 159 | racc |
@@ -578,6 +580,7 @@ DEPENDENCIES | @@ -578,6 +580,7 @@ DEPENDENCIES | ||
578 | fog (~> 1.3.1) | 580 | fog (~> 1.3.1) |
579 | font-awesome-rails (~> 3.2) | 581 | font-awesome-rails (~> 3.2) |
580 | foreman | 582 | foreman |
583 | + gemnasium-gitlab-service (~> 0.2) | ||
581 | gemoji (~> 1.3.0) | 584 | gemoji (~> 1.3.0) |
582 | github-markup (~> 0.7.4)! | 585 | github-markup (~> 0.7.4)! |
583 | gitlab-flowdock-git-hook (~> 0.4.2) | 586 | gitlab-flowdock-git-hook (~> 0.4.2) |
app/models/project.rb
@@ -53,6 +53,7 @@ class Project < ActiveRecord::Base | @@ -53,6 +53,7 @@ class Project < ActiveRecord::Base | ||
53 | has_one :hipchat_service, dependent: :destroy | 53 | has_one :hipchat_service, dependent: :destroy |
54 | has_one :flowdock_service, dependent: :destroy | 54 | has_one :flowdock_service, dependent: :destroy |
55 | has_one :assembla_service, dependent: :destroy | 55 | has_one :assembla_service, dependent: :destroy |
56 | + has_one :gemnasium_service, dependent: :destroy | ||
56 | has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" | 57 | has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" |
57 | has_one :forked_from_project, through: :forked_project_link | 58 | has_one :forked_from_project, through: :forked_project_link |
58 | 59 | ||
@@ -256,7 +257,7 @@ class Project < ActiveRecord::Base | @@ -256,7 +257,7 @@ class Project < ActiveRecord::Base | ||
256 | end | 257 | end |
257 | 258 | ||
258 | def available_services_names | 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 | end | 261 | end |
261 | 262 | ||
262 | def gitlab_ci? | 263 | def gitlab_ci? |
app/models/project_services/assembla_service.rb
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | class AssemblaService < Service | 19 | class AssemblaService < Service |
app/models/project_services/campfire_service.rb
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | class CampfireService < Service | 19 | class CampfireService < Service |
app/models/project_services/emails_on_push_service.rb
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | class EmailsOnPushService < Service | 19 | class EmailsOnPushService < Service |
app/models/project_services/flowdock_service.rb
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | require "flowdock-git-hook" | 19 | require "flowdock-git-hook" |
@@ -0,0 +1,54 @@ | @@ -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,6 +13,7 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | class GitlabCiService < Service | 19 | class GitlabCiService < Service |
app/models/project_services/hipchat_service.rb
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | class HipchatService < Service | 19 | class HipchatService < Service |
app/models/project_services/pivotaltracker_service.rb
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | class PivotaltrackerService < Service | 19 | class PivotaltrackerService < Service |
app/models/service.rb
@@ -13,12 +13,13 @@ | @@ -13,12 +13,13 @@ | ||
13 | # project_url :string(255) | 13 | # project_url :string(255) |
14 | # subdomain :string(255) | 14 | # subdomain :string(255) |
15 | # room :string(255) | 15 | # room :string(255) |
16 | +# api_key :string(255) | ||
16 | # | 17 | # |
17 | 18 | ||
18 | # To add new service you should build a class inherited from Service | 19 | # To add new service you should build a class inherited from Service |
19 | # and implement a set of methods | 20 | # and implement a set of methods |
20 | class Service < ActiveRecord::Base | 21 | class Service < ActiveRecord::Base |
21 | - attr_accessible :title, :token, :type, :active | 22 | + attr_accessible :title, :token, :type, :active, :api_key |
22 | 23 | ||
23 | belongs_to :project | 24 | belongs_to :project |
24 | has_one :service_hook | 25 | has_one :service_hook |
db/schema.rb
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | # | 11 | # |
12 | # It's strongly recommended that you check this file into your version control system. | 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 | create_table "broadcast_messages", force: true do |t| | 16 | create_table "broadcast_messages", force: true do |t| |
17 | t.text "message", null: false | 17 | t.text "message", null: false |
@@ -240,6 +240,7 @@ ActiveRecord::Schema.define(version: 20140209025651) do | @@ -240,6 +240,7 @@ ActiveRecord::Schema.define(version: 20140209025651) do | ||
240 | t.string "subdomain" | 240 | t.string "subdomain" |
241 | t.string "room" | 241 | t.string "room" |
242 | t.text "recipients" | 242 | t.text "recipients" |
243 | + t.string "api_key" | ||
243 | end | 244 | end |
244 | 245 | ||
245 | add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree | 246 | add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree |
spec/models/assembla_service_spec.rb
spec/models/flowdock_service_spec.rb
@@ -0,0 +1,47 @@ | @@ -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
spec/models/service_spec.rb