Class: March::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/march/repo.rb

Instance Method Summary collapse

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_ageObject



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.author.date
    newest = diff.commits.map { |c| c.commit.author.date }.sort.last
    res = { oldest: oldest, newest: newest }
    acc[name] = res unless name == default_branch_name || newest.nil?
  end
end

#branch_ownersObject



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|
      author_ary   = diff.commits.map { |c| c.commit.author }
      authors      =
        author_ary.map do |h|
          h.map { |k, v| v if k == :email }.compact
        end.uniq

      acc[name] = authors.flatten
    end
end

#branchesObject



30
31
32
# File 'lib/march/repo.rb', line 30

def branches
  @branches ||= @repo.rels[:branches].get.data
end

#clientObject



10
11
12
# File 'lib/march/repo.rb', line 10

def client
  March::Github.client
end

#compare_branchesObject



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_branchObject



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_nameObject



18
19
20
# File 'lib/march/repo.rb', line 18

def default_branch_name
  @repo.default_branch
end

#default_tipObject



26
27
28
# File 'lib/march/repo.rb', line 26

def default_tip
  default_branch.commit.sha
end

#delete_branches(branch_names) ⇒ Object

Raises:

  • (ArgumentError)


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

#idObject



14
15
16
# File 'lib/march/repo.rb', line 14

def id
  @repo.id
end

#merged_branchesObject



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