Created
July 10, 2015 04:23
-
-
Save paulschreiber/c579bf31b16511ea9067 to your computer and use it in GitHub Desktop.
WordPress plugin updater
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
#!/usr/bin/env ruby | |
require "FileUtils" | |
require "httparty" | |
require "tmpdir" | |
def update(slug) | |
url = "https://api.wordpress.org/plugins/info/1.0/#{slug}.json?fields=-compatibility,-sections,-tags,-ratings,-short_description" | |
response = HTTParty.get(url, {request: :json}) | |
unless response["version"] | |
puts "Could not find data for #{slug}" | |
return | |
end | |
version = response["version"] | |
download_url = response["download_link"] | |
zipfile = Dir.tmpdir + "/" + download_url.split("/")[-1] | |
FileUtils.rm_rf(slug) | |
File.open(zipfile, "wb"){|f| f.write HTTParty.get(download_url).parsed_response} | |
`unzip -qq #{zipfile}` | |
`git add -A` | |
`git commit -am "update #{slug} to #{version}"` | |
end | |
Dir.chdir("plugins") | |
Dir["*"].each do |plugin| | |
next if plugin[-4..-1] == ".php" | |
puts "Updating #{plugin}..." | |
update(File.basename(plugin)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment