Class: Atlassian::Stash::RepoInfo
- Inherits:
-
Object
- Object
- Atlassian::Stash::RepoInfo
- Defined in:
- lib/atlassian/stash/repo_info.rb
Class Method Summary collapse
- .appendFilePathAndFragment(uri, filePath, lineNumber) ⇒ Object
- .create(config, remote = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(config, projectKey, slug) ⇒ RepoInfo
constructor
A new instance of RepoInfo.
- #projectKey ⇒ Object
- #repoPath ⇒ Object
- #repoUrl(suffix, branch, options = {}) ⇒ Object
- #slug ⇒ Object
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
.appendFilePathAndFragment(uri, filePath, lineNumber) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 |
Instance Method Details
#projectKey ⇒ Object
12 13 14 |
# File 'lib/atlassian/stash/repo_info.rb', line 12 def projectKey @projectKey end |
#repoPath ⇒ Object
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, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/atlassian/stash/repo_info.rb', line 26 def repoUrl(suffix, branch, = {}) filePath = [:filePath] lineNumber = [: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 ⇒ Object
16 17 18 |
# File 'lib/atlassian/stash/repo_info.rb', line 16 def slug @slug end |