diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 3ce7303d47..c10858a353 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -12,6 +12,7 @@ require "mechanize/version" require "mechanize/http/content_disposition_parser" require "utils/curl" +require "utils/github" require "github_packages" @@ -1069,43 +1070,13 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy @repo = repo end - def github_last_commit - # TODO: move to Utils::GitHub - return if Homebrew::EnvConfig.no_github_api? - - output, _, status = curl_output( - "--silent", "--head", "--location", - "-H", "Accept: application/vnd.github.sha", - "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}" - ) - - return unless status.success? - - commit = output[/^ETag: "(\h+)"/, 1] - version.update_commit(commit) if commit - commit - end - - def multiple_short_commits_exist?(commit) - # TODO: move to Utils::GitHub - return if Homebrew::EnvConfig.no_github_api? - - output, _, status = curl_output( - "--silent", "--head", "--location", - "-H", "Accept: application/vnd.github.sha", - "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}" - ) - - !(status.success? && output && output[/^Status: (200)/, 1] == "200") - end - def commit_outdated?(commit) - @last_commit ||= github_last_commit + @last_commit ||= GitHub.last_commit(@user, @repo, @ref) if @last_commit return true unless commit return true unless @last_commit.start_with?(commit) - if multiple_short_commits_exist?(commit) + if GitHub.multiple_short_commits_exist?(@user, @repo, commit) true else version.update_commit(commit) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 0d7472784b..1769f1cb43 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -666,4 +666,32 @@ module GitHub pr_data = API.open_rest(url_to("repos", user, repo, "pulls", pr)) pr_data["labels"].map { |label| label["name"] } end + + def last_commit(user, repo, ref) + return if Homebrew::EnvConfig.no_github_api? + + output, _, status = curl_output( + "--silent", "--head", "--location", + "-H", "Accept: application/vnd.github.sha", + "https://api.github.com/repos/#{user}/#{repo}/commits/#{ref}" + ) + + return unless status.success? + + commit = output[/^ETag: "(\h+)"/, 1] + version.update_commit(commit) if commit + commit + end + + def multiple_short_commits_exist?(user, repo, commit) + return if Homebrew::EnvConfig.no_github_api? + + output, _, status = curl_output( + "--silent", "--head", "--location", + "-H", "Accept: application/vnd.github.sha", + "https://api.github.com/repos/#{user}/#{repo}/commits/#{commit}" + ) + + !(status.success? && output && output[/^Status: (200)/, 1] == "200") + end end