Skip to content

Commit

Permalink
WIP: start converting to ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Jun 10, 2021
1 parent a7f6afa commit ce37d32
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
69 changes: 69 additions & 0 deletions scripts/bors-stats.rb
@@ -0,0 +1,69 @@
#!/usr/bin/env ruby
#
require 'net/http'
require 'uri'
require 'json'
require 'date'
require 'ansi'

def sendGithubGraphQLQuery(qry)
githubApiToken = ENV.fetch("GITHUB_API_TOKEN")
header = { 'Authorization': 'bearer ' + githubApiToken }
url = "https://api.github.com/graphql"
uri = URI.parse(url)
data = {query: qry}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = data.to_json
return JSON.parse(http.request(request).body)
end

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

def pretty
color = (succeeded ? ANSI.green : ANSI.red)
return color + createdAt.strftime("%d %b %H:%M") + ANSI.clear + "\n" + bodyText
end
end

def fetch_comments
numberPRsToFetch = 10
numberCommentsToFetch = 100
query = <<~END
query {
repository(name: "cardano-wallet", owner: "input-output-hk") {
pullRequests(last: #{numberPRsToFetch}) { edges { node {
comments(first: #{numberCommentsToFetch}) { edges { node {
bodyText,
createdAt,
url,
author {
login
}
}}}
}}}
}
}
END
response = sendGithubGraphQLQuery(query)
return response['data']['repository']['pullRequests']['edges']
.map { |x| x['node']['comments']['edges']}
.flatten
.map { |x| x['node']}
.filter { |x| x['author']['login'] == "iohk-bors" }
.map do |x|
BorsComment.new( x['url'] , x['bodyText'], DateTime.parse(x['createdAt']), (x['bodyText'].include? "Build succeeded"))
end
end

objs = fetch_comments
for obj in objs do
puts ""
puts obj
puts ""
end
3 changes: 3 additions & 0 deletions scripts/bors-stats.sh
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

require 'open-uri'
require 'JSON'

# Script for analysing recent CI failures.

# TODO: Add option to output raw JSON.
Expand Down

0 comments on commit ce37d32

Please sign in to comment.