2025-11-13 15:53:21 +08:00
|
|
|
class Api::V1::Projects::CodeChecksController < Api::V1::BaseController
|
2025-11-12 17:33:01 +08:00
|
|
|
before_action :require_public_and_member_above
|
|
|
|
|
before_action :load_project
|
2025-11-13 11:18:06 +08:00
|
|
|
before_action -> { verification_with_setting('open_huawei_check_users') }
|
2025-11-13 11:01:57 +08:00
|
|
|
|
2025-11-12 17:33:01 +08:00
|
|
|
before_action do
|
|
|
|
|
@client = Api::V1::Projects::CodecheckService.new(@project)
|
|
|
|
|
end
|
2025-11-13 11:01:57 +08:00
|
|
|
def index
|
2025-11-12 17:33:01 +08:00
|
|
|
|
2025-11-13 11:01:57 +08:00
|
|
|
end
|
2025-11-12 17:33:01 +08:00
|
|
|
def create
|
|
|
|
|
@result = @client.create_task(params["branch"])
|
2025-11-13 11:01:57 +08:00
|
|
|
render :index
|
2025-11-12 17:33:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def run_task
|
2025-11-19 16:12:00 +08:00
|
|
|
@result = @client.run_task(params["branch"],params["task_id"])
|
2025-11-13 11:01:57 +08:00
|
|
|
render :index
|
2025-11-12 17:33:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def query_task
|
2025-11-19 16:12:00 +08:00
|
|
|
@result = @client.query_task(params["task_id"])
|
2025-11-13 11:01:57 +08:00
|
|
|
render :index
|
2025-11-12 17:33:01 +08:00
|
|
|
end
|
2025-11-13 11:01:57 +08:00
|
|
|
#----- 缺陷管理 ------
|
2025-11-12 17:33:01 +08:00
|
|
|
def defects_summary
|
2025-11-13 21:58:39 +08:00
|
|
|
allowed_query = %w[job_id merge_id]
|
|
|
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
|
|
|
@result = @client.defects_summary(query_params)
|
2025-11-13 11:01:57 +08:00
|
|
|
render :index
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def metrics_summary
|
|
|
|
|
@result = @client.metrics_summary
|
|
|
|
|
render :index
|
2025-11-12 17:33:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def defects_detail
|
2025-11-13 21:58:39 +08:00
|
|
|
allowed_query = %w[offset limit status_ids severity delay_status]
|
|
|
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
2025-11-14 15:24:31 +08:00
|
|
|
Rails.logger.info "defects_detail controller "
|
|
|
|
|
Rails.logger.info query_params
|
2025-11-13 21:58:39 +08:00
|
|
|
@result = @client.defects_detail(query_params)
|
2025-11-13 11:01:57 +08:00
|
|
|
render :index
|
2025-11-12 17:33:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def defects_statistic
|
|
|
|
|
@result = @client.defects_statistic
|
2025-11-13 11:01:57 +08:00
|
|
|
render :index
|
2025-11-12 17:33:01 +08:00
|
|
|
end
|
|
|
|
|
|
2025-11-13 11:01:57 +08:00
|
|
|
def defect_status #put
|
2025-11-18 10:28:28 +08:00
|
|
|
allowed_body = %w[defect_id defect_status]
|
2025-11-18 10:52:16 +08:00
|
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
2025-11-13 21:58:39 +08:00
|
|
|
@result = @client.defect_status(body_params)
|
2025-11-13 11:01:57 +08:00
|
|
|
render :index
|
|
|
|
|
end
|
2025-11-18 15:45:54 +08:00
|
|
|
#------ 代码问题 ----
|
|
|
|
|
def issue_status #post
|
2025-11-18 16:14:07 +08:00
|
|
|
allowed_body = %w[mergeId jobId status comment mergeKey operator]
|
|
|
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
2025-11-18 15:45:54 +08:00
|
|
|
@result = @client.issue_status(body_params)
|
|
|
|
|
render :index
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def issue_list_by_filter #post
|
2025-11-18 16:14:07 +08:00
|
|
|
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)
|
2025-11-18 15:45:54 +08:00
|
|
|
@result = @client.issue_list_by_filter(body_params)
|
|
|
|
|
render :index
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def issue_filter #post
|
2025-11-18 16:14:07 +08:00
|
|
|
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)
|
2025-11-18 15:45:54 +08:00
|
|
|
@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
|
2025-11-14 10:48:57 +08:00
|
|
|
|
2025-11-18 17:55:10 +08:00
|
|
|
def generate_pdf
|
|
|
|
|
@result = @client.generate_pdf
|
|
|
|
|
render :index
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def query_generate_pdf
|
2025-11-19 11:17:48 +08:00
|
|
|
@result = @client.query_generate_pdf(params[:async_job_id])
|
|
|
|
|
render :index
|
2025-11-18 17:55:10 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def download_pdf
|
|
|
|
|
allowed_query = %w[job_file]
|
|
|
|
|
query_params, _ = filter_params(allowed_query_keys: allowed_query)
|
|
|
|
|
@result = @client.download_pdf(query_params)
|
2025-11-19 11:17:48 +08:00
|
|
|
send_data(
|
|
|
|
|
@result[:data],
|
|
|
|
|
filename: @result[:filename],
|
|
|
|
|
type: @result[:content_type],
|
|
|
|
|
disposition: "attachment"
|
|
|
|
|
)
|
2025-11-18 17:55:10 +08:00
|
|
|
end
|
|
|
|
|
|
2025-11-19 14:34:38 +08:00
|
|
|
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
|
2025-11-25 17:04:09 +08:00
|
|
|
allowed_body = %w[filterType page pageSize]
|
2025-11-19 17:46:58 +08:00
|
|
|
_, body_params = filter_params(allowed_body_keys: allowed_body)
|
|
|
|
|
@result = @client.measure_list(body_params)
|
2025-11-19 14:34:38 +08:00
|
|
|
render :index
|
|
|
|
|
end
|
2025-11-13 21:58:39 +08:00
|
|
|
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
|
2025-11-12 17:33:01 +08:00
|
|
|
|
|
|
|
|
end
|