2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
class Projects::BadgesController < Projects::ApplicationController
|
2016-06-02 11:05:42 +05:30
|
|
|
layout 'project_settings'
|
|
|
|
before_action :authorize_admin_project!, only: [:index]
|
2019-07-31 22:56:46 +05:30
|
|
|
before_action :no_cache_headers, only: [:pipeline, :coverage]
|
|
|
|
before_action :authorize_read_build!, only: [:pipeline, :coverage]
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
feature_category :continuous_integration, [:index, :pipeline]
|
|
|
|
feature_category :code_testing, [:coverage]
|
2022-04-04 11:22:00 +05:30
|
|
|
feature_category :release_orchestration, [:release]
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def pipeline
|
2021-03-11 19:13:27 +05:30
|
|
|
pipeline_status = Gitlab::Ci::Badge::Pipeline::Status
|
2020-06-23 00:09:42 +05:30
|
|
|
.new(project, params[:ref], opts: {
|
2023-03-04 22:38:38 +05:30
|
|
|
ignore_skipped: params[:ignore_skipped],
|
|
|
|
key_text: params[:key_text],
|
|
|
|
key_width: params[:key_width]
|
|
|
|
})
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
render_badge pipeline_status
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def coverage
|
2021-03-11 19:13:27 +05:30
|
|
|
coverage_report = Gitlab::Ci::Badge::Coverage::Report
|
2020-06-23 00:09:42 +05:30
|
|
|
.new(project, params[:ref], opts: {
|
2023-03-04 22:38:38 +05:30
|
|
|
job: params[:job],
|
|
|
|
key_text: params[:key_text],
|
|
|
|
key_width: params[:key_width],
|
|
|
|
min_good: params[:min_good],
|
|
|
|
min_acceptable: params[:min_acceptable],
|
|
|
|
min_medium: params[:min_medium]
|
|
|
|
})
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
render_badge coverage_report
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
def release
|
|
|
|
latest_release = Gitlab::Ci::Badge::Release::LatestRelease
|
|
|
|
.new(project, current_user, opts: {
|
2023-03-04 22:38:38 +05:30
|
|
|
key_text: params[:key_text],
|
|
|
|
key_width: params[:key_width],
|
2023-05-27 22:25:52 +05:30
|
|
|
value_width: params[:value_width],
|
2023-03-04 22:38:38 +05:30
|
|
|
order_by: params[:order_by]
|
|
|
|
})
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
render_badge latest_release
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
private
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
def badge_layout
|
|
|
|
case params[:style]
|
|
|
|
when 'flat'
|
|
|
|
'badge'
|
|
|
|
when 'flat-square'
|
|
|
|
'badge_flat-square'
|
|
|
|
else
|
|
|
|
'badge'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def render_badge(badge)
|
2016-04-02 18:10:28 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html { render_404 }
|
|
|
|
format.svg do
|
2019-03-02 22:35:43 +05:30
|
|
|
render badge_layout, locals: { badge: badge.template }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|