-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
2,376 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.