diff options
| author | Mike McQuaid | 2017-06-19 15:46:48 +0100 |
|---|---|---|
| committer | GitHub | 2017-06-19 15:46:48 +0100 |
| commit | cd7e3cd39d4fd48cedf0963c1660fe9a70544ad5 (patch) | |
| tree | a06a73a998def9c6e91b2c82a408e9cb9e651f9f | |
| parent | b05545a3bf5e22bcf845d0c2f58cae745431c98c (diff) | |
| parent | c2899b65591c2a966ccfa87f0cdd47dac8fd0781 (diff) | |
| download | brew-cd7e3cd39d4fd48cedf0963c1660fe9a70544ad5.tar.bz2 | |
Merge pull request #2778 from jasonkarns/tap-full-name
refactor: DRY up redundant formulations of {#user}/homebrew-{#repo}
| -rw-r--r-- | Library/Homebrew/tap.rb | 16 | ||||
| -rw-r--r-- | Library/Homebrew/utils/github.rb | 4 |
2 files changed, 13 insertions, 7 deletions
diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 0aabce6c3..7990acc5d 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -64,6 +64,11 @@ class Tap # 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 @@ -73,7 +78,8 @@ class Tap @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 @@ -104,7 +110,7 @@ class Tap # 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. @@ -140,7 +146,7 @@ class Tap # 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 @@ -263,7 +269,7 @@ class Tap 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 @@ -513,7 +519,7 @@ class Tap if custom_remote? true else - GitHub.private_repo?(user, "homebrew-#{repo}") + GitHub.private_repo?(full_name) end rescue GitHub::HTTPNotFoundError true diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 5ba381529..1a781cee6 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -291,8 +291,8 @@ module GitHub 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 |
