forked from Gitlink/forgeplus
146 lines
4.3 KiB
Ruby
146 lines
4.3 KiB
Ruby
class Api::V1::Projects::CodeChecksController < Api::V1::BaseController
|
|
before_action :require_public_and_member_above
|
|
before_action :load_project
|
|
before_action -> { verification_with_setting('open_huawei_check_users') }
|
|
|
|
before_action do
|
|
@client = Api::V1::Projects::CodecheckService.new(@project)
|
|
end
|
|
def index
|
|
|
|
end
|
|
def create
|
|
@result = @client.create_task(params["branch"])
|
|
render :index
|
|
end
|
|
|
|
def run_task
|
|
@result = @client.run_task(params["branch"],params["task_id"])
|
|
render :index
|
|
end
|
|
|
|
def query_task
|
|
@result = @client.query_task(params["task_id"])
|
|
render :index
|
|
end
|
|
#----- 缺陷管理 ------
|
|
def defects_summary
|
|
allowed_query = %w[job_id merge_id]
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
@result = @client.defects_summary(query_params)
|
|
render :index
|
|
end
|
|
|
|
def metrics_summary
|
|
@result = @client.metrics_summary
|
|
render :index
|
|
end
|
|
|
|
def defects_detail
|
|
allowed_query = %w[offset limit status_ids severity delay_status]
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
Rails.logger.info "defects_detail controller "
|
|
Rails.logger.info query_params
|
|
@result = @client.defects_detail(query_params)
|
|
render :index
|
|
end
|
|
|
|
def defects_statistic
|
|
@result = @client.defects_statistic
|
|
render :index
|
|
end
|
|
|
|
def defect_status #put
|
|
allowed_body = %w[defect_id defect_status]
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
|
@result = @client.defect_status(body_params)
|
|
render :index
|
|
end
|
|
#------ 代码问题 ----
|
|
def issue_status #post
|
|
allowed_body = %w[mergeId jobId status comment mergeKey operator]
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
|
@result = @client.issue_status(body_params)
|
|
render :index
|
|
end
|
|
|
|
def issue_list_by_filter #post
|
|
allowed_body = %w[mergeId jobId pageSize page languages ruleIds authors isNew statusIds severities delayStatus fileNames userTags cwes]
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
|
@result = @client.issue_list_by_filter(body_params)
|
|
render :index
|
|
end
|
|
|
|
def issue_filter #post
|
|
allowed_body = %w[mergeId jobId facets languages ruleIds authors isNew statusIds severities delayStatus fileNames userTags cwes]
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
|
@result = @client.issue_filter(body_params)
|
|
render :index
|
|
end
|
|
|
|
def defect_metric_trend #get
|
|
allowed_query = %w[start_date end_date dimension]
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
@result = @client.defect_metric_trend(query_params)
|
|
render :index
|
|
end
|
|
|
|
def criterion_rule
|
|
allowed_query = %w[criterion_rule_id]
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
@result = @client.criterion_rule(query_params)
|
|
render :index
|
|
end
|
|
|
|
def generate_pdf
|
|
@result = @client.generate_pdf
|
|
render :index
|
|
end
|
|
|
|
def query_generate_pdf
|
|
@result = @client.query_generate_pdf(params[:async_job_id])
|
|
render :index
|
|
end
|
|
|
|
def download_pdf
|
|
allowed_query = %w[job_file]
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
@result = @client.download_pdf(query_params)
|
|
send_data(
|
|
@result[:data],
|
|
filename: @result[:filename],
|
|
type: @result[:content_type],
|
|
disposition: "attachment"
|
|
)
|
|
end
|
|
|
|
def measure_total
|
|
allowed_body = %w[jobId search]
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
|
@result = @client.measure_total(body_params)
|
|
render :index
|
|
end
|
|
|
|
def related_duplicate_blocks
|
|
allowed_query = %w[job_id file_path block_id duplication_type]
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
@result = @client.related_duplicate_blocks(query_params)
|
|
render :index
|
|
end
|
|
|
|
def measure_list
|
|
allowed_body = %w[filterType page pageSize]
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
|
@result = @client.measure_list(body_params)
|
|
render :index
|
|
end
|
|
private
|
|
|
|
# 过滤参数:可同时处理 query 和 body
|
|
def filter_params(allowed_query_keys: [], allowed_body_keys: [])
|
|
query_params = request.query_parameters.slice(*allowed_query_keys)
|
|
body_params = request.request_parameters.slice(*allowed_body_keys)
|
|
[query_params, body_params]
|
|
end
|
|
|
|
end |