From 297139f8f4ac33fb7909dcff7956ee65f2d30a63 Mon Sep 17 00:00:00 2001 From: David Yip Date: Thu, 14 Jun 2012 15:58:47 -0500 Subject: [PATCH 1/4] Switch to Github API v3. (v2 was turned off on 6/1/2012.) --- lib/chef/knife/cookbook_github_install.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/chef/knife/cookbook_github_install.rb b/lib/chef/knife/cookbook_github_install.rb index ca3ecbd..8776f01 100644 --- a/lib/chef/knife/cookbook_github_install.rb +++ b/lib/chef/knife/cookbook_github_install.rb @@ -141,7 +141,10 @@ 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 = noauth_rest.get_rest("https://api.github.com/repos/#{@github_user}/#{@github_repo}/git/refs/heads/#{github_branch}") + data['object']['sha'] + end end def github_branch From b2cc08628e179c2ebcdcd37b8180e272f647ed98 Mon Sep 17 00:00:00 2001 From: Tim Dettrick Date: Mon, 6 Aug 2012 13:58:11 +1000 Subject: [PATCH 2/4] Handling tag refs. --- lib/chef/knife/cookbook_github_install.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/chef/knife/cookbook_github_install.rb b/lib/chef/knife/cookbook_github_install.rb index 8776f01..7bbc0f7 100644 --- a/lib/chef/knife/cookbook_github_install.rb +++ b/lib/chef/knife/cookbook_github_install.rb @@ -141,10 +141,20 @@ def github_uri end def sha + data = nil @sha ||= begin - data = noauth_rest.get_rest("https://api.github.com/repos/#{@github_user}/#{@github_repo}/git/refs/heads/#{github_branch}") - data['object']['sha'] - end + 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} amoung #{ref_type}.") + false + end + end + data['object']['sha'] + end end def github_branch From ee96f8b8e9d846a8015a1848540e1e1b6e06a5ba Mon Sep 17 00:00:00 2001 From: Tim Dettrick Date: Mon, 6 Aug 2012 16:30:19 +1000 Subject: [PATCH 3/4] Fixing whitespace formatting. --- lib/chef/knife/cookbook_github_install.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/chef/knife/cookbook_github_install.rb b/lib/chef/knife/cookbook_github_install.rb index 7bbc0f7..6c9b72d 100644 --- a/lib/chef/knife/cookbook_github_install.rb +++ b/lib/chef/knife/cookbook_github_install.rb @@ -141,10 +141,10 @@ def github_uri end def sha - data = nil @sha ||= begin - raise "Unable to find SHA checksum" unless ['heads','tags'].any? do |ref_type| - 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 From 73a950bfe9fcc1f5ae571c93ebfb426b0a8cdd04 Mon Sep 17 00:00:00 2001 From: Tim Dettrick Date: Thu, 9 Aug 2012 08:54:30 +1000 Subject: [PATCH 4/4] Correcting spelling. --- lib/chef/knife/cookbook_github_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/knife/cookbook_github_install.rb b/lib/chef/knife/cookbook_github_install.rb index 6c9b72d..dab16fb 100644 --- a/lib/chef/knife/cookbook_github_install.rb +++ b/lib/chef/knife/cookbook_github_install.rb @@ -149,7 +149,7 @@ def sha ui.info("Found #{github_branch} amoung #{ref_type}.") true rescue - ui.info("Unable to find #{github_branch} amoung #{ref_type}.") + ui.info("Unable to find #{github_branch} among #{ref_type}.") false end end