Update GitHub API usage
This commit is contained in:
parent
9d8a5827a3
commit
56e0c3d9e8
@ -55,7 +55,7 @@ module Homebrew
|
|||||||
files["00.tap.out"] = { content: tap }
|
files["00.tap.out"] = { content: tap }
|
||||||
end
|
end
|
||||||
|
|
||||||
odie "`brew gist-logs` requires HOMEBREW_GITHUB_API_TOKEN to be set!" if GitHub.api_credentials_type == :none
|
odie "`brew gist-logs` requires HOMEBREW_GITHUB_API_TOKEN to be set!" if GitHub::API.api_credentials_type == :none
|
||||||
|
|
||||||
# Description formatted to work well as page title when viewing gist
|
# Description formatted to work well as page title when viewing gist
|
||||||
descr = if f.core_formula?
|
descr = if f.core_formula?
|
||||||
@ -63,9 +63,9 @@ module Homebrew
|
|||||||
else
|
else
|
||||||
"#{f.name} (#{f.full_name}) on #{OS_VERSION} - Homebrew build logs"
|
"#{f.name} (#{f.full_name}) on #{OS_VERSION} - Homebrew build logs"
|
||||||
end
|
end
|
||||||
url = create_gist(files, descr, private: args.private?)
|
url = GitHub.create_gist(files, descr, private: args.private?)
|
||||||
|
|
||||||
url = create_issue(f.tap, "#{f.name} failed to build on #{MacOS.full_version}", url) if args.new_issue?
|
url = GitHub.create_issue(f.tap, "#{f.name} failed to build on #{MacOS.full_version}", url) if args.new_issue?
|
||||||
|
|
||||||
puts url if url
|
puts url if url
|
||||||
end
|
end
|
||||||
@ -108,20 +108,6 @@ module Homebrew
|
|||||||
logs
|
logs
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_gist(files, description, private:)
|
|
||||||
url = "https://api.github.com/gists"
|
|
||||||
data = { "public" => !private, "files" => files, "description" => description }
|
|
||||||
scopes = GitHub::CREATE_GIST_SCOPES
|
|
||||||
GitHub.open_api(url, data: data, scopes: scopes)["html_url"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_issue(repo, title, body)
|
|
||||||
url = "https://api.github.com/repos/#{repo}/issues"
|
|
||||||
data = { "title" => title, "body" => body }
|
|
||||||
scopes = GitHub::CREATE_ISSUE_FORK_OR_PR_SCOPES
|
|
||||||
GitHub.open_api(url, data: data, scopes: scopes)["html_url"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def gist_logs
|
def gist_logs
|
||||||
args = gist_logs_args.parse
|
args = gist_logs_args.parse
|
||||||
|
|
||||||
|
|||||||
@ -337,9 +337,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def download_artifact(url, dir, pr)
|
def download_artifact(url, dir, pr)
|
||||||
odie "Credentials must be set to access the Artifacts API" if GitHub.api_credentials_type == :none
|
odie "Credentials must be set to access the Artifacts API" if GitHub::API.api_credentials_type == :none
|
||||||
|
|
||||||
token = GitHub.api_credentials
|
token = GitHub::API.api_credentials
|
||||||
curl_args = ["--header", "Authorization: token #{token}"]
|
curl_args = ["--header", "Authorization: token #{token}"]
|
||||||
|
|
||||||
# Download the artifact as a zip file and unpack it into `dir`. This is
|
# Download the artifact as a zip file and unpack it into `dir`. This is
|
||||||
|
|||||||
@ -114,7 +114,7 @@ module Homebrew
|
|||||||
rel = GitHub.get_release user, repo, tag
|
rel = GitHub.get_release user, repo, tag
|
||||||
odebug "Existing GitHub release \"#{tag}\" found"
|
odebug "Existing GitHub release \"#{tag}\" found"
|
||||||
rel
|
rel
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::API::HTTPNotFoundError
|
||||||
odebug "Creating new GitHub release \"#{tag}\""
|
odebug "Creating new GitHub release \"#{tag}\""
|
||||||
GitHub.create_or_update_release user, repo, tag
|
GitHub.create_or_update_release user, repo, tag
|
||||||
end
|
end
|
||||||
|
|||||||
@ -39,7 +39,7 @@ module Homebrew
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
latest_release = GitHub.get_latest_release "Homebrew", "brew"
|
latest_release = GitHub.get_latest_release "Homebrew", "brew"
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::API::HTTPNotFoundError
|
||||||
odie "No existing releases found!"
|
odie "No existing releases found!"
|
||||||
end
|
end
|
||||||
latest_version = Version.new latest_release["tag_name"]
|
latest_version = Version.new latest_release["tag_name"]
|
||||||
@ -48,7 +48,7 @@ module Homebrew
|
|||||||
one_month_ago = Date.today << 1
|
one_month_ago = Date.today << 1
|
||||||
latest_major_minor_release = begin
|
latest_major_minor_release = begin
|
||||||
GitHub.get_release "Homebrew", "brew", "#{latest_version.major_minor}.0"
|
GitHub.get_release "Homebrew", "brew", "#{latest_version.major_minor}.0"
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::API::HTTPNotFoundError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ module Homebrew
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
release = GitHub.create_or_update_release "Homebrew", "brew", new_version, body: release_notes, draft: true
|
release = GitHub.create_or_update_release "Homebrew", "brew", new_version, body: release_notes, draft: true
|
||||||
rescue *GitHub::API_ERRORS => e
|
rescue *GitHub::API::API_ERRORS => e
|
||||||
odie "Unable to create release: #{e.message}!"
|
odie "Unable to create release: #{e.message}!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -423,7 +423,7 @@ class BuildError < RuntimeError
|
|||||||
|
|
||||||
def fetch_issues
|
def fetch_issues
|
||||||
GitHub.issues_for_formula(formula.name, tap: formula.tap, state: "open")
|
GitHub.issues_for_formula(formula.name, tap: formula.tap, state: "open")
|
||||||
rescue GitHub::RateLimitExceededError => e
|
rescue GitHub::API::RateLimitExceededError => e
|
||||||
opoo e.message
|
opoo e.message
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|||||||
@ -79,7 +79,7 @@ module Homebrew
|
|||||||
@desc = metadata["description"]
|
@desc = metadata["description"]
|
||||||
@homepage = metadata["homepage"]
|
@homepage = metadata["homepage"]
|
||||||
@license = metadata["license"]["spdx_id"] if metadata["license"]
|
@license = metadata["license"]["spdx_id"] if metadata["license"]
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::API::HTTPNotFoundError
|
||||||
# If there was no repository found assume the network connection is at
|
# If there was no repository found assume the network connection is at
|
||||||
# fault rather than the input URL.
|
# fault rather than the input URL.
|
||||||
nil
|
nil
|
||||||
|
|||||||
@ -48,7 +48,7 @@ module Homebrew
|
|||||||
filename: query,
|
filename: query,
|
||||||
extension: "rb",
|
extension: "rb",
|
||||||
)
|
)
|
||||||
rescue GitHub::Error => e
|
rescue GitHub::API::Error => e
|
||||||
opoo "Error searching on GitHub: #{e}\n"
|
opoo "Error searching on GitHub: #{e}\n"
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|||||||
@ -692,9 +692,9 @@ class Tap
|
|||||||
else
|
else
|
||||||
GitHub.private_repo?(full_name)
|
GitHub.private_repo?(full_name)
|
||||||
end
|
end
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::API::HTTPNotFoundError
|
||||||
true
|
true
|
||||||
rescue GitHub::Error
|
rescue GitHub::API::Error
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,7 +21,7 @@ describe Homebrew::Search do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "does not raise if the network fails" do
|
it "does not raise if the network fails" do
|
||||||
allow(GitHub).to receive(:open_api).and_raise(GitHub::Error)
|
allow(GitHub::API).to receive(:open_api).and_raise(GitHub::API::Error)
|
||||||
|
|
||||||
expect(mod.search_taps("some-formula"))
|
expect(mod.search_taps("some-formula"))
|
||||||
.to match(formulae: [], casks: [])
|
.to match(formulae: [], casks: [])
|
||||||
@ -45,7 +45,7 @@ describe Homebrew::Search do
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
allow(GitHub).to receive(:open_api).and_yield(json_response)
|
allow(GitHub::API).to receive(:open_api).and_yield(json_response)
|
||||||
|
|
||||||
expect(mod.search_taps("some-formula"))
|
expect(mod.search_taps("some-formula"))
|
||||||
.to match(formulae: ["homebrew/foo/some-formula"], casks: ["homebrew/bar/some-cask"])
|
.to match(formulae: ["homebrew/foo/some-formula"], casks: ["homebrew/bar/some-cask"])
|
||||||
|
|||||||
@ -216,7 +216,7 @@ describe Tap do
|
|||||||
end
|
end
|
||||||
|
|
||||||
specify "#private?" do
|
specify "#private?" do
|
||||||
skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub.api_credentials
|
skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub::API.api_credentials
|
||||||
expect(homebrew_foo_tap).to be_private
|
expect(homebrew_foo_tap).to be_private
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,18 @@ module GitHub
|
|||||||
search("issues", query, **qualifiers)
|
search("issues", query, **qualifiers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_gist(files, description, private:)
|
||||||
|
url = "https://api.github.com/gists"
|
||||||
|
data = { "public" => !private, "files" => files, "description" => description }
|
||||||
|
API.open_api(url, data: data, scopes: CREATE_GIST_SCOPES)["html_url"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_issue(repo, title, body)
|
||||||
|
url = "https://api.github.com/repos/#{repo}/issues"
|
||||||
|
data = { "title" => title, "body" => body }
|
||||||
|
API.open_api(url, data: data, scopes: CREATE_ISSUE_FORK_OR_PR_SCOPES)["html_url"]
|
||||||
|
end
|
||||||
|
|
||||||
def repository(user, repo)
|
def repository(user, repo)
|
||||||
API.open_api(url_to("repos", user, repo))
|
API.open_api(url_to("repos", user, repo))
|
||||||
end
|
end
|
||||||
|
|||||||
@ -17,17 +17,17 @@ module SharedAudits
|
|||||||
@github_repo_data["#{user}/#{repo}"] ||= GitHub.repository(user, repo)
|
@github_repo_data["#{user}/#{repo}"] ||= GitHub.repository(user, repo)
|
||||||
|
|
||||||
@github_repo_data["#{user}/#{repo}"]
|
@github_repo_data["#{user}/#{repo}"]
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::API::HTTPNotFoundError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_release_data(user, repo, tag)
|
def github_release_data(user, repo, tag)
|
||||||
id = "#{user}/#{repo}/#{tag}"
|
id = "#{user}/#{repo}/#{tag}"
|
||||||
@github_release_data ||= {}
|
@github_release_data ||= {}
|
||||||
@github_release_data[id] ||= GitHub.open_api("#{GitHub::API_URL}/repos/#{user}/#{repo}/releases/tags/#{tag}")
|
@github_release_data[id] ||= GitHub::API.open_api("#{GitHub::API_URL}/repos/#{user}/#{repo}/releases/tags/#{tag}")
|
||||||
|
|
||||||
@github_release_data[id]
|
@github_release_data[id]
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::API::HTTPNotFoundError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ module SPDX
|
|||||||
end
|
end
|
||||||
|
|
||||||
def latest_tag
|
def latest_tag
|
||||||
@latest_tag ||= GitHub.open_api(API_URL)["tag_name"]
|
@latest_tag ||= GitHub::API.open_api(API_URL)["tag_name"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_latest_license_data!(to: DATA_PATH)
|
def download_latest_license_data!(to: DATA_PATH)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user