lib/danger/request_sources/github/github.rb in danger-4.3.2 vs lib/danger/request_sources/github/github.rb in danger-4.3.3
- old
+ new
@@ -414,12 +414,22 @@
rescue
nil
end
# @return [String] A URL to the specific file, ready to be downloaded
- def file_url(organisation: nil, repository: nil, branch: "master", path: nil)
+ def file_url(organisation: nil, repository: nil, branch: nil, path: nil)
organisation ||= self.organisation
- "https://raw.githubusercontent.com/#{organisation}/#{repository}/#{branch}/#{path}"
+
+ return @download_url unless @download_url.nil?
+ begin
+ # Retrieve the download URL (default branch on nil param)
+ contents = client.contents("#{organisation}/#{repository}", path: path, ref: branch)
+ @download_url = contents["download_url"]
+ rescue Octokit::ClientError
+ # Fallback to github.com
+ branch ||= "master"
+ @download_url = "https://raw.githubusercontent.com/#{organisation}/#{repository}/#{branch}/#{path}"
+ end
end
end
end
end