class Atlassian::Stash::RepoInfo

Public Class Methods

appendFilePathAndFragment(uri, filePath, lineNumber) click to toggle source
# File lib/atlassian/stash/repo_info.rb, line 42
def self.appendFilePathAndFragment(uri, filePath, lineNumber)
  if filePath && !filePath.empty?
    uri.path = uri.path + (filePath.start_with?('/') ? filePath : "/#{filePath}")

    if lineNumber && !lineNumber.nil?
      uri.fragment = lineNumber.to_s
    end
  end

  uri
end
create(config, remote=nil) click to toggle source
# File lib/atlassian/stash/repo_info.rb, line 54
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$/)
    raise "Repository does not seem to be hosted in Stash; Remote url: " + remoteUrl          
  end
  
  return RepoInfo.new(config, m[1], m[2])
end
new(config, projectKey, slug) click to toggle source
# File lib/atlassian/stash/repo_info.rb, line 6
def initialize(config, projectKey, slug)
  @config = config
  @projectKey = projectKey
  @slug = slug
end

Public Instance Methods

projectKey() click to toggle source
# File lib/atlassian/stash/repo_info.rb, line 12
def projectKey
  @projectKey
end
repoPath() click to toggle source
# 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, options = {}) click to toggle source
# File lib/atlassian/stash/repo_info.rb, line 26
def repoUrl(suffix, branch, options = {})
  filePath = options[:filePath]
  lineNumber = options[:lineNumber]
  uri = URI.parse(@config["stash_url"])
  uri.path = repoPath + (suffix.nil? ? '' : '/' + suffix)
  uri = RepoInfo.appendFilePathAndFragment(uri, filePath, lineNumber)

  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
slug() click to toggle source
# File lib/atlassian/stash/repo_info.rb, line 16
def slug
  @slug
end