Class: GitHttpsable::Push::Repository
- Inherits:
-
Object
- Object
- GitHttpsable::Push::Repository
- Defined in:
- lib/git_httpsable/push/repository.rb
Instance Method Summary collapse
- #absolute_path(path) ⇒ Object
- #env_git_access_token ⇒ Object
- #env_github_access_token ⇒ Object
- #git ⇒ Object
- #host(host) ⇒ Object
-
#initialize(path, options = {}) ⇒ Repository
constructor
A new instance of Repository.
- #logger ⇒ Object
- #port ⇒ Object
- #push(remote = 'origin', branch = 'master', options = {}) ⇒ Object
- #remote_url(remote) ⇒ Object
- #scheme ⇒ Object
- #userinfo ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Repository
Returns a new instance of Repository.
4 5 6 7 |
# File 'lib/git_httpsable/push/repository.rb', line 4 def initialize(path, = {}) @path = path = { log: logger }.merge() end |
Instance Method Details
#absolute_path(path) ⇒ Object
75 76 77 |
# File 'lib/git_httpsable/push/repository.rb', line 75 def absolute_path(path) path.start_with?('/') ? path : '/' + path end |
#env_git_access_token ⇒ Object
49 50 51 |
# File 'lib/git_httpsable/push/repository.rb', line 49 def env_git_access_token ENV['GIT_SERVER_ACCESS_TOKEN'] end |
#env_github_access_token ⇒ Object
45 46 47 |
# File 'lib/git_httpsable/push/repository.rb', line 45 def env_github_access_token ENV['GITHUB_ACCESS_TOKEN'] end |
#git ⇒ Object
37 38 39 |
# File 'lib/git_httpsable/push/repository.rb', line 37 def git @git ||= ::Git.open(@path, ) end |
#host(host) ⇒ Object
67 68 69 |
# File 'lib/git_httpsable/push/repository.rb', line 67 def host(host) ENV['GIT_SERVER_HOST'] || host end |
#logger ⇒ Object
33 34 35 |
# File 'lib/git_httpsable/push/repository.rb', line 33 def logger ::GitHttpsable::Push.logger end |
#port ⇒ Object
71 72 73 |
# File 'lib/git_httpsable/push/repository.rb', line 71 def port ENV['GIT_SERVER_PORT'] || nil end |
#push(remote = 'origin', branch = 'master', options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/git_httpsable/push/repository.rb', line 9 def push(remote = 'origin', branch = 'master', = {}) logger.debug(remote: remote, branch: branch, options: ) # check current branch's upstream remote and branch? url = remote_url(remote) fail NotExistRemoteUrlError, %(no "#{remote}" url) unless url parsed = GitCloneUrl.parse(url) converted_url = \ URI::Generic.build( scheme: scheme, userinfo: userinfo, host: host(parsed.host), port: port, path: absolute_path(parsed.path) ) git.push(converted_url.to_s, branch, ) rescue StandardError => e raise e if e.is_a?(GitHttpsablePushError) exception = GitHttpsablePushError.new('(' + e.class.name + ') ' + e.) exception.set_backtrace(e.backtrace) raise exception end |
#remote_url(remote) ⇒ Object
41 42 43 |
# File 'lib/git_httpsable/push/repository.rb', line 41 def remote_url(remote) git.remote(remote) && git.remote(remote).url end |
#scheme ⇒ Object
63 64 65 |
# File 'lib/git_httpsable/push/repository.rb', line 63 def scheme ENV['GIT_SERVER_SCHEME'] || 'https' end |
#userinfo ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/git_httpsable/push/repository.rb', line 53 def userinfo if env_git_access_token env_git_access_token elsif env_github_access_token "#{env_github_access_token}:x-oauth-basic" else fail NoAuthDataError end end |