Class: GitHubChangelogGenerator::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/github_changelog_generator/generator/entry.rb

Overview

This class generates the content for a single changelog entry. An entry is generally either for a specific tagged release or the collection of unreleased changes.

An entry is comprised of header text followed by a series of sections relating to the entry.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = Options.new({})) ⇒ Entry

Returns a new instance of Entry.



18
19
20
21
# File 'lib/github_changelog_generator/generator/entry.rb', line 18

def initialize(options = Options.new({}))
  @content = ""
  @options = Options.new(options)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



16
17
18
# File 'lib/github_changelog_generator/generator/entry.rb', line 16

def content
  @content
end

Instance Method Details

#generate_entry_for_tag(pull_requests, issues, newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name) ⇒ String

Generates log entry with header and body

Parameters:

  • pull_requests (Array)

    List or PR’s in new section

  • issues (Array)

    List of issues in new section

  • newer_tag_name (String)

    Name of the newer tag. Could be nil for ‘Unreleased` section.

  • newer_tag_link (String)

    Name of the newer tag. Could be “HEAD” for ‘Unreleased` section.

  • newer_tag_time (Time)

    Time of the newer tag

  • older_tag_name (Hash, nil)

    Older tag, used for the links. Could be nil for last tag.

Returns:

  • (String)

    Ready and parsed section content.



32
33
34
35
36
37
38
39
40
41
# File 'lib/github_changelog_generator/generator/entry.rb', line 32

def generate_entry_for_tag(pull_requests, issues, newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name) # rubocop:disable Metrics/ParameterLists
  github_site = @options[:github_site] || "https://github.com"
  project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}"

  create_sections

  @content = generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
  @content += generate_body(pull_requests, issues)
  @content
end

#line_labels_for(issue) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/github_changelog_generator/generator/entry.rb', line 43

def line_labels_for(issue)
  labels = if @options[:issue_line_labels] == ["ALL"]
             issue["labels"]
           else
             issue["labels"].select { |label| @options[:issue_line_labels].include?(label["name"]) }
           end
  labels.map { |label| " \[[#{label['name']}](#{label['url'].sub('api.github.com/repos', 'github.com')})\]" }.join("")
end