Skip to content

Commit

Permalink
Merge 24b570b into 9d6ec7f
Browse files Browse the repository at this point in the history
  • Loading branch information
Kutomore committed Mar 7, 2019
2 parents 9d6ec7f + 24b570b commit e464059
Show file tree
Hide file tree
Showing 43 changed files with 2,376 additions and 230 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ gem 'devise-authy', '~> 1.10.0'
gem 'devise-i18n'
gem 'differ'
gem 'dotenv-rails'
gem 'faraday'
gem 'foreman'
gem 'friendly_id', '~> 5.2.5'
gem 'grape'
Expand Down Expand Up @@ -57,6 +58,7 @@ gem 'sidekiq_mailer'
gem 'sinatra', require: nil
gem 'uglifier', '>= 2.5.3'
gem 'user_impersonate2', require: 'user_impersonate'
gem 'virtus'
gem 'webpacker', '>= 4.0.x'
gem 'pusher'

Expand Down
62 changes: 32 additions & 30 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/Codeminer42/cm42-central-support.git
revision: ec28820f522ed192d67e3b9960af18a9786e8035
revision: a0f33d2e8185be2675ad6b9119c6c98835315fa3
specs:
central-support (0.9.4)
activerecord (>= 5.1)
Expand Down Expand Up @@ -79,28 +79,28 @@ GEM
rails (>= 3.2)
authy (2.7.5)
httpclient (>= 2.5.3.3)
autoprefixer-rails (9.4.6)
autoprefixer-rails (9.4.9)
execjs
aws_cf_signer (0.1.3)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.12)
better_errors (2.5.0)
better_errors (2.5.1)
coderay (>= 1.0.0)
erubi (>= 1.0.0)
rack (>= 0.9.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.4.0)
bootstrap-sass (3.4.1)
autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
builder (3.2.3)
bullet (5.9.0)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
capybara (3.13.2)
capybara (3.14.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -154,13 +154,13 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.4)
daemons (1.2.6)
daemons (1.3.1)
dalli (2.7.9)
database_cleaner (1.7.0)
debug_inspector (0.0.3)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.5.0)
devise (4.6.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
Expand All @@ -172,17 +172,17 @@ GEM
devise-authy (1.10.0)
authy (>= 2.7.2)
devise (>= 3.0.0)
devise-i18n (1.7.1)
devise (>= 4.5)
devise-i18n (1.8.0)
devise (>= 4.6)
diff-lcs (1.3)
differ (0.1.2)
docile (1.1.5)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.6.0)
dotenv-rails (2.6.0)
dotenv (= 2.6.0)
railties (>= 3.2, < 6.0)
dotenv (2.7.1)
dotenv-rails (2.7.1)
dotenv (= 2.7.1)
railties (>= 3.2, < 6.1)
em-http-request (1.1.5)
addressable (>= 2.3.4)
cookiejar (!= 0.3.1)
Expand All @@ -202,14 +202,14 @@ GEM
eventmachine (1.2.7)
excon (0.62.0)
execjs (2.7.0)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
factory_bot_rails (4.11.1)
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.1)
factory_bot (~> 5.0.0)
railties (>= 4.2.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
ffi (1.9.25)
ffi (1.10.0)
foreman (0.85.0)
thor (~> 0.19.1)
formtastic (3.1.5)
Expand All @@ -231,7 +231,7 @@ GEM
multi_json (>= 1.3.2)
grape-swagger (0.32.1)
grape (>= 0.16.2)
grape-swagger-rails (0.3.0)
grape-swagger-rails (0.3.1)
railties (>= 3.2.12)
gravtastic (3.2.6)
has_scope (0.7.2)
Expand Down Expand Up @@ -265,7 +265,7 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.1.0)
json (2.2.0)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
Expand Down Expand Up @@ -314,12 +314,12 @@ GEM
mustermann-grape (1.0.0)
mustermann (~> 1.0.0)
netrc (0.11.0)
newrelic_rpm (6.0.0.351)
newrelic_rpm (6.1.0.352)
nio4r (2.3.1)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
parallel (1.13.0)
parallel (1.14.0)
parser (2.6.0.0)
ast (~> 2.4.0)
pg (1.1.4)
Expand Down Expand Up @@ -355,7 +355,7 @@ GEM
rack (2.0.6)
rack-accept (0.4.5)
rack (>= 0.4)
rack-cache (1.8.0)
rack-cache (1.9.0)
rack (>= 0.4)
rack-cors (1.0.2)
rack-protection (2.0.5)
Expand Down Expand Up @@ -428,7 +428,7 @@ GEM
rgb_utils (0.1.2)
activesupport (>= 3.2)
virtus (~> 1.0)
rollbar (2.18.2)
rollbar (2.19.2)
multi_json
rspec-activemodel-mocks (1.1.0)
activemodel (>= 3.0)
Expand Down Expand Up @@ -468,22 +468,22 @@ GEM
rubocop (>= 0.60.0)
ruby-progressbar (1.10.0)
rubyzip (1.2.2)
safe_yaml (1.0.4)
safe_yaml (1.0.5)
sass (3.4.25)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sassc (2.0.0)
ffi (~> 1.9.6)
sassc (2.0.1)
ffi (~> 1.9)
rake
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
shoulda-matchers (3.1.3)
activesupport (>= 4.0.0)
shoulda-matchers (4.0.1)
activesupport (>= 4.2.0)
sidekiq (5.2.5)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
Expand Down Expand Up @@ -584,6 +584,7 @@ DEPENDENCIES
differ
dotenv-rails
factory_bot_rails
faraday
foreman
friendly_id (~> 5.2.5)
grape
Expand Down Expand Up @@ -638,6 +639,7 @@ DEPENDENCIES
uglifier (>= 2.5.3)
user_impersonate2
vcr
virtus
webmock
webpacker (>= 4.0.x)

Expand Down
10 changes: 10 additions & 0 deletions app/controllers/gitlab/projects/events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Gitlab
module Projects
class EventsController < WebhookBaseController
def create
Gitlab::ProjectEventsService.perform(params)
head :ok
end
end
end
end
27 changes: 27 additions & 0 deletions app/controllers/gitlab/webhook_base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Gitlab
class WebhookBaseController < ActionController::Base
before_action :validate_secret_key

def validate_secret_key
head :unprocessable_entity unless valid_secret_key?
end

private

def valid_secret_key?
request.headers['X-Gitlab-Token'] == integration.data['secret_key']
end

def integration
@integration ||= project.integrations.find_by(kind: 'gitlab')
end

def project
@project ||= story.project
end

def story
@story ||= Story.find_by branch: params['object_attributes']['source_branch']
end
end
end
8 changes: 8 additions & 0 deletions app/models/gitlab/branch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Gitlab
class Branch
include Virtus.model

attribute :name, String
attribute :merged, Boolean
end
end
8 changes: 8 additions & 0 deletions app/models/gitlab/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Gitlab
class Project
include Virtus.model

attribute :id, Integer
attribute :name, String
end
end
2 changes: 2 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Project < ApplicationRecord

belongs_to :tag_group

has_many :integrations, dependent: :destroy

has_many :changesets, dependent: :destroy

has_attachment :import, accept: [:raw]
Expand Down
31 changes: 31 additions & 0 deletions app/services/gitlab/create_hook_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Gitlab
class CreateHookService
delegate :error_message, to: :api, allow_nil: true

def initialize(project, params)
@project = project
@params = params
end

def fetch
return unless gitlab_integration

@api ||= GitlabApi::CreateHook.new(
gitlab_integration.data['api_url'],
gitlab_integration.data['private_token'],
gitlab_integration.data['project_id'],
@params
).perform

api.success?
end

private

def gitlab_integration
@gitlab_integration ||= @project.integrations.find_by(kind: 'gitlab')
end

attr_reader :project, :api
end
end
35 changes: 35 additions & 0 deletions app/services/gitlab/fetch_branches_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Gitlab
class FetchBranchesService
delegate :error_message, to: :api, allow_nil: true

def initialize(project)
@project = project
end

def fetch
return unless gitlab_integration

@api ||= GitlabApi::FetchBranches.new(
gitlab_integration.data['api_url'],
gitlab_integration.data['private_token'],
gitlab_integration.data['project_id']
).perform

api.success?
end

def branches
return unless api&.success?

api.data.map { |branch| Gitlab::Branch.new(branch) }
end

private

def gitlab_integration
@gitlab_integration ||= @project.integrations.find_by(kind: 'gitlab')
end

attr_reader :project, :api
end
end
34 changes: 34 additions & 0 deletions app/services/gitlab/fetch_projects_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Gitlab
class FetchProjectsService
delegate :error_message, to: :api, allow_nil: true

def initialize(project)
@project = project
end

def fetch
return unless gitlab_integration

@api ||= GitlabApi::FetchProjects.new(
gitlab_integration.data['api_url'],
gitlab_integration.data['private_token']
).perform

api.success?
end

def projects
return unless api&.success?

api.data.map { |project| Gitlab::Project.new(project) }
end

private

def gitlab_integration
@gitlab_integration ||= @project.integrations.find_by(kind: 'gitlab')
end

attr_reader :project, :api
end
end

0 comments on commit e464059

Please sign in to comment.