Merge branch 'pre_trustie_server' into trustie_server

This commit is contained in:
yystopf 2025-02-14 16:35:37 +08:00
commit 9e10625b8b
7 changed files with 88 additions and 29 deletions

View File

@ -0,0 +1,45 @@
class Api::Pm::ActionRunsController < Api::Pm::BaseController
before_action :require_login
def index
tip_exception('请输入workflows') if params[:workflows].blank?
@owner = Owner.find_by(login: params[:owner_id].to_s) || Owner.find_by(id: params[:owner_id].to_s)
tip_exception('组织未找到') if @owner.blank?
action_runs = Gitea::ActionRun.where(owner_id: @owner.gitea_uid)
group_data = action_runs.where(workflow_id: params[:workflows].to_s.split(",")).where(status: [1,2]).group(:workflow_id, :status).count
@result = []
params[:workflows].to_s.split(",").each do |file|
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
@result << {
name: file,
total: total,
success: success,
failure: failure
}.merge(last_action_run_json)
end
render :json => {data: @result}
end
end

View File

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

View File

@ -1,8 +1,9 @@
class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController
def index def index
@result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token) @result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token)
puts @result_object @begin_num = (page.to_i - 1) * limit.to_i
# puts @result_object
end end
def create def create

View File

@ -31,6 +31,7 @@ class Projects::TransferService < ApplicationService
project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) } project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) }
project.update!(user_id: new_owner.id) project.update!(user_id: new_owner.id)
project.set_owner_permission(new_owner) project.set_owner_permission(new_owner)
project.pinned_projects.destroy_all # 移除原来精选的项目
end end
def update_actions def update_actions

View File

@ -1,6 +1,7 @@
json.total_data @result_object[:total_data].to_i json.total_data @result_object[:total_data].to_i
if @result_object[:data]["Runs"].present? if @result_object[:data]["Runs"].present?
json.runs @result_object[:data]["Runs"].each do |run| json.runs @result_object[:data]["Runs"].each_with_index.to_a do |run, index|
json.num @result_object[:total_data].to_i - @begin_num - index
json.workflow run["WorkflowID"] json.workflow run["WorkflowID"]
json.index run["Index"] json.index run["Index"]
json.title run["Title"] json.title run["Title"]

View File

@ -13,19 +13,15 @@ on:
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
paths-ignore:
- '.gitea/workflows/**'
- '.github/workflows/**'
<% end %> <% end %>
<%if node.name.to_s.include?("on-pull_request") && node.input_values.present? %> <%if node.name.to_s.include?("on-pull_request") %>
pull_request: pull_request:
<% node.input_values.each_key do |key| %> <% end %>
<%=key %>: <%if node.name.to_s.include?("on-fork") %>
<% if node.input_values[key].blank? %> fork:
- '*'
<% else %>
<% node.input_values[key].to_s.split(",").each do |val| %>
- <%=val %>
<% end %>
<% end %>
<% end %>
<% end %> <% end %>
<%if node.name.to_s.include?("on-schedule") && node.input_values.present? %> <%if node.name.to_s.include?("on-schedule") && node.input_values.present? %>
schedule: schedule:

View File

@ -50,6 +50,7 @@ defaults format: :json do
get :polyline get :polyline
end end
end end
resources :action_runs, only: [:index]
end end
namespace :v1 do namespace :v1 do