Module: ReleaseNotes Private

Extended by:
T::Sig
Defined in:
release_notes.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper functions for generating release notes.

Class Method Summary collapse

Class Method Details

.generate_release_notes(start_ref, end_ref, markdown: false) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'release_notes.rb', line 16

def generate_release_notes(start_ref, end_ref, markdown: false)
  log_output = Utils.popen_read(
    "git", "-C", HOMEBREW_REPOSITORY, "log", "--pretty=format:'%s >> - %b%n'", "#{start_ref}..#{end_ref}"
  ).lines.grep(/Merge pull request/)

  log_output.map! do |s|
    matches = s.match(%r{.*Merge pull request #(?<pr>\d+) from (?<user>[^/]+)/[^>]*>> - (?<body>.*)})
    body = if matches[:body].empty?
      s.gsub(/.*(Merge pull request .*) >> - .*/, "\\1").chomp
    else
      matches[:body]
    end
    "https://github.com/Homebrew/brew/pull/#{matches[:pr]} (@#{matches[:user]}) - #{body}\n"
  end

  if markdown
    log_output.map! do |s|
      /(.*\d)+ \(@(.+)\) - (.*)/ =~ s
      "- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})\n"
    end
  end

  log_output.join
end