fixed: 流水线批量查询运行数据,改成一维数据方便使用,增加类型识别

This commit is contained in:
xxq250 2025-01-24 09:42:45 +08:00
parent 4da3ac2558
commit a26bbf35c5
1 changed files with 18 additions and 10 deletions

View File

@ -31,18 +31,26 @@ class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions
failure += v if k[0] == file && k[1] == 2 failure += v if k[0] == file && k[1] == 2
end end
pipeline_type = 1
begin
content = Gitea::Repository::Entries::GetService.call(@project&.owner, @project&.identifier, URI.escape(file), ref: last_action_run.present? ? last_action_run.gsub("refs/heads/","") : @project.default_branch)['content']
yaml_string = Base64.decode64(content).force_encoding("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding?
yaml_string = Base64.decode64(content).force_encoding('UTF-8')
yml = YAML.safe_load(yaml_string)
pipeline_type = yml.name == file.to_s.gsub(".yml","").gsub(".yaml","") ? 2 : 1
rescue
Rails.logger.info("#{file}不能识别流水线类型")
end
@result << { @result << {
name: file, name: file.to_s.gsub(".yml","").gsub(".yaml","") ,
last_action_run: last_action_run_json, branch: last_action_run.present? ? last_action_run.gsub("refs/heads/","") : @project.default_branch,
history: { pipeline_type: pipeline_type,
total: total, total: total,
success: success, success: success,
failure: failure, failure: failure
} }.merge(last_action_run_json)
}
end end
render :json => {data: @result}
render :json => @result
end end
def index def index