Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
wip

fixup
  • Loading branch information
Anviking committed Jun 10, 2021
1 parent ad90613 commit ff53675
Showing 1 changed file with 52 additions and 17 deletions.
69 changes: 52 additions & 17 deletions scripts/bors-stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ def sendGithubGraphQLQuery(qry)
end

# A parsed bors comment corresponding to a succeeding or failing build
BorsComment = Struct.new(:url, :bodyText, :body, :createdAt, :tags, :succeeded) do
BorsComment = Struct.new(:url, :bodyText, :links, :createdAt, :tags, :succeeded) do
def to_s
self.pretty
end

def pretty(showDetails = :auto)
maybeDetails = ((((not succeeded) and tags.length == 0) and showDetails == :auto) or (showDetails == true) ) ? bodyText : ""
if showDetails == "auto" then showDetails = :auto end
if showDetails == "true" then showDetails = true end
if showDetails == "false" then showDetails = false end
details = links.join("\n") + "\n" + bodyText
maybeDetails = ((((not succeeded) and tags.length == 0) and showDetails == :auto) or (showDetails == true) ) ? details : ""
header = pretty_time + " " + pretty_tags + " " + ANSI.blue + url + ANSI.clear
return (header + "\n" + maybeDetails)
end
Expand All @@ -42,7 +46,7 @@ def pretty_tags
end

def fetch_comments(target = 100, before = nil)
numberPRsToFetch = [100, target].min
numberPRsToFetch = [100, target.to_i].min
numberCommentsToFetch = 100
beforeQ = if before then ", before: \"" + before + "\"" else "" end
query = <<~END
Expand Down Expand Up @@ -70,13 +74,27 @@ def fetch_comments(target = 100, before = nil)
.filter { |x| x['author']['login'] == "iohk-bors" }
.map do |x|
tags = x['bodyText'].scan(/^#[\d\w\-]+/).to_a

# Matches on the link from e.g.
# [ci/hydra-build:required](https://hydra.iohk.io/build/6623546)
buildLinks = x['body'].scan(/^\s+\* \[[^\]]+\]\((https:\/\/[^)]+)/).map { |x| x[0] }

buildLinks.each do |l|
if l.start_with? "https://hydra.iohk.io" then
tags += ["hydra"]
elsif l.start_with? "https://buildkite" then
tags += ["buildkite"]
end
end


createdAt = DateTime.parse(x['createdAt'])
succ = x['bodyText'].include? "Build succeeded"
BorsComment.new(x['url'], x['bodyText'], x['body'], createdAt, tags, succ)
BorsComment.new(x['url'], x['bodyText'], buildLinks, createdAt, tags, succ)
end
remaining = target - numberPRsToFetch
if !res.empty? and remaining > 0 then
fetch_comments(before = cursor, target = remaining ) + res
fetch_comments(remaining, cursor) + res
else
res
end
Expand Down Expand Up @@ -139,17 +157,10 @@ def fetch_gh_ticket_titlemap
.transform_values { |x| x[0] }
end

def show_bors_failures(comments, alwaysShowDetails)
def show_bors_failures(comments, showDetails)
comments.each do |c|
# Only print the full comment if failure or if no tags
maybeDetails = (((not c.succeeded) and c.tags.length == 0) or alwaysShowDetails) ? c.bodyText : ""
#key = c.tags.first
#title = titlemap.dig key, "title"
#title = unless title.nil? then title else "" end

header = c.pretty_time + " " + c.pretty_tags + " " + ANSI.blue + c.url + ANSI.clear

puts ("\n" + header + "\n" + maybeDetails + "\n")
puts c.pretty(showDetails = showDetails)
end
end

Expand Down Expand Up @@ -208,13 +219,37 @@ def eventDate(x)
class BorsStats < Thor
desc "list", "list all failures with optional filter (e.g. list 2292)"
option :count, :type => :numeric, :required => false, :default => 100, :desc => "How many PRs to fetch"
option :details, :type => :string, :required => false, :default => :auto, :desc => "Show details (true/false/auto)"
def list(tag = nil)
comments = fetch_comments(target = options[:count])
unless tag.nil? then
show_bors_failures(comments.filter {|x| x.tags.include? ('#'+tag) }, true)
else
show_bors_failures(comments, false)
comments = comments.filter {|x| x.tags.include? ('#'+tag) }
end

comments.each do |c|
c.links.each do |l|
if l.start_with? "https://hydra.iohk.io" then
# fetch system from hydra api
# but not sure how to get the the build that actually failed, not
# just the "parent build". So a dirty workaround is to scrape the HTML response.
uri = URI(l)
# req = Net::HTTP::Get.new(uri, 'Accept' => 'application/json')
req = Net::HTTP::Get.new(uri)
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) {|http|
http.request(req)
}
#system = JSON.parse(res.body)['system']
if res.body.include? "mac-mini"
c.tags += ["mac"]
else
c.tags += ["linux"]
end
end
end
end


show_bors_failures(comments, options[:details])
tm = fetch_gh_ticket_titlemap
show_breakdown(comments,tm).each do |k,v|
t = k[:tag]
Expand Down

0 comments on commit ff53675

Please sign in to comment.