class ReleaseNotes::GithubRepo

  def initialize
    @git = Git.open(Rails.application.secrets.github_repository)
  end

  def prepare_branch(branch)
    @git.checkout(:master)
    @git.pull
    @git.fetch
    @git.checkout(branch)
    @git.pull(:origin, branch)
  end

  def release_notes(branch)
    @git.log(1000).between(:master, branch).each_with_object([]) do |commit, array|
      commit_array = @git.object(commit).contents.split("\n").reject!(&:empty?)
      commit_array.each do |message|
        if message =~ /Merge pull request #/
          array << "* #{message.scan(/#\d+/).first} #{commit_array.last}"
        end
      end
    end
  end

end