move two methods from download_storategy to utils/github
This commit is contained in:
parent
7c55ef857b
commit
3f3a0b5469
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user