Skip to content

Instantly share code, notes, and snippets.

@dlitz
Created October 14, 2013 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlitz/6982406 to your computer and use it in GitHub Desktop.
Save dlitz/6982406 to your computer and use it in GitHub Desktop.
diff --git a/lib/travis/github/services/fetch_config.rb b/lib/travis/github/services/fetch_config.rb
index 6d61dd7..542cd0a 100644
--- a/lib/travis/github/services/fetch_config.rb
+++ b/lib/travis/github/services/fetch_config.rb
@@ -11,7 +11,8 @@ module Travis
register :github_fetch_config
def run
- config = retrying(3) { parse(fetch) }
+ config = retrying(3) { parse(fetch(config_url)) }
+ config ||= retrying(3) { parse(fetch(fallback_config_url)) }
config || Travis.logger.warn("[request:fetch_config] Empty config for request id=#{request.id} config_url=#{config_url.inspect}")
rescue GH::Error => e
if e.info[:response_status] == 404
@@ -30,13 +31,17 @@ module Travis
request.config_url
end
+ def fallback_config_url
+ request.fallback_config_url
+ end
+
private
- def fetch
+ def fetch(url)
content = GH[config_url]['content']
- Travis.logger.warn("[request:fetch_config] Empty content for #{config_url}") if content.nil?
+ Travis.logger.warn("[request:fetch_config] Empty content for #{url}") if content.nil?
content = content.to_s.unpack('m').first
- Travis.logger.warn("[request:fetch_config] Empty unpacked content for #{config_url}, content was #{content.inspect}") if content.nil?
+ Travis.logger.warn("[request:fetch_config] Empty unpacked content for #{url}, content was #{content.inspect}") if content.nil?
nbsp = "\xC2\xA0".force_encoding("binary")
content = content.gsub(/^(#{nbsp})+/) { |match| match.gsub(nbsp, " ") }
diff --git a/lib/travis/model/request.rb b/lib/travis/model/request.rb
index 3f2756b..18ae34e 100644
--- a/lib/travis/model/request.rb
+++ b/lib/travis/model/request.rb
@@ -53,6 +53,10 @@ class Request < Travis::Model
end
def config_url
+ "https://api.github.com/repos/#{repository.slug}/contents/.travis.yml?ref=travis-ci"
+ end
+
+ def fallback_config_url
"https://api.github.com/repos/#{repository.slug}/contents/.travis.yml?ref=#{commit.commit}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment