Commit b0a8bd12 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-generic-api-endpoint' into 'master'

Create a blank endpoint for generic alerts

See merge request gitlab-org/gitlab-ee!15802
parents eab1cd01 7ee732ac
# frozen_string_literal: true
module Projects
module Alerting
class NotificationsController < Projects::ApplicationController
respond_to :json
skip_before_action :project
prepend_before_action :repository, :project_without_auth
before_action :check_generic_alert_endpoint_feature_flag!
def create
head :ok
end
private
def project_without_auth
@project ||= Project
.find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}")
end
def check_generic_alert_endpoint_feature_flag!
render_404 unless Feature.enabled?(:generic_alert_endpoint, @project)
end
end
end
end
......@@ -127,12 +127,8 @@ module Projects
end
def project_without_auth
return @project if @project
namespace = params[:namespace_id]
id = params[:project_id]
@project = Project.find_by_full_path("#{namespace}/#{id}")
@project ||= Project
.find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}")
end
def prometheus_alerts
......
......@@ -52,6 +52,8 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end
# End of the /-/ scope.
post 'alerts/notify', to: 'alerting/notifications#create'
resource :tracing, only: [:show]
resources :web_ide_terminals, path: :ide_terminals, only: [:create, :show], constraints: { id: /\d+/, format: :json } do
......
# frozen_string_literal: true
require 'spec_helper'
describe Projects::Alerting::NotificationsController do
set(:project) { create(:project) }
set(:environment) { create(:environment, project: project) }
describe 'POST #create' do
def make_request(opts = {})
post :create, params: project_params, session: { as: :json }
end
context 'when feature flag is on' do
before do
stub_feature_flags(generic_alert_endpoint: true)
end
it 'responds with ok' do
make_request
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when feature flag is off' do
before do
stub_feature_flags(generic_alert_endpoint: false)
end
it 'responds with not_found' do
make_request
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
def project_params(opts = {})
opts.reverse_merge(namespace_id: project.namespace, project_id: project)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment