diff --git a/Gemfile b/Gemfile index edaae8a75..811fabc41 100644 --- a/Gemfile +++ b/Gemfile @@ -141,4 +141,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.4.6' +gem 'gitea-client', '~> 1.5.7' diff --git a/app/controllers/api/v1/projects/actions/runs_controller.rb b/app/controllers/api/v1/projects/actions/runs_controller.rb index 05918dbe2..ff7c28e85 100644 --- a/app/controllers/api/v1/projects/actions/runs_controller.rb +++ b/app/controllers/api/v1/projects/actions/runs_controller.rb @@ -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 \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 59d061629..34751cf50 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -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