Class: March::Repo
- Inherits:
-
Object
- Object
- March::Repo
- Defined in:
- lib/march/repo.rb
Instance Method Summary collapse
- #branch_age ⇒ Object
- #branch_owners ⇒ Object
- #branches ⇒ Object
- #client ⇒ Object
- #compare_branches ⇒ Object
- #default_branch ⇒ Object
- #default_branch_name ⇒ Object
- #default_tip ⇒ Object
- #delete_branches(branch_names) ⇒ Object
- #id ⇒ Object
-
#initialize(namespace, repo) ⇒ Repo
constructor
A new instance of Repo.
- #merged_branches ⇒ Object
Constructor Details
#initialize(namespace, repo) ⇒ Repo
Returns a new instance of Repo.
5 6 7 8 |
# File 'lib/march/repo.rb', line 5 def initialize(namespace, repo) @string = "#{namespace}/#{repo}" @repo = client.repo(@string) end |
Instance Method Details
#branch_age ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/march/repo.rb', line 59 def branch_age compare_branches.each_with_object({}) do |(name, diff), acc| oldest = diff.merge_base_commit.commit..date newest = diff.commits.map { |c| c.commit..date }.sort.last res = { oldest: oldest, newest: newest } acc[name] = res unless name == default_branch_name || newest.nil? end end |
#branch_owners ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/march/repo.rb', line 46 def branch_owners @branch_owners ||= compare_branches.each_with_object({}) do |(name, diff), acc| = diff.commits.map { |c| c.commit. } = .map do |h| h.map { |k, v| v if k == :email }.compact end.uniq acc[name] = .flatten end end |
#branches ⇒ Object
30 31 32 |
# File 'lib/march/repo.rb', line 30 def branches @branches ||= @repo.rels[:branches].get.data end |
#compare_branches ⇒ Object
34 35 36 37 38 |
# File 'lib/march/repo.rb', line 34 def compare_branches branches.each_with_object({}) do |branch, acc| acc[branch.name] = client.compare(id, default_tip, branch.commit.sha) end end |
#default_branch ⇒ Object
22 23 24 |
# File 'lib/march/repo.rb', line 22 def default_branch branches[branches.find_index { |b| b.name == default_branch_name }] end |
#default_branch_name ⇒ Object
18 19 20 |
# File 'lib/march/repo.rb', line 18 def default_branch_name @repo.default_branch end |
#default_tip ⇒ Object
26 27 28 |
# File 'lib/march/repo.rb', line 26 def default_tip default_branch.commit.sha end |
#delete_branches(branch_names) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/march/repo.rb', line 68 def delete_branches(branch_names) raise ArgumentError unless branch_names.is_a?(Array) branch_names.each do |name| puts 'Deleting ' + name client.delete_branch(id, name) end end |
#id ⇒ Object
14 15 16 |
# File 'lib/march/repo.rb', line 14 def id @repo.id end |
#merged_branches ⇒ Object
40 41 42 43 44 |
# File 'lib/march/repo.rb', line 40 def merged_branches @merged_branches ||= compare_branches.select do |_name, diff| diff.commits.empty? end.map(&:first).reject { |name| name == default_branch.name } end |