Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ gem "seed-fu"

# Markdown to HTML
gem "redcarpet", "~> 2.2.2"
gem "github-markup", "~> 0.7.4", require: 'github/markup', git: 'https://github.com/gitlabhq/markup.git', ref: '61ade389c1e1c159359338f570d18464a44ddbc4'
gem "github-markup", "~> 0.7.4", require: 'github/markup', git: 'https://github.com/gitlabhq/markup.git', ref: '61ade389c1e1c159359338f570d18464a44ddbc4'

# Asciidoc to HTML
gem "asciidoctor"
Expand Down Expand Up @@ -128,6 +128,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"

Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,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
Expand Down Expand Up @@ -423,6 +425,7 @@ GEM
ruby-hmac (0.4.0)
ruby-progressbar (1.2.0)
rubyntlm (0.1.1)
rugged (0.19.0)
safe_yaml (0.9.7)
sanitize (2.0.6)
nokogiri (>= 1.4.4)
Expand Down Expand Up @@ -576,6 +579,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)
Expand Down
3 changes: 2 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -256,7 +257,7 @@ def build_missing_services
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?
Expand Down
1 change: 1 addition & 0 deletions app/models/project_services/assembla_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

class AssemblaService < Service
Expand Down
1 change: 1 addition & 0 deletions app/models/project_services/campfire_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

class CampfireService < Service
Expand Down
1 change: 1 addition & 0 deletions app/models/project_services/emails_on_push_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

class EmailsOnPushService < Service
Expand Down
1 change: 1 addition & 0 deletions app/models/project_services/flowdock_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

require "flowdock-git-hook"
Expand Down
54 changes: 54 additions & 0 deletions app/models/project_services/gemnasium_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# == 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
1 change: 1 addition & 0 deletions app/models/project_services/gitlab_ci_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

class GitlabCiService < Service
Expand Down
1 change: 1 addition & 0 deletions app/models/project_services/hipchat_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

class HipchatService < Service
Expand Down
1 change: 1 addition & 0 deletions app/models/project_services/pivotaltracker_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

class PivotaltrackerService < Service
Expand Down
12 changes: 11 additions & 1 deletion app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,4 +54,13 @@ def execute
def can_test?
!project.empty_repo?
end

def doc
begin
Gitlab::ServiceDoc.get(to_param)
rescue
Rails.logger.error "Unable to get Service documentation"
nil
end
end
end
8 changes: 8 additions & 0 deletions app/views/projects/services/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@
&nbsp;
- if @service.valid? && @service.activated? && @service.can_test?
= link_to 'Test settings', test_project_service_path(@project, @service.to_param), class: 'btn btn-small'


- unless @service.doc.nil?
%h4
Help
%i.icon-question.clgray

%p= markdown(@service.doc)
1 change: 1 addition & 0 deletions config/initializers/load_services_doc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gitlab::ServiceDoc.load
5 changes: 5 additions & 0 deletions db/migrate/20140214102325_add_api_key_to_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddApiKeyToServices < ActiveRecord::Migration
def change
add_column :services, :api_key, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140116231608) do
ActiveRecord::Schema.define(version: 20140214102325) do

create_table "broadcast_messages", force: true do |t|
t.text "message", null: false
Expand Down Expand Up @@ -222,6 +222,7 @@
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
Expand Down
13 changes: 13 additions & 0 deletions doc/services/gemnasium
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
To setup the service you'll need to register an account on [gemnasium.com](https://gemnasium.com/) and add your project.
Then proceed with the following steps:

----

1. Grab your personnal API key from your [account's settings page](https://gemnasium.com/settings)
2. Grab the project's slug from the project's settings page and paste it in **token** field
3. Check "Active"
4. Click "Save"
5. Click "Update Settings" to manually trigger the first sync

Now you can check your project's status on [gemnasium.com](https://gemnasium.com/).
It will be updated automatically each time you push commits on this repository.
7 changes: 7 additions & 0 deletions features/project/service.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ Feature: Project Services
And I click email on push service link
And I fill email on push settings
Then I should see email on push service settings saved

Scenario: Activate Gemnasium service
When I visit project "Shop" services page
And I click Gemnasium service link
Then I should see Gemnasium service help text
And I fill Gemnasium settings
Then I should see Gemnasium service settings saved
22 changes: 22 additions & 0 deletions features/steps/project/project_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ProjectServices < Spinach::FeatureSteps
page.should have_content 'Hipchat'
page.should have_content 'GitLab CI'
page.should have_content 'Assembla'
page.should have_content 'Gemnasium'
end

step 'I click gitlab-ci service link' do
Expand Down Expand Up @@ -100,4 +101,25 @@ class ProjectServices < Spinach::FeatureSteps
step 'I should see email on push service settings saved' do
find_field('Recipients').value.should == 'qa@company.name'
end

step 'I click Gemnasium service link' do
click_link 'Gemnasium'
end

step 'I fill Gemnasium settings' do
check 'Active'
fill_in 'Api key', with: 'verySecretApiKey'
fill_in 'Token', with: 'verySecret'
click_button 'Save'
end

step 'I should see Gemnasium service settings saved' do
find_field('Api key').value.should == 'verySecretApiKey'
find_field('Token').value.should == 'verySecret'
end

step 'I should see Gemnasium service help text' do
page.should have_content "To setup the service you'll need to register an account on gemnasium.com and add your project."
end

end
20 changes: 20 additions & 0 deletions lib/gitlab/service_doc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Gitlab
class ServiceDoc
DOC_DIR = Rails.root.join("doc","services").freeze
class << self
def load
@docs = {}
if File.exists? DOC_DIR
Dir.foreach(DOC_DIR) do |name|
next if name == '.' or name == '..'
@docs[name] = File.read(File.join(DOC_DIR, name))
end
end
end

def get(name)
@docs[name]
end
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/doc/services/example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a sample documentation file
34 changes: 34 additions & 0 deletions spec/lib/gitlab/service_doc_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'

describe Gitlab::ServiceDoc do

describe 'load' do
context "without doc folder" do
before do
Gitlab::ServiceDoc.send(:remove_const, 'DOC_DIR')
Gitlab::ServiceDoc::DOC_DIR = "imaginary_dir"
end
it { expect{ Gitlab::ServiceDoc.load }.to_not raise_error }
it { Gitlab::ServiceDoc.instance_variable_get(:@docs).should be_empty }
end

context "without doc files" do
before do
Dir.stub(:foreach).and_return([])
end
it { expect{ Gitlab::ServiceDoc.load }.to_not raise_error }
it { Gitlab::ServiceDoc.instance_variable_get(:@docs).should be_empty }
end

context "with doc files" do
before do
Gitlab::ServiceDoc.send(:remove_const, 'DOC_DIR')
Gitlab::ServiceDoc::DOC_DIR = Rails.root.join("spec","fixtures","doc","services")
Gitlab::ServiceDoc.load
end
it { Gitlab::ServiceDoc.instance_variable_get(:@docs).should_not be_empty }
it { Gitlab::ServiceDoc.get("example").should == "This is a sample documentation file" }
end
end

end
1 change: 1 addition & 0 deletions spec/models/assembla_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

require 'spec_helper'
Expand Down
1 change: 1 addition & 0 deletions spec/models/flowdock_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# api_key :string(255)
#

require 'spec_helper'
Expand Down
Loading