Skip to content

Instantly share code, notes, and snippets.

@philwhln
Last active September 26, 2018 21:15
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 philwhln/9b3f948e64507734b2b5 to your computer and use it in GitHub Desktop.
Save philwhln/9b3f948e64507734b2b5 to your computer and use it in GitHub Desktop.
update_gists.rb
require 'octokit'
access_token = ENV['TOKEN']
# Provide authentication credentials
client = Octokit::Client.new(:access_token => access_token)
user = client.user
[
'/Users/phillipwhelan/.config/fish/config.fish',
'/Users/phillipwhelan/update_gists.rb'
].each do |filepath|
filename = File.basename(filepath)
gist = client.gists.find do |gist|
gist[:files][filename.to_sym]
end
content = IO.read(filepath)
if gist
$stderr.puts "Updating gist #{gist.id} #{filename}"
client.edit_gist(gist.id, { :files => { filename.to_sym => { :content => content } } })
else
$stderr.puts "Creating gist #{filename}"
client.create_gist({ :description => filename, :files => { filename.to_sym => { :content => content } }, :public => true })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment