新增: 流水线改版接口
This commit is contained in:
		
							parent
							
								
									0fb6069ed6
								
							
						
					
					
						commit
						c7b399f624
					
				| 
						 | 
					@ -1,5 +1,49 @@
 | 
				
			||||||
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 
 | 
				
			||||||
 | 
					    @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 
 | 
				
			||||||
 | 
					    @result = []
 | 
				
			||||||
 | 
					    @files.map{|i|i['name']}.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] == 1 
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      @result << {
 | 
				
			||||||
 | 
					        name: file,
 | 
				
			||||||
 | 
					        last_action_run: last_action_run_json,
 | 
				
			||||||
 | 
					        history: {
 | 
				
			||||||
 | 
					          total: total, 
 | 
				
			||||||
 | 
					          success: success,
 | 
				
			||||||
 | 
					          failure: failure,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    render :json => @result
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def index 
 | 
					  def index 
 | 
				
			||||||
    begin 
 | 
					    begin 
 | 
				
			||||||
      gitea_result = $gitea_hat_client.get_repos_actions_by_owner_repo(@project&.owner&.login, @project&.identifier)
 | 
					      gitea_result = $gitea_hat_client.get_repos_actions_by_owner_repo(@project&.owner&.login, @project&.identifier)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					class Gitea::ActionRun < Gitea::Base
 | 
				
			||||||
 | 
					  self.inheritance_column = nil # FIX  The single-table inheritance mechanism failed
 | 
				
			||||||
 | 
					  # establish_connection :gitea_db
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  self.table_name = "action_run"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # belongs_to :user, class_name: '::User', primary_key: :gitea_uid, foreign_key: :owner_id, optional: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
| 
						 | 
					@ -162,6 +162,7 @@ defaults format: :json do
 | 
				
			||||||
            resource :dataset, only: [:create, :update, :show]
 | 
					            resource :dataset, only: [:create, :update, :show]
 | 
				
			||||||
            resources :actions, module: 'actions' do
 | 
					            resources :actions, module: 'actions' do
 | 
				
			||||||
              collection do 
 | 
					              collection do 
 | 
				
			||||||
 | 
					                get :new_index
 | 
				
			||||||
                post :disable
 | 
					                post :disable
 | 
				
			||||||
                post :enable
 | 
					                post :enable
 | 
				
			||||||
                resources :runs, only: [:index, :create] do 
 | 
					                resources :runs, only: [:index, :create] do 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue