Merge pull request #14112 from hyuraku/move-two-methods-to-utils/github
move two methods from download_strategy to utils/github
This commit is contained in:
commit
68b944a94f
@ -12,6 +12,7 @@ require "mechanize/version"
|
|||||||
require "mechanize/http/content_disposition_parser"
|
require "mechanize/http/content_disposition_parser"
|
||||||
|
|
||||||
require "utils/curl"
|
require "utils/curl"
|
||||||
|
require "utils/github"
|
||||||
|
|
||||||
require "github_packages"
|
require "github_packages"
|
||||||
|
|
||||||
@ -1069,43 +1070,13 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
|
|||||||
@repo = repo
|
@repo = repo
|
||||||
end
|
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)
|
def commit_outdated?(commit)
|
||||||
@last_commit ||= github_last_commit
|
@last_commit ||= GitHub.last_commit(@user, @repo, @ref)
|
||||||
if @last_commit
|
if @last_commit
|
||||||
return true unless commit
|
return true unless commit
|
||||||
return true unless @last_commit.start_with?(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
|
true
|
||||||
else
|
else
|
||||||
version.update_commit(commit)
|
version.update_commit(commit)
|
||||||
|
|||||||
@ -666,4 +666,37 @@ module GitHub
|
|||||||
pr_data = API.open_rest(url_to("repos", user, repo, "pulls", pr))
|
pr_data = API.open_rest(url_to("repos", user, repo, "pulls", pr))
|
||||||
pr_data["labels"].map { |label| label["name"] }
|
pr_data["labels"].map { |label| label["name"] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_commit(user, repo, ref)
|
||||||
|
return if Homebrew::EnvConfig.no_github_api?
|
||||||
|
|
||||||
|
output, _, status = curl_output(
|
||||||
|
"--silent", "--head", "--location",
|
||||||
|
"--header", "Accept: application/vnd.github.sha",
|
||||||
|
url_to("repos", user, repo, "commits", ref).to_s
|
||||||
|
)
|
||||||
|
|
||||||
|
return unless status.success?
|
||||||
|
|
||||||
|
commit = output[/^ETag: "(\h+)"/, 1]
|
||||||
|
return if commit.blank?
|
||||||
|
|
||||||
|
version.update_commit(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",
|
||||||
|
"--header", "Accept: application/vnd.github.sha",
|
||||||
|
url_to("repos", user, repo, "commits", commit).to_s
|
||||||
|
)
|
||||||
|
|
||||||
|
return true unless status.success?
|
||||||
|
return true if output.blank?
|
||||||
|
|
||||||
|
output[/^Status: (200)/, 1] != "200"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
require "utils/shell"
|
require "utils/shell"
|
||||||
|
require "utils/formatter"
|
||||||
|
|
||||||
module GitHub
|
module GitHub
|
||||||
API_URL = "https://api.github.com"
|
API_URL = "https://api.github.com"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user