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
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
def pipeline
|
|
|
|
pipeline_status = Gitlab::Badge::Pipeline::Status
|
2016-08-11 09:17:13 -04:00
|
|
|
.new(project, params[:ref])
|
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
|
|
|
|
coverage_report = Gitlab::Badge::Coverage::Report
|
|
|
|
.new(project, params[:ref], params[:job])
|
|
|
|
|
|
|
|
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
|