Update GitHub API usage

This commit is contained in:
nandahkrishna 2021-02-15 21:48:21 +05:30
parent 9d8a5827a3
commit 56e0c3d9e8
No known key found for this signature in database
GPG Key ID: 067E5FCD58ADF3AA
13 changed files with 33 additions and 35 deletions

View File

@ -55,7 +55,7 @@ module Homebrew
files["00.tap.out"] = { content: tap }
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
descr = if f.core_formula?
@ -63,9 +63,9 @@ module Homebrew
else
"#{f.name} (#{f.full_name}) on #{OS_VERSION} - Homebrew build logs"
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
end
@ -108,20 +108,6 @@ module Homebrew
logs
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
args = gist_logs_args.parse

View File

@ -337,9 +337,9 @@ module Homebrew
end
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}"]
# Download the artifact as a zip file and unpack it into `dir`. This is

View File

@ -114,7 +114,7 @@ module Homebrew
rel = GitHub.get_release user, repo, tag
odebug "Existing GitHub release \"#{tag}\" found"
rel
rescue GitHub::HTTPNotFoundError
rescue GitHub::API::HTTPNotFoundError
odebug "Creating new GitHub release \"#{tag}\""
GitHub.create_or_update_release user, repo, tag
end

View File

@ -39,7 +39,7 @@ module Homebrew
begin
latest_release = GitHub.get_latest_release "Homebrew", "brew"
rescue GitHub::HTTPNotFoundError
rescue GitHub::API::HTTPNotFoundError
odie "No existing releases found!"
end
latest_version = Version.new latest_release["tag_name"]
@ -48,7 +48,7 @@ module Homebrew
one_month_ago = Date.today << 1
latest_major_minor_release = begin
GitHub.get_release "Homebrew", "brew", "#{latest_version.major_minor}.0"
rescue GitHub::HTTPNotFoundError
rescue GitHub::API::HTTPNotFoundError
nil
end
@ -89,7 +89,7 @@ module Homebrew
begin
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}!"
end

View File

@ -423,7 +423,7 @@ class BuildError < RuntimeError
def fetch_issues
GitHub.issues_for_formula(formula.name, tap: formula.tap, state: "open")
rescue GitHub::RateLimitExceededError => e
rescue GitHub::API::RateLimitExceededError => e
opoo e.message
[]
end

View File

@ -79,7 +79,7 @@ module Homebrew
@desc = metadata["description"]
@homepage = metadata["homepage"]
@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
# fault rather than the input URL.
nil

View File

@ -48,7 +48,7 @@ module Homebrew
filename: query,
extension: "rb",
)
rescue GitHub::Error => e
rescue GitHub::API::Error => e
opoo "Error searching on GitHub: #{e}\n"
nil
end

View File

@ -692,9 +692,9 @@ class Tap
else
GitHub.private_repo?(full_name)
end
rescue GitHub::HTTPNotFoundError
rescue GitHub::API::HTTPNotFoundError
true
rescue GitHub::Error
rescue GitHub::API::Error
false
end
end

View File

@ -21,7 +21,7 @@ describe Homebrew::Search do
end
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"))
.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"))
.to match(formulae: ["homebrew/foo/some-formula"], casks: ["homebrew/bar/some-cask"])

View File

@ -216,7 +216,7 @@ describe Tap do
end
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
end

View File

@ -30,6 +30,18 @@ module GitHub
search("issues", query, **qualifiers)
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)
API.open_api(url_to("repos", user, repo))
end

View File

@ -17,17 +17,17 @@ module SharedAudits
@github_repo_data["#{user}/#{repo}"] ||= GitHub.repository(user, repo)
@github_repo_data["#{user}/#{repo}"]
rescue GitHub::HTTPNotFoundError
rescue GitHub::API::HTTPNotFoundError
nil
end
def github_release_data(user, repo, tag)
id = "#{user}/#{repo}/#{tag}"
@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]
rescue GitHub::HTTPNotFoundError
rescue GitHub::API::HTTPNotFoundError
nil
end

View File

@ -29,7 +29,7 @@ module SPDX
end
def latest_tag
@latest_tag ||= GitHub.open_api(API_URL)["tag_name"]
@latest_tag ||= GitHub::API.open_api(API_URL)["tag_name"]
end
def download_latest_license_data!(to: DATA_PATH)