Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
yystopf 2025-02-14 16:35:09 +08:00
commit 383019b7f5
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
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

View File

@ -1,8 +1,9 @@
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)
puts @result_object
@begin_num = (page.to_i - 1) * limit.to_i
# puts @result_object
end
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.update!(user_id: new_owner.id)
project.set_owner_permission(new_owner)
project.pinned_projects.destroy_all # 移除原来精选的项目
end
def update_actions

View File

@ -1,6 +1,7 @@
json.total_data @result_object[:total_data].to_i
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.index run["Index"]
json.title run["Title"]

View File

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

View File

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