diff --git a/lib/chef/knife/cookbook_github_install.rb b/lib/chef/knife/cookbook_github_install.rb index ca3ecbd..dab16fb 100644 --- a/lib/chef/knife/cookbook_github_install.rb +++ b/lib/chef/knife/cookbook_github_install.rb @@ -141,7 +141,20 @@ def github_uri end def sha - @sha ||= noauth_rest.get_rest("http://github.com/api/v2/json/repos/show/#{@github_user}/#{@github_repo}/branches")['branches'][github_branch] + @sha ||= begin + data = nil + raise "Unable to find SHA checksum" unless ['heads','tags'].any? do |ref_type| + begin + data = noauth_rest.get_rest("https://api.github.com/repos/#{@github_user}/#{@github_repo}/git/refs/#{ref_type}/#{github_branch}") + ui.info("Found #{github_branch} amoung #{ref_type}.") + true + rescue + ui.info("Unable to find #{github_branch} among #{ref_type}.") + false + end + end + data['object']['sha'] + end end def github_branch