Class: Atlassian::Stash::RepoInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/atlassian/stash/repo_info.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, projectKey, slug) ⇒ RepoInfo

Returns a new instance of RepoInfo.



6
7
8
9
10
# File 'lib/atlassian/stash/repo_info.rb', line 6

def initialize(config, projectKey, slug)
  @config = config
  @projectKey = projectKey
  @slug = slug
end

Class Method Details

.create(config, remote = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/atlassian/stash/repo_info.rb', line 40

def self.create (config, remote=nil)
  config = Hash.new if config.nil?
  remote = config["remote"] if (remote.nil? || remote.empty?)
  remoteUrl = Atlassian::Stash::Git.get_remote_url(remote)

  if remoteUrl.nil?
    remotes = Atlassian::Stash::Git.get_remotes
    if remotes.empty?
      raise "No git remotes found, could not determine Stash project URL"
    else
      remote = Atlassian::Stash::Git::DEFAULT_REMOTE if (remote.nil? || remote.empty?)
      raise "Could not find requested git remote '#{remote}'. Remotes found: \r\n" + remotes
    end
  end

  if m = remoteUrl.match(/\/([a-zA-Z~][a-zA-Z0-9_\-]*)\/([[:alnum:]][\w\-\.]*).git$/)
    return RepoInfo.new(config, m[1], m[2])
  end
  raise "Repository does not seem to be hosted in Stash; Remote url: " + remoteUrl
end

Instance Method Details

#projectKeyObject



12
13
14
# File 'lib/atlassian/stash/repo_info.rb', line 12

def projectKey
  @projectKey
end

#repoPathObject



20
21
22
23
24
# File 'lib/atlassian/stash/repo_info.rb', line 20

def repoPath
  uri = URI.parse(@config["stash_url"])
  repoPath = uri.path + '/projects/' + @projectKey + '/repos/' + @slug
  repoPath
end

#repoUrl(suffix, branch) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/atlassian/stash/repo_info.rb', line 26

def repoUrl(suffix, branch)
  uri = URI.parse(@config["stash_url"])
  path = repoPath + (suffix.nil? ? '' : '/' + suffix)
  uri.path = path
  
  if (!branch.nil? and !branch.empty?)
      q = uri.query || ''
      q = q + (q.empty? ? '' : '&') + 'at=' + branch unless branch.nil?
      uri.query = q
  end

  uri.to_s
end

#slugObject



16
17
18
# File 'lib/atlassian/stash/repo_info.rb', line 16

def slug
  @slug
end