OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix rubocop warning
Christophe Bliard1eeebb72bbb7
diff --git a/script/github_pr_errors b/script/github_pr_errorsindex e54bff02efc..63651a8f702 100755--- a/script/github_pr_errors+++ b/script/github_pr_errors@@ -272,14 +272,56 @@ def get_workflow_run(run_id)endend-class Report- attr_accessor :errors,- :failures_explanation,- :head_branch,- :head_sha,- :commit_message,- :run_started_at,- :merge_branch_sha+class WorkflowRunDecorator+ attr_reader :workflow_run++ def initialize(workflow_run)+ @workflow_run = workflow_run+ end++ def head_branch = workflow_run["head_branch"]+ def head_sha = workflow_run["head_sha"]+ def run_started_at = Time.parse(workflow_run["run_started_at"]).utc++ def commit_message+ workflow_run["head_commit"]+ .then { |commit| commit["message"] }+ .then { |message| message.split("\n", 2).first }+ end+end++Report = Data.define(+ :errors,+ :failures_explanation,+ :head_branch,+ :head_sha,+ :commit_message,+ :run_started_at,+ :run_status,+ :failed_job_logs,+ :merge_branch_sha+) do+ def initialize(errors: [],+ failures_explanation: nil,+ head_branch: nil,+ head_sha: nil,+ commit_message: nil,+ run_started_at: nil,+ run_status: nil,+ failed_job_logs: nil,+ merge_branch_sha: nil)+ super+ end++ def with_workflow_run_info(workflow_run)+ workflow_run = WorkflowRunDecorator.new(workflow_run)+ with(+ head_branch: workflow_run.head_branch,+ head_sha: workflow_run.head_sha,+ commit_message: workflow_run.commit_message,+ run_started_at: workflow_run.run_started_at+ )+ endendclass Error@@ -322,10 +364,11 @@ class JobErrorsFinderlogs.each do |log|finder.scan_log(log)end- report.errors = finder.errors- report.failures_explanation = finder.failures_explanation- report.merge_branch_sha = finder.merge_branch_sha- report+ report.with(+ errors: finder.errors,+ failures_explanation: finder.failures_explanation,+ merge_branch_sha: finder.merge_branch_sha+ )enddef scan_log(log)@@ -454,16 +497,11 @@ class Formatter@compactend- def display_workflow_run_info(report, workflow_run)- report.head_branch = workflow_run["head_branch"]- report.head_sha = workflow_run["head_sha"]- report.commit_message = commit_message(workflow_run)- report.run_started_at = Time.parse(workflow_run["run_started_at"]).utc+ def display_workflow_run_info(report)warn " Branch: #{report.head_branch.bold}"warn " Commit SHA: #{report.head_sha.bold}"warn " Commit message: #{report.commit_message.bold}"warn " Last attempted run started at: #{report.run_started_at.localtime.to_s.bold}"- display_pull_request_info(workflow_run)enddef display_workflow_status(workflow_run)@@ -475,7 +513,7 @@ class Formatterwarn " #{status_line(job)}"end- def display_report(report)+ def display_errors_from_report(report)display_failures_explanation(report.failures_explanation)display_errors(report.errors)display_checkout_test_commit_information(report) if Options.display_rerun_info@@ -499,6 +537,19 @@ class Formatterendend+ def display_pull_request_info(workflow_run)+ return unless workflow_run["event"] == "pull_request"++ if pr = workflow_run["pull_requests"].first+ pr_number = "##{pr['number']}"+ pr_html_url = "#{GITHUB_HTML_OPENPROJECT_PREFIX}/pull/#{pr['number']}"+ pr_display_title = "#{workflow_run['display_title']} #{pr_number.white.dark} #{pr_html_url.white.dark}"+ warn " Pull Request: #{pr_display_title} "+ else+ warn " Pull Request: not found; perhaps it is already merged or closed?"+ end+ end+privatedef display_errors_compact(errors)@@ -599,25 +650,6 @@ class Formatterwarn ""end- def display_pull_request_info(workflow_run)- return unless workflow_run["event"] == "pull_request"-- if pr = workflow_run["pull_requests"].first- pr_number = "##{pr['number']}"- pr_html_url = "#{GITHUB_HTML_OPENPROJECT_PREFIX}/pull/#{pr['number']}"- pr_display_title = "#{workflow_run['display_title']} #{pr_number.white.dark} #{pr_html_url.white.dark}"- warn " Pull Request: #{pr_display_title} "- else- warn " Pull Request: not found; perhaps it is already merged or closed?"- end- end-- def commit_message(workflow_run)- workflow_run["head_commit"]- .then { |commit| commit["message"] }- .then { |message| message.split("\n", 2).first }- end-def status_icon(job)case job["status"]when "queued", "in_progress"@@ -680,13 +712,18 @@ enddef get_failed_jobs_logs_from_github(report, formatter)workflow_run = get_workflow_run(Options.run_id)+ report = report.with_workflow_run_info(workflow_run)- formatter.display_workflow_run_info(report, workflow_run)+ formatter.display_workflow_run_info(report)+ formatter.display_pull_request_info(workflow_run)- job_logs = get_relevant_jobs(Options.job_id, workflow_run, formatter)+ failed_job_logs = get_relevant_jobs(Options.job_id, workflow_run, formatter).map { |job| get_log(job) }- [job_logs, job_logs.any? ? "error" : workflow_run["status"]]+ report.with(+ failed_job_logs:,+ run_status: failed_job_logs.any? ? "error" : workflow_run["status"]+ )enddef get_failed_jobs_logs_from_args@@ -695,7 +732,11 @@ enddef get_failed_jobs_logs(report, formatter)if Options.failed_jobs_logs.any?- [get_failed_jobs_logs_from_args, failed_jobs_logs.none? ? "completed" : "error"]+ failed_job_logs = get_failed_jobs_logs_from_args+ report.with(+ failed_job_logs:,+ run_status: failed_job_logs.none? ? "completed" : "error"+ )elseget_failed_jobs_logs_from_github(report, formatter)end@@ -707,15 +748,15 @@ endreport = Report.newformatter = Formatter.new(compact: Options.compact)-failed_jobs_logs, status = get_failed_jobs_logs(report, formatter)+report = get_failed_jobs_logs(report, formatter)-JobErrorsFinder.scan_logs(report, failed_jobs_logs)+report = JobErrorsFinder.scan_logs(report, report.failed_job_logs)-case status+case report.run_statuswhen "completed"warn "All jobs successful 🎉"when "in_progress"# NOOPwhen "error"- formatter.display_report(report)+ formatter.display_errors_from_report(report)end