Class: Hub::Context::GithubProject

Inherits:
Struct
  • Object
show all
Defined in:
lib/hub/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ GithubProject

Returns a new instance of GithubProject.



200
201
202
203
# File 'lib/hub/context.rb', line 200

def initialize(*args)
  super
  self.host ||= local_repo.default_host
end

Class Method Details

.from_url(url, local_repo) ⇒ Object



193
194
195
196
197
198
# File 'lib/hub/context.rb', line 193

def self.from_url(url, local_repo)
  if local_repo.known_hosts.include? url.host
    _, owner, name = url.path.split('/', 4)
    GithubProject.new(local_repo, owner, name.sub(/\.git$/, ''), url.host)
  end
end

Instance Method Details

#==(other) ⇒ Object



219
220
221
# File 'lib/hub/context.rb', line 219

def ==(other)
  name_with_owner == other.name_with_owner
end

#api_create_pullrequest_url(type) ⇒ Object



267
268
269
# File 'lib/hub/context.rb', line 267

def api_create_pullrequest_url(type)
  api_url(type, 'pulls', "#{owner}/#{name}")
end

#api_create_url(type) ⇒ Object



259
260
261
# File 'lib/hub/context.rb', line 259

def api_create_url(type)
  api_url(type, 'repos', 'create')
end

#api_fork_url(type) ⇒ Object



255
256
257
# File 'lib/hub/context.rb', line 255

def api_fork_url(type)
  api_url(type, 'repos', "fork/#{owner}/#{name}")
end

#api_pullrequest_url(id, type) ⇒ Object



263
264
265
# File 'lib/hub/context.rb', line 263

def api_pullrequest_url(id, type)
  api_url(type, 'pulls', "#{owner}/#{name}/#{id}")
end

#api_show_url(type) ⇒ Object



251
252
253
# File 'lib/hub/context.rb', line 251

def api_show_url(type)
  api_url(type, 'repos', "show/#{owner}/#{name}")
end

#api_url(type, resource, action) ⇒ Object



247
248
249
# File 'lib/hub/context.rb', line 247

def api_url(type, resource, action)
  URI("https://#{host}/api/v2/#{type}/#{resource}/#{action}")
end

#git_url(options = {}) ⇒ Object



240
241
242
243
244
245
# File 'lib/hub/context.rb', line 240

def git_url(options = {})
  if options[:https] then "https://#{host}/"
  elsif options[:private] or private? then "git@#{host}:"
  else "git://#{host}/"
  end + name_with_owner + '.git'
end

#name_with_ownerObject



215
216
217
# File 'lib/hub/context.rb', line 215

def name_with_owner
  "#{owner}/#{name}"
end

#owned_by(new_owner) ⇒ Object



209
210
211
212
213
# File 'lib/hub/context.rb', line 209

def owned_by(new_owner)
  new_project = dup
  new_project.owner = new_owner
  new_project
end

#private?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/hub/context.rb', line 205

def private?
  local_repo and host != local_repo.main_host
end

#remoteObject



223
224
225
# File 'lib/hub/context.rb', line 223

def remote
  local_repo.remotes.find { |r| r.project == self }
end

#web_url(path = nil) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/hub/context.rb', line 227

def web_url(path = nil)
  project_name = name_with_owner
  if project_name.sub!(/\.wiki$/, '')
    unless '/wiki' == path
      path = if path =~ %r{^/commits/} then '/_history'
             else path.to_s.sub(/\w+/, '_\0')
             end
      path = '/wiki' + path
    end
  end
  "https://#{host}/" + project_name + path.to_s
end