Last active
September 26, 2018 21:15
-
-
Save philwhln/9b3f948e64507734b2b5 to your computer and use it in GitHub Desktop.
update_gists.rb
This file contains 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 '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