diff options
| author | Masayuki Morita | 2017-01-03 14:58:08 +0900 |
|---|---|---|
| committer | Masayuki Morita | 2017-01-03 15:12:53 +0900 |
| commit | a4330f458a09e946ef7bac912fba63628dbf67ca (patch) | |
| tree | fcd9c894fcd61f028a64d1826839b7661ec9f70b /Library/Homebrew | |
| parent | 248beb9bf6ce0b9afc97dfc72067b6acfcb5eeb8 (diff) | |
| download | brew-a4330f458a09e946ef7bac912fba63628dbf67ca.tar.bz2 | |
Use util/github insted of open-uri in GitHubReleaseDownloadStrategy
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/download_strategy.rb | 21 | ||||
| -rw-r--r-- | Library/Homebrew/test/download_strategies_test.rb | 2 |
2 files changed, 7 insertions, 16 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 6e618f720..19af8820c 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -535,18 +535,19 @@ end # GitHubReleaseDownloadStrategy downloads tarballs from GitHub Release assets. # To use it, add ":using => GitHubReleaseDownloadStrategy" to the URL section # of your formula. This download strategy uses GitHub access tokens (in the -# environment variables GITHUB_TOKEN) to sign the request. +# environment variables HOMEBREW_GITHUB_API_TOKEN) to sign the request. # This strategy is suitable for corporate use just like S3DownloadStrategy, # because it lets you use a private GttHub repository for internal distribution. # It works with public one, but in that case simply use CurlDownloadStrategy. class GitHubReleaseDownloadStrategy < CurlDownloadStrategy - require 'open-uri' + require "utils/formatter" + require 'utils/github' def initialize(name, resource) super - @github_token = ENV["GITHUB_TOKEN"] - raise CurlDownloadStrategyError, "Environmental variable GITHUB_TOKEN is required." unless @github_token + @github_token = ENV["HOMEBREW_GITHUB_API_TOKEN"] + raise CurlDownloadStrategyError, "Environmental variable HOMEBREW_GITHUB_API_TOKEN is required." unless @github_token url_pattern = %r|https://github.com/(\S+)/(\S+)/releases/download/(\S+)/(\S+)| raise CurlDownloadStrategyError, "Invalid url pattern for GitHub Release." unless @url =~ url_pattern @@ -584,17 +585,7 @@ class GitHubReleaseDownloadStrategy < CurlDownloadStrategy end def fetch_release_metadata - begin - release_response = open(release_url, {:http_basic_authentication => [@github_token]}).read - rescue OpenURI::HTTPError => e - if e.message == '404 Not Found' - raise CurlDownloadStrategyError, "GitHub Release not found." - else - raise e - end - end - - return JSON.parse(release_response) + GitHub.open(release_url) end end diff --git a/Library/Homebrew/test/download_strategies_test.rb b/Library/Homebrew/test/download_strategies_test.rb index 1df0267af..e69bdfda2 100644 --- a/Library/Homebrew/test/download_strategies_test.rb +++ b/Library/Homebrew/test/download_strategies_test.rb @@ -64,7 +64,7 @@ end class GitHubReleaseDownloadStrategyTests < Homebrew::TestCase def setup resource = ResourceDouble.new("https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz") - ENV["GITHUB_TOKEN"] = "token" + ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" @strategy = GitHubReleaseDownloadStrategy.new("foo", resource) end |
