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