Method: Raketeer::BumpTask#bump_changelogs

Defined in:
lib/raketeer/bump_task.rb

#bump_changelogs(bump_ver) ⇒ Object

See Also:

Since:

  • 0.2.4



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/raketeer/bump_task.rb', line 184

def bump_changelogs(bump_ver)
  return nil if @changelogs.empty?

  bumper = FilesBumper.new(@changelogs,bump_ver,@dry_run,@strict) do
    @header_bumped = false
    @unreleased_bumped = false
  end

  header_regex = /\A(\s*##\s*\[+\D*)(#{SemVer.regex(@strict)})(.*)\z/m
  unreleased_regex = /\A.*Unreleased.*http.*\.{3}/

  bumper.bump_files do
    if @header_bumped && @unreleased_bumped
      break if bumper.bump_ver_empty?
      next
    end

    if bumper.line =~ unreleased_regex
      next if @unreleased_bumped

      # Match from the end, in case the URL has a number (like '%20').
      match = bumper.line.match(/(#{SemVer.regex(@strict)})(\.{3}.*)\z/m)

      next if match.nil? || match.length < 3 || (i = match.begin(0)) < 1

      match = [bumper.line[0..i - 1],match[1],match[-1]]

      next if match.any? { |m| m.nil? || m.strip.empty? }

      orig_line = bumper.line.dup
      bumper.line = match[1]

      if (result = bumper.bump_line!(add_change: false)) != :no_ver
        @unreleased_bumped = true

        if result == :same_ver
          bumper.line = orig_line

          next
        end

        bumper.line = match[0] << bumper.line << match[2]

        bumper.add_change(bumper.line,push: false)
      else
        bumper.line = orig_line
      end
    elsif !(match = bumper.line.match(header_regex)).nil?
      next if @header_bumped || match.length < 4

      match = [match[1],match[2],match[-1]]

      next if match.any? { |m| m.nil? || m.strip.empty? }

      orig_line = bumper.line.dup
      bumper.line = match[1]

      if (result = bumper.bump_line!(add_change: false)) != :no_ver
        @header_bumped = true

        if result == :same_ver
          bumper.line = orig_line

          next
        end

        bumper.line = (match[0] << bumper.line)

        # Replace the date with today's date for the new Markdown header, if it exists.
        match[2].sub!(/\d+\s*-\s*\d+\s*-\s*\d+(.*)\z/m,"#{Date.today.strftime('%F')}\\1")

        # Fix the link if there is one:
        #   https://github.com/esotericpig/raketeer/compare/v0.2.10...v0.2.11
        versions_regex = /
          (?<beg_ver>#{SemVer.regex(@strict)})
          (?<sep>\.{3}[^\d\s]{,11}) # 11 for 'v', 'version', or something else.
          (?<end_ver>#{SemVer.regex(@strict)})
        /xmi
        versions_match = match[2].match(versions_regex)

        if versions_match
          match[2].sub!(
            versions_regex,
            "#{versions_match[:end_ver]}" \
            "#{versions_match[:sep]}" \
            "#{bumper.sem_ver}",
          )
        end

        bumper.line << match[2]

        bumper.add_change(bumper.line,push: true)

        # Add after add_change(), so not printed to console.
        bumper.line << "\n\n"
      end

      # We are adding a new Markdown header, so always set the line back to its original value.
      bumper.line = orig_line
    end
  end

  return bumper.version
end