Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: DRY up redundant formulations of {#user}/homebrew-{#repo} #2778

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def self.from_path(path)
# e.g. `user/repo`
attr_reader :name

# The full name of this {Tap}, including the `homebrew-` prefix.
# It combines {#user} and 'homebrew-'-prefixed {#repo} with a slash.
# e.g. `user/homebrew-repo`
attr_reader :full_name

# The local path to this {Tap}.
# e.g. `/usr/local/Library/Taps/user/homebrew-repo`
attr_reader :path
Expand All @@ -73,7 +78,8 @@ def initialize(user, repo)
@user = user
@repo = repo
@name = "#{@user}/#{@repo}".downcase
@path = TAP_DIRECTORY/"#{@user}/homebrew-#{@repo}".downcase
@full_name = "#{@user}/homebrew-#{@repo}"
@path = TAP_DIRECTORY/@full_name.downcase
@path.extend(GitRepositoryExtension)
end

Expand Down Expand Up @@ -104,7 +110,7 @@ def remote

# The default remote path to this {Tap}.
def default_remote
"https://github.com/#{user}/homebrew-#{repo}"
"https://github.com/#{full_name}"
end

# True if this {Tap} is a git repository.
Expand Down Expand Up @@ -140,7 +146,7 @@ def git_last_commit_date
# e.g. `https://github.com/user/homebrew-repo/issues`
def issues_url
return unless official? || !custom_remote?
"https://github.com/#{user}/homebrew-#{repo}/issues"
"#{default_remote}/issues"
end

def to_s
Expand Down Expand Up @@ -263,7 +269,7 @@ def install(options = {})
credentials each time you update, you can use git HTTP credential
caching or issue the following command:
cd #{path}
git remote set-url origin git@github.com:#{user}/homebrew-#{repo}.git
git remote set-url origin git@github.com:#{full_name}.git
EOS
end

Expand Down Expand Up @@ -513,7 +519,7 @@ def read_or_set_private_config
if custom_remote?
true
else
GitHub.private_repo?(user, "homebrew-#{repo}")
GitHub.private_repo?(full_name)
end
rescue GitHub::HTTPNotFoundError
true
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/utils/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ def print_pull_requests_matching(query)
prs.each { |i| puts "#{i["title"]} (#{i["html_url"]})" }
end

def private_repo?(user, repo)
uri = URI.parse("#{API_URL}/repos/#{user}/#{repo}")
def private_repo?(full_name)
uri = URI.parse("#{API_URL}/repos/#{full_name}")
open(uri) { |json| json["private"] }
end
end