Module: Git
- Defined in:
- lib/spm_version_updates/git.rb
Class Method Summary collapse
-
.branch_last_commit(repo_url, branch_name) ⇒ String
Call git to find the last commit on a branch.
-
.repo_name(repo_url) ⇒ String
Extract a readable name for the repo given the url, generally org/repo.
-
.trim_repo_url(repo_url) ⇒ String
Removes protocol and trailing .git from a repo URL.
-
.version_tags(repo_url) ⇒ Array<Semantic::Version>
Call git to list tags.
Class Method Details
.branch_last_commit(repo_url, branch_name) ⇒ String
Call git to find the last commit on a branch
50 51 52 53 54 55 |
# File 'lib/spm_version_updates/git.rb', line 50 def self.branch_last_commit(repo_url, branch_name) `git ls-remote -h #{repo_url}` .split("\n") .find { |line| line.split("\trefs/heads/")[1] == branch_name } .split("\trefs/heads/")[0] end |
.repo_name(repo_url) ⇒ String
Extract a readable name for the repo given the url, generally org/repo
14 15 16 17 18 19 20 21 22 |
# File 'lib/spm_version_updates/git.rb', line 14 def self.repo_name(repo_url) match = repo_url.match(%r{([\w-]+/[\w-]+)(.git)?$}) if match match[1] || match[0] else repo_url end end |
.trim_repo_url(repo_url) ⇒ String
Removes protocol and trailing .git from a repo URL
8 9 10 |
# File 'lib/spm_version_updates/git.rb', line 8 def self.trim_repo_url(repo_url) repo_url.split("://").last.gsub(/\.git$/, "") end |
.version_tags(repo_url) ⇒ Array<Semantic::Version>
Call git to list tags
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/spm_version_updates/git.rb', line 28 def self.(repo_url) versions = `git ls-remote -t #{repo_url}` .split("\n") .map { |line| line.split("/tags/").last } .filter_map { |line| begin Semantic::Version.new(line) rescue ArgumentError nil end } versions.sort! versions.reverse! versions end |