Skip to content

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

Improve retrieval of pull requests errors

Christophe Bliard25088797ba1c
diff --git a/script/github_pr_errors b/script/github_pr_errors
index 7e4af3c1b1d..236da825422 100755
--- a/script/github_pr_errors
+++ b/script/github_pr_errors
@@ -4,8 +4,6 @@ require 'pathname'
require 'json'
require 'rest-client'
require 'pry'
-require 'zip'
-require 'tempfile'
# current branch
branch_name = `git rev-parse --abbrev-ref HEAD`.strip
@@ -16,7 +14,7 @@ elsif !ENV['GITHUB_TOKEN']
raise "Missing GITHUB_TOKEN env, go to https://github.com/settings/tokens and create one with 'repo' access"
end
-def get_http(path, json: true)
+def get_http(path)
url =
if path.start_with?('http')
path
@@ -31,44 +29,49 @@ def get_http(path, json: true)
password: ENV.fetch('GITHUB_TOKEN')
).execute
- if json
- JSON.parse(response.to_str)
- else
- response.to_str
- end
+ response.to_str
rescue StandardError => e
warn "Failed to perform API request #{url}: #{e} #{e.message}"
+ exit 1
+end
+
+def get_json(path)
+ JSON.parse(get_http(path))
+end
+
+def commit_message(workflow_run)
+ get_json("commits/#{workflow_run['head_sha']}?per_page=1")
+ .then { |commit_response| commit_response["commit"]["message"] }
+ .then { |message| message.split("\n", 2).first }
end
-warn "Looking for the last action in branch #{branch_name}"
+warn "Looking for the last 'Test suite' workflow run in branch #{branch_name}"
-response = get_http "actions/runs?branch=#{CGI.escape(branch_name)}"
+response = get_json "actions/runs?branch=#{CGI.escape(branch_name)}"
last_test_action =
response['workflow_runs']
.select { |entry| entry['name'] == 'Test suite' }
+ .reject { |entry| entry['status'] == 'in_progress' }
.max_by { |entry| entry['run_number'] }
raise "No action run found for branch #{branch_name}" unless last_test_action
-log_response = get_http last_test_action['logs_url'], json: false
-errors = []
-
-# rubyzip needs a file to read with general purpose bit set
-Tempfile.open('logs.zip') do |file|
- file.write log_response
- file.close
-
- zip = Zip::File.open(file)
- zip.each do |entry|
- next unless entry.file?
+warn " Commit SHA: #{last_test_action['head_sha']}"
+warn " Commit message: #{commit_message(last_test_action)}"
- log = entry.get_input_stream.read
+errors = []
+get_json(last_test_action['jobs_url'])
+ .then { |jobs_response| jobs_response['jobs'] }
+ .select { _1['conclusion'] == 'failure' }
+ .sort_by { _1['name'] }
+ .each { warn " #{_1['name']}: #{_1['conclusion']}" }
+ .each do |job|
+ log = get_http "actions/jobs/#{job['id']}/logs"
log.scan(/^\S+ rspec (\S+) #.+$/) do |match|
errors << match
end
end
-end
if errors.empty?
warn "No rspec errors found :-/"