Class: Bruh::Changelog
- Inherits:
-
Object
- Object
- Bruh::Changelog
- Extended by:
- T::Sig
- Defined in:
- lib/bruh/changelog.rb
Overview
Manages changelog updates and version entries
Class Method Summary collapse
- .generate_release_notes(project_root) ⇒ Object
- .update(version, project_root, interactive: true) ⇒ Object
Class Method Details
.generate_release_notes(project_root) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bruh/changelog.rb', line 44 def self.generate_release_notes(project_root) changelog_path = File.join(project_root, 'CHANGELOG.md') return { version: 'unknown', notes: 'No changelog found' } unless File.exist?(changelog_path) content = File.read(changelog_path) # Extract the latest version entry if content =~ /## \[([^\]]+)\][^\n]*\n\n(.*?)(?=\n## |\Z)/m version = ::Regexp.last_match(1) notes = T.must(::Regexp.last_match(2)).strip return { version: version, notes: notes } end { version: 'unknown', notes: 'Could not extract release notes' } end |
.update(version, project_root, interactive: true) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bruh/changelog.rb', line 13 def self.update(version, project_root, interactive: true) changelog_path = File.join(project_root, 'CHANGELOG.md') today = Date.today.strftime('%Y-%m-%d') # Create file if it doesn't exist File.write(changelog_path, "# Changelog\n\n") unless File.exist?(changelog_path) content = File.read(changelog_path) # Check if this version already exists in changelog return true if content.include?("## [#{version}]") # Insert new version entry after the header new_content = content.sub(/^# Changelog/, "# Changelog\n\n## [#{version}] - #{today}\n\n- Add your changes here\n\n") File.write(changelog_path, new_content) # Open editor for user to edit changelog if in interactive mode if interactive editor = ENV['EDITOR'] || 'nano' puts 'Opening CHANGELOG.md for editing. Please add your release notes.' system("#{editor} #{changelog_path}") puts 'Press Enter to continue with the release process...' gets end true end |