新增:actions重新运行接口
This commit is contained in:
		
							parent
							
								
									caa7acc654
								
							
						
					
					
						commit
						572a6de2ad
					
				
							
								
								
									
										2
									
								
								Gemfile
								
								
								
								
							
							
						
						
									
										2
									
								
								Gemfile
								
								
								
								
							| 
						 | 
				
			
			@ -141,4 +141,4 @@ gem 'doorkeeper'
 | 
			
		|||
 | 
			
		||||
gem 'doorkeeper-jwt'
 | 
			
		||||
 | 
			
		||||
gem 'gitea-client', '~> 1.4.6'
 | 
			
		||||
gem 'gitea-client', '~> 1.5.7'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,42 @@ class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::B
 | 
			
		|||
    puts @result_object
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def rerun 
 | 
			
		||||
    return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
 | 
			
		||||
    gitea_result = $gitea_hat_client.post_repos_actions_runs_rerun_by_owner_repo_run(@project&.owner&.login, @project&.identifier, params[:run_id]) rescue nil 
 | 
			
		||||
    if gitea_result
 | 
			
		||||
      render_ok 
 | 
			
		||||
    else 
 | 
			
		||||
      render_error("重启所有流水线任务失败")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def job_rerun 
 | 
			
		||||
    return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
 | 
			
		||||
    return render_error("请输入正确的流水线任务ID") if params[:job].blank? 
 | 
			
		||||
    gitea_result = $gitea_hat_client.post_repos_actions_runs_jobs_rerun_by_owner_repo_run_job(@project&.owner&.login, @project&.identifier, params[:run_id], params[:job]) rescue nil 
 | 
			
		||||
    if gitea_result
 | 
			
		||||
      render_ok 
 | 
			
		||||
    else 
 | 
			
		||||
      render_error("重启流水线任务失败")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def job_show 
 | 
			
		||||
    @result_object = Api::V1::Projects::Actions::Runs::JobShowService.call(@project, params[:run_id], params[:job], params[:log_cursors], current_user&.gitea_token)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def job_logs 
 | 
			
		||||
    return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
 | 
			
		||||
    return render_error("请输入正确的流水线任务ID") if params[:job].blank? 
 | 
			
		||||
    domain  = GiteaService.gitea_config[:domain]
 | 
			
		||||
    api_url = GiteaService.gitea_config[:hat_base_url]
 | 
			
		||||
 | 
			
		||||
    url = "/repos/#{@owner.login}/#{@repository.identifier}/actions/runs/#{CGI.escape(params[:run_id])}/jobs/#{CGI.escape(params[:job])}/logs"
 | 
			
		||||
    file_path = [domain, api_url, url].join
 | 
			
		||||
    file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?") 
 | 
			
		||||
 | 
			
		||||
    redirect_to file_path
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -96,6 +96,9 @@ defaults format: :json do
 | 
			
		|||
                post :enable
 | 
			
		||||
                resources :runs, only: [:index] do 
 | 
			
		||||
                  post '/jobs/:job', to: 'runs#job_show'
 | 
			
		||||
                  post '/rerun', to: 'runs#rerun'
 | 
			
		||||
                  post '/jobs/:job/rerun', to: 'runs#job_rerun'
 | 
			
		||||
                  get '/jobs/:job/logs', to: 'runs#job_logs'
 | 
			
		||||
                end 
 | 
			
		||||
              end
 | 
			
		||||
            end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue