Class: Releasinator::Changelog::Importer

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

Instance Method Summary collapse

Constructor Details

#initialize(releasinator_config) ⇒ Importer

Returns a new instance of Importer.



8
9
10
# File 'lib/changelog/importer.rb', line 8

def initialize(releasinator_config)
  @releasinator_config = releasinator_config
end

Instance Method Details

#import(repo_url) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/changelog/importer.rb', line 12

def import(repo_url)
  # create tempfile 
  File.open('CHANGELOG.md.tmp', 'w') do |f|
    title_string = "#{@releasinator_config[:product_name]} release notes"
    f.puts title_string

    # print ====== with the length of the previous line for prettiness
    title_string.length.times { f.print "=" }
    f.puts

    # read releases
    github_repo = GitHubRepo.new(repo_url)

    begin
      github_releases = github_repo.client.releases "#{github_repo.org}/#{github_repo.repo}"
      github_releases.each do |github_release|
        puts github_release.inspect if @releasinator_config[:trace]
        f.puts
        f.puts github_release.name
        f.puts "-----"
        f.puts github_release.body
      end
    rescue => error
      f.puts "<could not read releases from github>"
      Printer.fail(error.inspect)
      abort()
    end
  end
end