2014-09-02 18:07:02 +05:30
|
|
|
class Projects::ServicesController < Projects::ApplicationController
|
2015-09-11 14:41:01 +05:30
|
|
|
ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_version, :subdomain,
|
|
|
|
:room, :recipients, :project_url, :webhook,
|
|
|
|
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
|
2015-09-25 12:07:36 +05:30
|
|
|
:build_key, :server, :teamcity_url, :drone_url, :build_type,
|
2015-09-11 14:41:01 +05:30
|
|
|
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
|
|
|
|
:colorize_messages, :channels,
|
|
|
|
:push_events, :issues_events, :merge_requests_events, :tag_push_events,
|
|
|
|
:note_events, :send_from_committer_email, :disable_diffs, :external_wiki_url,
|
|
|
|
:notify, :color,
|
2015-09-25 12:07:36 +05:30
|
|
|
:server_host, :server_port, :default_irc_uri, :enable_ssl_verification]
|
2014-09-02 18:07:02 +05:30
|
|
|
# Authorize
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_admin_project!
|
|
|
|
before_action :service, only: [:edit, :update, :test]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
layout "project_settings"
|
|
|
|
|
|
|
|
def index
|
|
|
|
@project.build_missing_services
|
2015-04-26 12:48:37 +05:30
|
|
|
@services = @project.services.visible.reload
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @service.update_attributes(service_params)
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to(
|
|
|
|
edit_namespace_project_service_path(@project.namespace, @project,
|
|
|
|
@service.to_param, notice:
|
|
|
|
'Successfully updated.')
|
|
|
|
)
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
2015-04-26 12:48:37 +05:30
|
|
|
data = Gitlab::PushDataBuilder.build_sample(project, current_user)
|
2015-09-11 14:41:01 +05:30
|
|
|
outcome = @service.test(data)
|
|
|
|
if outcome[:success]
|
2015-04-26 12:48:37 +05:30
|
|
|
message = { notice: 'We sent a request to the provided URL' }
|
|
|
|
else
|
2015-09-11 14:41:01 +05:30
|
|
|
error_message = "We tried to send a request to the provided URL but an error occurred"
|
|
|
|
error_message << ": #{outcome[:result]}" if outcome[:result].present?
|
|
|
|
message = { alert: error_message }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to :back, message
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def service
|
|
|
|
@service ||= @project.services.find { |service| service.to_param == params[:id] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def service_params
|
2015-09-11 14:41:01 +05:30
|
|
|
params.require(:service).permit(ALLOWED_PARAMS)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|