|
|
|
@@ -1,12 +1,17 @@ |
|
|
|
class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions::BaseController |
|
|
|
|
|
|
|
def new_index |
|
|
|
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") |
|
|
|
puts @files |
|
|
|
@action_runs = Gitea::ActionRun.where(repo_id: @project.gpid, status: [1,2]) |
|
|
|
group_data = @action_runs.group(:workflow_id, :status).count |
|
|
|
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue [] |
|
|
|
@workflows = params[:workflows].split(",") if params[:workflows].present? |
|
|
|
@action_runs = Gitea::ActionRun.where(repo_id: @project.gpid) |
|
|
|
@action_runs = @action_runs.where(id: params[:ids].split(",")) if params[:ids].present? |
|
|
|
@action_runs = @action_runs.where(workflow_id: @workflows) if params[:workflows].present? |
|
|
|
group_data = @action_runs.where(status: [1,2]).group(:workflow_id, :status).count |
|
|
|
@result = [] |
|
|
|
@files.map{|i|i['name']}.each do |file| |
|
|
|
if @workflows.present? |
|
|
|
next if !@workflows.include?(file) |
|
|
|
end |
|
|
|
last_action_run = @action_runs.where(workflow_id: file).order(updated: :desc).first |
|
|
|
last_action_run_json = last_action_run.present? ? { |
|
|
|
id: last_action_run.id, |
|
|
|
@@ -27,21 +32,30 @@ class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions |
|
|
|
group_data.each do |k,v| |
|
|
|
total += v if k[0] == file |
|
|
|
success += v if k[0] == file && k[1] == 1 |
|
|
|
failure += v if k[0] == file && k[1] == 1 |
|
|
|
failure += v if k[0] == file && k[1] == 2 |
|
|
|
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.ref.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 << { |
|
|
|
name: file, |
|
|
|
last_action_run: last_action_run_json, |
|
|
|
history: { |
|
|
|
total: total, |
|
|
|
success: success, |
|
|
|
failure: failure, |
|
|
|
} |
|
|
|
} |
|
|
|
filename: file, |
|
|
|
name: file.to_s.gsub(".yml","").gsub(".yaml","") , |
|
|
|
branch: last_action_run.present? ? last_action_run.ref.gsub("refs/heads/","") : @project.default_branch, |
|
|
|
pipeline_type: pipeline_type, |
|
|
|
total: total, |
|
|
|
success: success, |
|
|
|
failure: failure |
|
|
|
}.merge(last_action_run_json) |
|
|
|
end |
|
|
|
|
|
|
|
render :json => @result |
|
|
|
render :json => {data: @result} |
|
|
|
end |
|
|
|
|
|
|
|
def index |
|
|
|
|