json.status 0
json.message "success"
json.count @pipelines.total_count
json.projects @pipelines.map(&:project_id).uniq.each do |project_id|
  json.id project_id
  project = Project.find_by(id: project_id)
  if project.present?
    json.owner project.owner.name
    json.identifier project.identifier
    json.name project.name
    json.url "#{Rails.application.config_for(:configuration)['platform_url']}/#{project.owner.name}/#{project.identifier}"
    pipelines = Action::Pipeline.where(project_id: project.id).order(updated_at: :desc)
    pipelines =  pipelines.where("pipeline_name like ?", "%#{params[:pipeline_name]}%") if params[:pipeline_name].present?
    pipelines =  pipelines.where(pipeline_type: params[:pipeline_type]) if params[:pipeline_type].present?
    json.pipelines pipelines.each do |pipeline|
      json.extract! pipeline, :id, :project_id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design,
                    :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at
      repo_config = @disabled_workflows.select { |config| config.repo_id == pipeline.project.gpid }
      if repo_config.present?
        json.disable JSON.parse(repo_config.first.config)["DisabledWorkflows"].to_s.include?(pipeline.file_name.to_s.gsub(".gitea/workflows/", ""))
      else
        json.disable pipeline.disable
      end
      json.pipeline_type pipeline.pipeline_type
      if pipeline.json.blank? && pipeline.yaml.blank?
        json.run_data nil
      else
        json.run_data @run_result.select { |result| result[:repo_id] == project.gpid && result[:filename] == pipeline.file_name}.first
      end
      json.creator do
        if pipeline.user.present?
          json.partial! "api/v1/users/simple_user", user: pipeline.user
        else
          json.nil!
        end
      end
    end
  end
end
