Skip to content

Commit

Permalink
Make script/github_pr_error extract run_id from job url
Browse files Browse the repository at this point in the history
Instead of `script/github_pr_errors -r 6073044922`, you can now use
`script/github_pr_errors https://github.com/opf/openproject/actions/runs/6073044922/job/16474191600`.
  • Loading branch information
cbliard committed Sep 5, 2023
1 parent d3b4ec0 commit 329cb85
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions script/github_pr_errors
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ class Options
}.freeze

BANNER = <<~BANNER.freeze
Usage: #{$0} [options]
Usage: #{$0} [options] [url]
Fetches rspec failures from last completed GitHub actions on current
branch, and outputs them on standard output, one by line.
If given an url, it will fetch the failures from the given url instead of
the tip of the current branch.
Information is printed on standard error to preserve standard output.
Use this script with xargs to run failing specs locally:
Expand All @@ -51,7 +54,11 @@ class Options

class << self
def options
@options ||= parse_options
return @options if defined?(@options)

@options = DEFAULTS.dup
parse_options!
@options
end

def method_missing(name, *)
Expand All @@ -66,8 +73,13 @@ class Options
DEFAULTS.key?(name) || super
end

def parse_options
options = DEFAULTS.dup
def parse_options!
options.merge!(parse_args)
options.merge!(parse_url(ARGV.first)) if ARGV.any?
end

def parse_args
options = {}
opt_parser = OptionParser.new do |parser|
parser.banner = BANNER

Expand Down Expand Up @@ -100,13 +112,25 @@ class Options
end

parser.on("-v", "--verbose",
"Print more information, mostly useful for debugging") do |value|
"Print more information, mostly useful for debugging") do |_value|
options[:verbose] = true
end
end
opt_parser.parse!
options
end

def parse_url(url)
case url
when %r{^https://github.com/opf/openproject/actions/runs/(\d+)(?:/job/\d+)?$}
run_id = $1.to_i
say_verbose("Extracted run id #{run_id} from #{url}")
{ run_id: }
else
say_verbose("Unrecognized url #{url}")
{}
end
end
end
end

Expand Down

0 comments on commit 329cb85

Please sign in to comment.