Skip to content

Commit

Permalink
Merge #2718
Browse files Browse the repository at this point in the history
2718: scripts/bors-stats.rb: fix --force-refresh r=Anviking a=Anviking

# Issue Number

ADP-970


# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] Fix ` ./scripts/bors-stats.rb list --fetch-system`


# Comments

<!-- Additional comments or screenshots to attach if any -->

<!--
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
 ✓ Finally, in the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages.
-->


Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
  • Loading branch information
iohk-bors[bot] and Anviking committed Jun 17, 2021
2 parents 89d0a33 + 01f1834 commit e35fc2c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions scripts/bors-stats.rb
Expand Up @@ -57,6 +57,8 @@ class BorsStats < Thor
class_option :annotate, :type => :array, :required => false, :desc => "Convert matches in comments into tags"
class_option :after, :type => :string, :required => false, :desc => "Only show failures after this date"
class_option :before, :type => :string, :required => false, :desc => "Only show failures before this date"
class_option :group, :type => :array, :required => false, :desc => "Group all given tags into the first given tag.",
:long_desc => "`--group #1 #2 #3` will replace #2 and #3 with #1."

desc "list", "list all failures"
def list()
Expand All @@ -66,7 +68,7 @@ def list()
puts c.pretty(showDetails = options[:details])
end

tm = fetch_gh_ticket_titlemap
tm = fetch_gh_ticket_titlemap options
nTot = comments[:filtered].count
nExcluded = comments[:unfiltered].length - nTot
nSucc = comments[:filtered].filter { |x| x.succeeded }.length
Expand Down Expand Up @@ -125,16 +127,16 @@ def sendGithubGraphQLQuery(qry, force_refetch = false)
# aggregate build, to use the json response, so a dirty workaround is
# to scrape the HTML.
#
def fetch_system_from_build_link(link, force_refetch: false)
def fetch_system_from_build_link(link)
if link.start_with? "https://hydra.iohk.io" then
res = hydra_fetch(url: link, force_refetch: force_refetch)
res = hydra_fetch(url: link)
return (res.include? "mac-mini") ? "mac" : "linux"
end
end

def try_fetch_system(comment, force_refetch=false)
def try_fetch_system(comment)
comment.links.each do |l|
os = fetch_system_from_build_link(l, force_refetch)
os = fetch_system_from_build_link(l)
if os then comment.tags += [os] end
end
end
Expand Down Expand Up @@ -241,9 +243,10 @@ def pretty_time

def fetch_merged_prs(target, before = nil)
numberPRsToFetch = [100, target.to_i].min
beforeQ = if before then ", before: \"" + before + "\"" else "" end
query = <<~END
query { repository(name: "cardano-wallet", owner: "input-output-hk") {
pullRequests(last: #{numberPRsToFetch}, states: MERGED) { edges { cursor, node {
pullRequests(last: #{numberPRsToFetch} #{beforeQ}, states: MERGED) { edges { cursor, node {
number,
mergedAt,
title,
Expand Down Expand Up @@ -276,7 +279,7 @@ def fetch_merged_prs(target, before = nil)
# === Example return value
#
# {2083=>[{"number"=>2083, "url"=>"https://github.com/input-output-hk/cardano-wallet/issues/2083", "title"=>"Windows integration" }
def fetch_gh_ticket_titlemap
def fetch_gh_ticket_titlemap(options)
query = <<~END
query { repository(name: "cardano-wallet", owner: "input-output-hk") {
issues(labels: ["Test failure"], last: 100) { edges { node {
Expand All @@ -286,7 +289,7 @@ def fetch_gh_ticket_titlemap
}}}
}}
END
return sendGithubGraphQLQuery(query)['data']['repository']['issues']['edges']
return sendGithubGraphQLQuery(query, force_refetch: options["force_refetch"])['data']['repository']['issues']['edges']
.map { |x| x['node'] }
.group_by { |x| "#" + x['number'].to_s }
.transform_values { |x| x[0] }
Expand Down Expand Up @@ -357,7 +360,7 @@ def fetch_comments_with_options(options)

if options["fetch-system"] then
comments.each do |c|
try_fetch_system(c, options["force-refetch"]) unless c.succeeded
try_fetch_system(c) unless c.succeeded
end
end

Expand Down Expand Up @@ -394,6 +397,16 @@ def fetch_comments_with_options(options)
end
end

if options[:group] and options[:group].length >= 2 then
head, *tail = options[:group]
comments.each do |c|
new_tags = c.tags - tail
if new_tags != c.tags then
c.tags = new_tags + [head]
end
end
end

filteredComments = comments.filter { |x| include_worthy_comment x }
return { :unfiltered => comments, :filtered => filteredComments }
end
Expand Down

0 comments on commit e35fc2c

Please sign in to comment.