2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-09 07:10:16 -05:00
|
|
|
class Projects::BadgesController < Projects::ApplicationController
|
2016-04-04 06:32:50 -04:00
|
|
|
layout 'project_settings'
|
|
|
|
before_action :authorize_admin_project!, only: [:index]
|
2019-06-21 12:56:03 -04:00
|
|
|
before_action :no_cache_headers, only: [:pipeline, :coverage]
|
|
|
|
before_action :authorize_read_build!, only: [:pipeline, :coverage]
|
2016-03-22 05:21:45 -04:00
|
|
|
|
2021-11-17 04:10:43 -05:00
|
|
|
feature_category :continuous_integration, [:index, :pipeline]
|
|
|
|
feature_category :code_testing, [:coverage]
|
2020-10-08 14:08:32 -04:00
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
def pipeline
|
2021-01-26 22:08:58 -05:00
|
|
|
pipeline_status = Gitlab::Ci::Badge::Pipeline::Status
|
2020-05-29 17:08:35 -04:00
|
|
|
.new(project, params[:ref], opts: {
|
2020-08-24 08:10:17 -04:00
|
|
|
ignore_skipped: params[:ignore_skipped],
|
2020-05-29 17:08:35 -04:00
|
|
|
key_text: params[:key_text],
|
|
|
|
key_width: params[:key_width]
|
|
|
|
})
|
2016-03-23 06:24:18 -04:00
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
render_badge pipeline_status
|
2016-08-11 09:17:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def coverage
|
2021-01-26 22:08:58 -05:00
|
|
|
coverage_report = Gitlab::Ci::Badge::Coverage::Report
|
2020-05-29 17:08:35 -04:00
|
|
|
.new(project, params[:ref], opts: {
|
|
|
|
job: params[:job],
|
|
|
|
key_text: params[:key_text],
|
2021-09-28 20:10:07 -04:00
|
|
|
key_width: params[:key_width],
|
|
|
|
min_good: params[:min_good],
|
|
|
|
min_acceptable: params[:min_acceptable],
|
|
|
|
min_medium: params[:min_medium]
|
2020-05-29 17:08:35 -04:00
|
|
|
})
|
2016-08-11 09:17:13 -04:00
|
|
|
|
|
|
|
render_badge coverage_report
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-01-18 08:39:35 -05:00
|
|
|
def badge_layout
|
|
|
|
case params[:style]
|
|
|
|
when 'flat'
|
|
|
|
'badge'
|
|
|
|
when 'flat-square'
|
|
|
|
'badge_flat-square'
|
|
|
|
else
|
|
|
|
'badge'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-11 09:17:13 -04:00
|
|
|
def render_badge(badge)
|
2016-02-09 07:10:16 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render_404 }
|
|
|
|
format.svg do
|
2019-01-18 08:39:35 -05:00
|
|
|
render badge_layout, locals: { badge: badge.template }
|
2016-02-09 07:10:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|