流水线列表新接口
This commit is contained in:
parent
0c438cbe21
commit
164bcb86bd
|
@ -5,13 +5,17 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
||||||
def index
|
def index
|
||||||
pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)
|
pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)
|
||||||
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue []
|
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue []
|
||||||
|
@action_runs = Gitea::ActionRun.where(repo_id: @project.gpid)
|
||||||
|
group_data = @action_runs.where(status: [1,2]).group(:workflow_id, :status).count
|
||||||
db_files = pipelines.pluck(:file_name)
|
db_files = pipelines.pluck(:file_name)
|
||||||
|
@run_result = []
|
||||||
@files.map { |i| i['name'] }.each do |file|
|
@files.map { |i| i['name'] }.each do |file|
|
||||||
unless db_files.include?(".gitea/workflows/#{file}")
|
unless db_files.include?(".gitea/workflows/#{file}")
|
||||||
pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""),
|
pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""),
|
||||||
file_name: ".gitea/workflows/#{file}",
|
file_name: ".gitea/workflows/#{file}",
|
||||||
branch: @project.default_branch,
|
branch: @project.default_branch,
|
||||||
is_graphic_design: false,
|
is_graphic_design: false,
|
||||||
|
disable: false,
|
||||||
project_id: @project.id)
|
project_id: @project.id)
|
||||||
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, ".gitea/workflows/#{file}", ref: @project.default_branch)
|
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, ".gitea/workflows/#{file}", ref: @project.default_branch)
|
||||||
if interactor.success?
|
if interactor.success?
|
||||||
|
@ -20,6 +24,34 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
||||||
pipeline.user_id = current_user.id
|
pipeline.user_id = current_user.id
|
||||||
pipeline.save
|
pipeline.save
|
||||||
end
|
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,
|
||||||
|
schedule: last_action_run.schedule_id > 0,
|
||||||
|
title: last_action_run.title,
|
||||||
|
index: last_action_run.index,
|
||||||
|
status: last_action_run.status,
|
||||||
|
started: last_action_run.started,
|
||||||
|
stopped: last_action_run.stopped,
|
||||||
|
length: last_action_run.stopped-last_action_run.started,
|
||||||
|
created: last_action_run.created,
|
||||||
|
updated: last_action_run.updated,
|
||||||
|
} : {}
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
success = 0
|
||||||
|
failure = 0
|
||||||
|
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] == 2
|
||||||
|
end
|
||||||
|
@run_result << {
|
||||||
|
filename: ".gitea/workflows/#{file}",
|
||||||
|
total: total,
|
||||||
|
success: success,
|
||||||
|
failure: failure
|
||||||
|
}.merge(last_action_run_json)
|
||||||
end
|
end
|
||||||
@pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)
|
@pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)
|
||||||
@pipelines = paginate @pipelines
|
@pipelines = paginate @pipelines
|
||||||
|
|
|
@ -36,4 +36,8 @@ class Action::Pipeline < ApplicationRecord
|
||||||
validates :pipeline_name, presence: { message: "不能为空" }
|
validates :pipeline_name, presence: { message: "不能为空" }
|
||||||
validates :json, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
validates :json, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
||||||
validates :yaml, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
validates :yaml, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
||||||
|
|
||||||
|
def pipeline_type
|
||||||
|
self.is_graphic_design? ? 2 : 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
json.status 0
|
json.status 0
|
||||||
json.message "success"
|
json.message "success"
|
||||||
|
|
||||||
json.pipelines @pipelines.each do |pip|
|
json.pipelines @pipelines.each do |pipeline|
|
||||||
json.extract! pip, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design,
|
json.extract! pipeline, :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_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at
|
||||||
# json.project
|
json.pipeline_type
|
||||||
|
json.run_data @run_result.select { |result| result.filename == pipeline.file_name }.first
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue