Class: Releaser::Repo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '.') ⇒ Repo

Returns a new instance of Repo.



51
52
53
# File 'lib/releaser.rb', line 51

def initialize(path = '.')
  @repo = Rugged::Repository.new(Rugged::Repository.discover(path))
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



49
50
51
# File 'lib/releaser.rb', line 49

def repo
  @repo
end

Instance Method Details

#all_change_logsObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/releaser.rb', line 82

def all_change_logs
  start_tag = Tag.new("HEAD", repo.last_commit)
  start_on = start_tag.oid == tags.first.oid ? nil : start_tag

  change_logs = []
  tags.reduce(start_on) do |start_tag, end_tag|
    if start_tag
      commits = commits_between(start_tag.commit, end_tag.commit)
      change_logs << ChangeLog.new(self, start_tag, commits)
    end
    end_tag
  end

  change_logs
end

#commits_between(start_ref, end_ref) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/releaser.rb', line 98

def commits_between(start_ref, end_ref)
  commits = []
  repo.walk(start_ref.oid) do |commit|
    break if commit.oid == end_ref.oid
    commits << commit
  end

  commits
end

#create_release(tag_name) ⇒ Object



63
64
65
# File 'lib/releaser.rb', line 63

def create_release(tag_name)
  Rugged::Reference.create(repo, "refs/tags/#{tag_name}", repo.last_commit.oid)
end

#last_change_logObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/releaser.rb', line 67

def last_change_log
  raise "Not enough tags in repo" if tags.length < 1

  # Need at least one tag in the repo (two if it's the current commit)
  if tags.first.oid == repo.last_commit.oid
    start_tag = tags.first
    end_tag = tags[1]
  else
    start_tag = Tag.new("HEAD", repo.last_commit)
    end_tag = tags[0]
  end

  ChangeLog.new(self, start_tag, commits_between(repo.last_commit, end_tag.commit))
end

#tagsObject



55
56
57
58
59
60
61
# File 'lib/releaser.rb', line 55

def tags
  @tags ||= repo.tags.map do |tagname|
    rev = repo.rev_parse(tagname)
    commit = rev.respond_to?(:target) ? rev.target : rev
    Tag.new(tagname, commit)
  end.sort_by(&:time).reverse
end