Class: ChangesSince::ChangelogPrinter
- Inherits:
-
Object
- Object
- ChangesSince::ChangelogPrinter
- Defined in:
- lib/changes_since/changelog_printer.rb
Constant Summary collapse
- TAGS =
{ :public => 'Public', :bug => 'Bugs', :internal => 'Internal' }
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#teams ⇒ Object
readonly
Returns the value of attribute teams.
Instance Method Summary collapse
-
#initialize(commits, teams, options) ⇒ ChangelogPrinter
constructor
A new instance of ChangelogPrinter.
- #print! ⇒ Object
- #print_commits!(output_commits) ⇒ Object
- #print_message(commit, tag = nil) ⇒ Object
- #print_team_commits! ⇒ Object
- #print_team_name(name) ⇒ Object
Constructor Details
#initialize(commits, teams, options) ⇒ ChangelogPrinter
Returns a new instance of ChangelogPrinter.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/changes_since/changelog_printer.rb', line 11 def initialize(commits, teams, ) @commits = commits @teams = teams @options = git = Git.open(Dir.pwd) @repo = "https://github.com/" << git.remote.url.split(/[:.]/)[-2] if [:markdown] @api_client = ApiClient.new end end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
3 4 5 |
# File 'lib/changes_since/changelog_printer.rb', line 3 def api_client @api_client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/changes_since/changelog_printer.rb', line 3 def @options end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
3 4 5 |
# File 'lib/changes_since/changelog_printer.rb', line 3 def repo @repo end |
#teams ⇒ Object (readonly)
Returns the value of attribute teams.
3 4 5 |
# File 'lib/changes_since/changelog_printer.rb', line 3 def teams @teams end |
Instance Method Details
#print! ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/changes_since/changelog_printer.rb', line 22 def print! if teams print_team_commits! else print_commits!(@commits) end return end |
#print_commits!(output_commits) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/changes_since/changelog_printer.rb', line 59 def print_commits!(output_commits) output_commits.sort! { |a, b| a..name <=> b..name } if [:tags] TAGS.each do |type, title| tagged_commits = output_commits.select { |commit| commit..include?("##{type}") } next if tagged_commits.empty? puts "\n#{title}:\n\n" tagged_commits.each { |commit| (commit, type) } output_commits -= tagged_commits end return if output_commits.empty? puts "\nUnclassified:\n\n" end output_commits.each { |commit| (commit) } end |
#print_message(commit, tag = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/changes_since/changelog_printer.rb', line 78 def (commit, tag=nil) = commit..split("\n\n") if .first =~ /Merge pull request/ title = .last pr = .first.split(" from ").first.split("#").last else title = .first end title.gsub!("##{tag}", "") if tag = commit..name if [:markdown] text = "|#{title}|" text << "#{}|" text << "[##{pr}|#{@repo}/pull/#{pr}]|" if @repo && pr text << "#{api_client.pull_request_risks(pr)}|" else text = "* #{title} (#{})" end puts text end |
#print_team_commits! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/changes_since/changelog_printer.rb', line 31 def print_team_commits! teams.each do |team, members| = /#{members.join("|")}/i team_commits = @commits.select do |commit| [commit..name, commit..email].any? do |str| str.force_encoding(Encoding::UTF_8) =~ end end next if team_commits.empty? @commits -= team_commits print_team_name(team) print_commits!(team_commits) end return if @commits.empty? print_team_name("Other") print_commits!(@commits) end |
#print_team_name(name) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/changes_since/changelog_printer.rb', line 50 def print_team_name(name) if [:markdown] row = "||*#{name}*||Author||PR||Risk||" puts row else puts "\n*#{name}*\n" end end |