]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
Bump cookstyle from 6.20.1 to 6.20.2
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require "chef/mixin/shell_out"
2
3 require "addressable"
4 require "httpclient"
5 require "php_serialize"
6
7 class Chef
8   module Wordpress
9     extend Chef::Mixin::ShellOut
10
11     @api_responses = {}
12     @svn_responses = {}
13
14     class << self
15       def current_version
16         core_version_check["offers"].first["current"]
17       end
18
19       def current_plugin_version(name)
20         if svn_cat("https://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/
21           Regexp.last_match[1]
22         else
23           "trunk"
24         end
25       end
26
27       private
28
29       def core_version_check
30         api_get("https://api.wordpress.org/core/version-check/1.6")
31       end
32
33       def api_get(url)
34         @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url))
35       end
36
37       def svn_cat(url)
38         unless @svn_responses[url]
39           result = shell_out!("svn", "cat", url)
40
41           @svn_responses[url] = result.stdout.force_encoding("UTF-8")
42         end
43
44         @svn_responses[url]
45       end
46     end
47   end
48 end