Skip to content

Instantly share code, notes, and snippets.

@blasterpal
Created April 24, 2018 17:10
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 blasterpal/0f515165983b711845e09c2399481246 to your computer and use it in GitHub Desktop.
Save blasterpal/0f515165983b711845e09c2399481246 to your computer and use it in GitHub Desktop.
Ruby script to parse GH audit download
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