Created
April 24, 2018 17:10
-
-
Save blasterpal/0f515165983b711845e09c2399481246 to your computer and use it in GitHub Desktop.
Ruby script to parse GH audit download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'pry' | |
require 'active_support' | |
require 'date' | |
require 'csv' | |
class GHAudit | |
def initialize | |
@file = File.open('./gh_audit.json','r') | |
@json = JSON.load(@file) | |
@org_add_remove_events = @json.select{|r| r["action"] == 'org.remove_member' || r["action"] == 'org.add_member' } | |
@formatted_add_remove = @org_add_remove_events.map do |r| | |
r["created_at"] = DateTime.strptime(r["created_at"].to_s,'%Q').rfc2822 | |
r | |
end | |
CSV.open("gh_add_remove_events.csv", "w") do |csv| #open new file for write | |
@formatted_add_remove.each do |record| | |
csv << record.values | |
end | |
end | |
end | |
end | |
puts "starting..." | |
@audit = GHAudit.new | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment