Fix rubocop style warning of download_strategy

This commit is contained in:
Masayuki Morita 2017-01-08 18:29:20 +09:00
parent 560d5bdd71
commit 12b9cb7f4c
2 changed files with 17 additions and 19 deletions

View File

@ -542,7 +542,7 @@ end
# works with public one, but in that case simply use CurlDownloadStrategy. # works with public one, but in that case simply use CurlDownloadStrategy.
class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy
require "utils/formatter" require "utils/formatter"
require 'utils/github' require "utils/github"
def initialize(name, resource) def initialize(name, resource)
super super
@ -551,12 +551,12 @@ class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy
end end
def parse_url_pattern def parse_url_pattern
url_pattern = %r|https://github.com/([^/]+)/([^/]+)/(\S+)| url_pattern = %r{https://github.com/([^/]+)/([^/]+)/(\S+)}
unless @url =~ url_pattern unless @url =~ url_pattern
raise CurlDownloadStrategyError, "Invalid url pattern for GitHub Repository." raise CurlDownloadStrategyError, "Invalid url pattern for GitHub Repository."
end end
_, @owner, @repo, @filepath = *(@url.match(url_pattern)) _, @owner, @repo, @filepath = *@url.match(url_pattern)
end end
def download_url def download_url
@ -578,7 +578,6 @@ class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy
end end
def validate_github_repository_access! def validate_github_repository_access!
begin
# Test access to the repository # Test access to the repository
GitHub.repository(@owner, @repo) GitHub.repository(@owner, @repo)
rescue GitHub::HTTPNotFoundError rescue GitHub::HTTPNotFoundError
@ -590,7 +589,6 @@ class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy
EOS EOS
raise CurlDownloadStrategyError, message raise CurlDownloadStrategyError, message
end end
end
end end
# GitHubPrivateRepositoryReleaseDownloadStrategy downloads tarballs from GitHub # GitHubPrivateRepositoryReleaseDownloadStrategy downloads tarballs from GitHub
@ -600,12 +598,12 @@ end
# environment variables HOMEBREW_GITHUB_API_TOKEN) to sign the request. # environment variables HOMEBREW_GITHUB_API_TOKEN) to sign the request.
class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDownloadStrategy class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDownloadStrategy
def parse_url_pattern def parse_url_pattern
url_pattern = %r|https://github.com/([^/]+)/([^/]+)/releases/download/([^/]+)/(\S+)| url_pattern = %r{https://github.com/([^/]+)/([^/]+)/releases/download/([^/]+)/(\S+)}
unless @url =~ url_pattern unless @url =~ url_pattern
raise CurlDownloadStrategyError, "Invalid url pattern for GitHub Release." raise CurlDownloadStrategyError, "Invalid url pattern for GitHub Release."
end end
_, @owner, @repo, @tag, @filename = *(@url.match(url_pattern)) _, @owner, @repo, @tag, @filename = *@url.match(url_pattern)
end end
def download_url def download_url
@ -615,7 +613,7 @@ class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDo
def _fetch def _fetch
# HTTP request header `Accept: application/octet-stream` is required. # HTTP request header `Accept: application/octet-stream` is required.
# Without this, the GitHub API will respond with metadata, not binary. # Without this, the GitHub API will respond with metadata, not binary.
curl download_url, "-C", downloaded_size, "-o", temporary_path, "-H", 'Accept: application/octet-stream' curl download_url, "-C", downloaded_size, "-o", temporary_path, "-H", "Accept: application/octet-stream"
end end
private private
@ -626,10 +624,10 @@ class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDo
def resolve_asset_id def resolve_asset_id
release_metadata = fetch_release_metadata release_metadata = fetch_release_metadata
assets = release_metadata["assets"].select{ |a| a["name"] == @filename } assets = release_metadata["assets"].select { |a| a["name"] == @filename }
raise CurlDownloadStrategyError, "Asset file not found." if assets.empty? raise CurlDownloadStrategyError, "Asset file not found." if assets.empty?
return assets.first["id"] assets.first["id"]
end end
def fetch_release_metadata def fetch_release_metadata

View File

@ -117,7 +117,7 @@ class GitHubPrivateRepositoryReleaseDownloadStrategyTests < Homebrew::TestCase
"id" => 456, "id" => 456,
"name" => "foo_v0.1.0_darwin_amd64.tar.gz", "name" => "foo_v0.1.0_darwin_amd64.tar.gz",
}, },
] ],
} }
@strategy.stubs(:fetch_release_metadata).returns(release_metadata) @strategy.stubs(:fetch_release_metadata).returns(release_metadata)
assert_equal 456, @strategy.send(:resolve_asset_id) assert_equal 456, @strategy.send(:resolve_asset_id)