Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created July 24, 2021 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xaviershay/1f9b0c54b65ee45bea86f07475a01e5a to your computer and use it in GitHub Desktop.
Save xaviershay/1f9b0c54b65ee45bea86f07475a01e5a to your computer and use it in GitHub Desktop.
Script to find issues referenced in a repo and check whether they're fixed or not
#!/usr/bin/env ruby
require 'tmpdir'
require 'net/http'
require 'openssl'
require 'uri'
require 'json'
require 'date'
def file_cache(key)
key = ($0 + key.to_s).gsub(/[^a-z0-9]/i, "-")
path = File.join(Dir.tmpdir, key)
begin
last_modified = File.mtime(path).to_date
if last_modified == Date.today
Marshal.load(File.read(path))
else
raise "File needs update"
end
rescue
ret = yield
File.write(path, Marshal.dump(ret))
ret
end
end
issues = `grep "FIX: " -R app spec config lib Gemfile* README*`.lines
issues = issues.map do |line|
file = line.split(':')[0]
issue = line.match(%r{FIX: https://github.com(.*)})[1]
[file, issue]
end
widths = issues.transpose.map {|x| x.map(&:length).max }
fixed = issues.any? do |file, issue|
url = URI("https://api.github.com/repos" + issue)
response = file_cache(url) do
Net::HTTP.get_response(url)
end
response_body = JSON.parse(response.body)
if response_body['state']
puts "%-#{widths[0]}s\t%-#{widths[1]}s\t%s\t%s" % [
file,
issue,
response_body['state'],
DateTime.parse(response_body['updated_at'])
.strftime("%Y-%m-%d")
]
response_body['state'] != "open"
else
puts "There was an error connecting to Github for #{issue}:" \
"\n\t#{response_body['message']}\n"
false
end
end
exit fixed ? 1 : 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment