release-notes 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,40 +2,73 @@
2
2
 
3
3
  module Release
4
4
  module Notes
5
- module System
6
- module_function
5
+ class System
6
+ include Configurable
7
+ attr_reader :opts
7
8
 
8
- extend ActiveSupport::Concern
9
- include Git
9
+ #
10
+ # Release::Notes::System initializer
11
+ #
12
+ # @param **opts
13
+ #
14
+ # @return none
15
+ #
16
+ def initialize(**opts)
17
+ @opts = opts
10
18
 
11
- delegate :all_labels, to: :"Release::Notes.configuration"
19
+ return unless opts.delete(:log_all) == true
12
20
 
13
- included do
14
- def system_log(**opts)
15
- if opts.delete(:log_all) == true
16
- opts[:label] = all_labels
17
- opts[:invert_grep] = " --invert-grep"
18
- end
19
-
20
- `#{log(opts)}`
21
- end
21
+ opts[:label] = config_all_labels
22
+ opts[:invert_grep] = " --invert-grep"
22
23
  end
23
24
 
24
- def first_commit
25
- `#{Git.first_commit}`
25
+ #
26
+ # Call Git.log method with configurable options
27
+ #
28
+ # @return [String] shell output of running Git.log
29
+ #
30
+ def log
31
+ `#{Git.log(opts)}`
26
32
  end
27
33
 
28
- def all_tags
29
- `#{Git.read_all_tags}`
30
- end
34
+ class << self
35
+ #
36
+ # Call Git.first_commit method
37
+ #
38
+ # @return [String] shell output of running Git.first_commit
39
+ #
40
+ def first_commit
41
+ `#{Git.first_commit}`
42
+ end
31
43
 
32
- def system_last_tag
33
- `#{Git.last_tag}`
34
- end
44
+ #
45
+ # Call Git.read_all_tags method
46
+ #
47
+ # @return [String] shell output of running Git.read_all_tags
48
+ #
49
+ def all_tags
50
+ `#{Git.read_all_tags}`
51
+ end
52
+
53
+ #
54
+ # Call Git.last_tag method
55
+ #
56
+ # @return [String] shell output of running Git.last_tag
57
+ #
58
+ def last_tag
59
+ `#{Git.last_tag}`
60
+ end
35
61
 
36
- def tag_date(tag: nil)
37
- tag ||= system_last_tag
38
- `#{Git.tag_date(tag)}`
62
+ #
63
+ # Call Git.tag_date method
64
+ #
65
+ # @param [String] tag - a tag that you want to get the date created for
66
+ #
67
+ # @return [String] shell output of running Git.tag_date
68
+ #
69
+ def tag_date(tag: nil)
70
+ `#{Git.tag_date(tag || last_tag)}`
71
+ end
39
72
  end
40
73
  end
41
74
  end
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Release
4
+ module Notes
5
+ class Tag
6
+ include Configurable
7
+ attr_accessor :_hashes
8
+ attr_reader :tag, :previous_tag
9
+
10
+ delegate :digest_header, prefix: :writer, to: :@writer
11
+
12
+ # Release::Notes::Tag initializer
13
+ #
14
+ # @param [String] tag - a git tag (ex: v2.0.0)
15
+ # @param [Release::Notes::Write] writer - an object containing a header, title, and associated log messages
16
+ # @param [String] previous_tag - the previous git tag (ex: v1.3.0)
17
+ def initialize(tag:, writer:, previous_tag:)
18
+ @tag = tag
19
+ @writer = writer
20
+ @previous_tag = previous_tag
21
+
22
+ @_commits = {}
23
+ @_hashes = []
24
+ end
25
+
26
+ #
27
+ # Adds log messages to @_commits variable, and if there are commits that need to be added to
28
+ # changelog, add the header and associated log messages
29
+ #
30
+ # @return none
31
+ #
32
+ def perform
33
+ store_commits # adds to @_commits
34
+
35
+ if commits_available? # true
36
+ writer_digest_header(header_title) # <File:./release-notes.tmp.md (closed)>
37
+ log_commits # hash [0,1,2...], messages for sha
38
+ end
39
+
40
+ self
41
+ end
42
+
43
+ private
44
+
45
+ #
46
+ # Are there git sha's with commits?
47
+ #
48
+ # @return [Boolean] true: commits are present, false: there are no commits
49
+ #
50
+ def commits_available?
51
+ @_commits.present?
52
+ end
53
+
54
+ #
55
+ # Formats a supplied date
56
+ #
57
+ # @param [String] date - a date
58
+ #
59
+ # @return [String] formatted date
60
+ #
61
+ def formatted_date(date = nil)
62
+ DateFormatter.new(date).humanize
63
+ end
64
+
65
+ #
66
+ # Generate header title
67
+ #
68
+ # @return [String] the header to be added to changelog
69
+ #
70
+ def header_title
71
+ config_header_title.yield_self { |t| title(t) } # config_header_title = "tag"
72
+ end
73
+
74
+ #
75
+ # Creates new commit objects from the @_commits object
76
+ #
77
+ # @return [Hash] unique log messages per tag
78
+ #
79
+ def log_commits
80
+ @_commits.each do |key, val|
81
+ Commits.new(title: titles[key], value: val, writer: @writer, tagger: self).perform
82
+ end
83
+ end
84
+
85
+ #
86
+ # Transform tag into date
87
+ #
88
+ # @return [String] date the tag was created
89
+ #
90
+ def tag_date
91
+ System.tag_date(tag: tag)
92
+ end
93
+
94
+ #
95
+ # Adds log messages to @_commits
96
+ #
97
+ # @return none
98
+ #
99
+ def store_commits
100
+ all_labels.each_with_index do |lab, i|
101
+ system_log(label: lab).tap { |str| @_commits[i] = str if str.present? }
102
+ end
103
+
104
+ # if log_all = true
105
+ @_commits[all_labels.size] = system_log(log_all: true) if config_log_all
106
+ end
107
+
108
+ #
109
+ # Create new system object that contains log messages between tag_from and tag_to
110
+ # with the relevant options
111
+ #
112
+ # @param [Hash] opts - options like the label to grep
113
+ #
114
+ # @return [String] log messages that meet the criteria
115
+ #
116
+ def system_log(**opts)
117
+ System.new({ tag_from: previous_tag, tag_to: tag }.merge(opts)).log
118
+ end
119
+
120
+ #
121
+ # Array of strings containing all labels
122
+ #
123
+ # @return [Array] array of all labels
124
+ #
125
+ def all_labels
126
+ [config_features, config_bugs, config_misc]
127
+ end
128
+
129
+ #
130
+ # Array of strings containing all titles
131
+ #
132
+ # @return [Array] array of all titles
133
+ #
134
+ def titles
135
+ [config_feature_title, config_bug_title,
136
+ config_misc_title, config_log_all_title]
137
+ end
138
+
139
+ #
140
+ # Title or formatted tag date
141
+ #
142
+ # @param [String] title - should the title be the git tag? If yes, use the git
143
+ # tag as the title, if not use the tag date
144
+ #
145
+ # @return [String] tag title or formatted tag date to be added to changelog
146
+ #
147
+ def title(title)
148
+ title == "tag" ? tag : formatted_date(tag_date)
149
+ end
150
+ end
151
+ end
152
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Release
4
4
  module Notes
5
- VERSION = "2.0.0"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
@@ -4,24 +4,33 @@ module Release
4
4
  module Notes
5
5
  class Write
6
6
  include Link
7
- include PrettyPrint
8
-
9
- delegate :output_file, :temp_file, :link_commits?, :all_labels,
10
- :prettify_messages?, :release_notes_exist?,
11
- :force_rewrite, to: :"Release::Notes.configuration"
7
+ include Configurable
12
8
 
9
+ #
10
+ # Release::Notes::Write initializer
11
+ #
12
+ # @return none
13
+ #
13
14
  def initialize
14
- # create a new temp file regardless if it exists
15
15
  new_temp_file_template
16
16
  end
17
17
 
18
- # write strings to tempfile
18
+ #
19
+ # Write strings to tempfile
20
+ #
21
+ # @param [String] str - string to add to the temp file
22
+ #
19
23
  def digest(str)
20
- File.open(temp_file, "a") { |fi| fi << str }
24
+ File.open(config_temp_file, "a") { |fi| fi << str }
21
25
  end
22
26
 
23
- # formats titles to be added to the new file
24
- # removes tags from title if configured
27
+ # Formats titles to be added to the new file and removes tags from title if configured
28
+ #
29
+ # @param [String] title - string representing a label title
30
+ # @param [String] log_message - string containing log messages that fall under the title
31
+ #
32
+ # @return [String] formatted label title and log messages that fall under it.
33
+ #
25
34
  def digest_title(title: nil, log_message: nil)
26
35
  @title = title
27
36
  @log_message = log_message
@@ -30,64 +39,111 @@ module Release
30
39
  digest(titles)
31
40
  end
32
41
 
33
- # formats the headers to be added to the new file
42
+ #
43
+ # Adds formatted header to changelog
44
+ #
45
+ # @param [String] header - unformatted header that needs to be added to changelog
46
+ #
34
47
  def digest_header(header)
35
48
  @header = header
36
49
  digest(header_present)
37
50
  end
38
51
 
52
+ #
39
53
  # append old file to new temp file
40
54
  # overwrite output file with tmp file
55
+ #
56
+ # @return none
57
+ #
41
58
  def write_new_file
42
- copy_over_notes if release_notes_exist? && !force_rewrite
59
+ copy_over_notes if config_release_notes_exist? && !config_force_rewrite
43
60
 
44
- FileUtils.cp(temp_file, output_file)
45
- FileUtils.rm temp_file
61
+ FileUtils.cp(config_temp_file, config_output_file)
62
+ FileUtils.rm config_temp_file
46
63
  end
47
64
 
48
65
  private
49
66
 
50
- # @api private
67
+ #
68
+ # Formats the header
69
+ #
70
+ # @return [String] formatted header to be added to changelog
71
+ #
51
72
  def header_present
52
- "\n## #{@header}\n"
73
+ "#{NEWLINE}## #{@header}#{NEWLINE}"
53
74
  end
54
75
 
55
- # @api private
76
+ #
77
+ # Formats the title
78
+ #
79
+ # @return [String] formatted title to be added to changelog
80
+ #
56
81
  def title_present
57
- "\n#{@title}\n\n"
82
+ "#{NEWLINE}#{@title}#{NEWLINE}#{NEWLINE}"
58
83
  end
59
84
 
60
- # @api private
85
+ #
86
+ # If prettify_messages is true, remove the label keyword from log message
87
+ # else, just return the log message
88
+ #
89
+ # @return [String] log message to be added to changelog
90
+ #
61
91
  def format_line
62
- return "#{prettify(line: link_messages)}\n" if prettify_messages?
92
+ return "#{prettify_linked_messages}#{NEWLINE}" if config_prettify_messages?
63
93
 
64
94
  link_messages
65
95
  end
66
96
 
67
- # @api private
97
+ #
98
+ # Calls link_message method with a log message
99
+ #
100
+ # @return [String] log message to be added to the changelog
101
+ #
68
102
  def link_messages
69
103
  link_message @log_message
70
104
  end
71
105
 
72
- # @api private
106
+ #
107
+ # Prettifies linked log messages
108
+ #
109
+ # @return [String] formatted log message
110
+ #
111
+ def prettify_linked_messages
112
+ Prettify.new(line: link_messages).perform
113
+ end
114
+
115
+ #
116
+ # Appends previous changelog to a temporary file
117
+ #
118
+ # @return none
119
+ #
73
120
  def copy_over_notes
74
- File.open(temp_file, "a") do |f|
75
- f << "\n"
76
- IO.readlines(output_file)[2..-1].each { |line| f << line }
121
+ File.open(config_temp_file, "a") do |f|
122
+ f << NEWLINE
123
+ IO.readlines(config_output_file)[2..-1].each { |line| f << line }
77
124
  end
78
125
  end
79
126
 
80
- # @api private
127
+ #
128
+ # Returns the log message if message linking is not configured
129
+ # else, return the linked log_message
130
+ #
131
+ # @return [String] original or updated log essage
132
+ #
81
133
  def link_message(log_message)
82
- return log_message unless link_commits?
134
+ return log_message unless config_link_commits?
83
135
 
84
136
  link_lines(lines: log_message)
85
137
  end
86
138
 
87
- # @api private
139
+ #
140
+ # Open temp file and output release notes header
141
+ #
142
+ # @return none
143
+ #
88
144
  def new_temp_file_template
89
- File.open(temp_file, "w") do |fi|
90
- fi << "# Release Notes\n"
145
+ File.open(config_temp_file, "w") do |fi|
146
+ fi << "# Release Notes#{NEWLINE}"
91
147
  end
92
148
  end
93
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: release-notes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Monroe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-08 00:00:00.000000000 Z
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -112,15 +112,18 @@ files:
112
112
  - lib/generators/release/notes/install/templates/README
113
113
  - lib/generators/release/notes/install/templates/release_notes.rb
114
114
  - lib/release/notes.rb
115
+ - lib/release/notes/commits.rb
116
+ - lib/release/notes/configurable.rb
115
117
  - lib/release/notes/configuration.rb
116
- - lib/release/notes/date_format.rb
118
+ - lib/release/notes/date_formatter.rb
117
119
  - lib/release/notes/git.rb
118
120
  - lib/release/notes/install.rb
119
121
  - lib/release/notes/link.rb
120
122
  - lib/release/notes/log.rb
121
- - lib/release/notes/pretty_print.rb
123
+ - lib/release/notes/prettify.rb
122
124
  - lib/release/notes/railtie.rb
123
125
  - lib/release/notes/system.rb
126
+ - lib/release/notes/tag.rb
124
127
  - lib/release/notes/tasks/install.rake
125
128
  - lib/release/notes/version.rb
126
129
  - lib/release/notes/write.rb