Class: Changelog
- Inherits:
-
WorkflowAction
- Object
- WorkflowAction
- Changelog
- Defined in:
- lib/release_manager/changelog.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Attributes included from ReleaseManager::VCSManager
Class Method Summary collapse
-
.check_requirements(path) ⇒ Object
checks to make sure the unreleased line is valid, and the file exists.
Instance Method Summary collapse
- #already_released? ⇒ Boolean
- #changelog_file ⇒ Object
- #changelog_lines ⇒ Object
-
#commit_changelog(msg = nil, remote = false, branch = 'master') ⇒ String
The oid of the commit that was created.
- #empty_changelog_contents ⇒ Object
-
#get_unreleased_content ⇒ Array
-
array of lines of the unreleased content, text between unreleased and next version.
-
-
#get_version_content(version) ⇒ Array
-
array of lines of the specified version content, text between specified version and next version.
-
-
#initialize(module_path, version, options = {}) ⇒ Changelog
constructor
A new instance of Changelog.
- #module_name ⇒ Object
- #new_content ⇒ Object
- #path ⇒ Object
-
#run(remote = false, branch = 'master') ⇒ String
Create the changelog entries and commit.
- #unreleased_index ⇒ Object
- #update_unreleased ⇒ Object
Methods included from ReleaseManager::VCSManager
adapter_instance, adapter_types, default_instance
Methods included from ReleaseManager::Logger
Methods included from ReleaseManager::Git::Utilities
#add_all, #add_file, #add_remote, #apply_diff, #apply_patch, #author, #author_email, #author_name, #branch_exist?, #changed_files, #checkout_branch, #cherry_pick, #cli_create_commit, #clone, #create_branch, #create_commit, #create_diff, #create_diff_obj, #create_local_tag, #credentials, #current_branch, #current_branch?, #delete_branch, #fetch, #fetch_cli, #find_or_create_remote, #find_ref, #find_tag, #get_content, #git_command, #git_url?, #push_branch, #push_tags, #rebase_branch, #ref_exists?, #remote_exists?, #remote_from_name, #remote_from_url, #remote_url_matches?, #remove_file, #repo, #tag_exists?, #tags, #transports, #up2date?
Constructor Details
#initialize(module_path, version, options = {}) ⇒ Changelog
Returns a new instance of Changelog.
20 21 22 23 24 |
# File 'lib/release_manager/changelog.rb', line 20 def initialize(module_path, version, = {}) @options = @root_dir = module_path @version = version end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/release_manager/changelog.rb', line 14 def @options end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
14 15 16 |
# File 'lib/release_manager/changelog.rb', line 14 def root_dir @root_dir end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/release_manager/changelog.rb', line 14 def version @version end |
Class Method Details
.check_requirements(path) ⇒ Object
checks to make sure the unreleased line is valid, and the file exists
129 130 131 132 |
# File 'lib/release_manager/changelog.rb', line 129 def self.check_requirements(path) log = new(path, nil) log.unreleased_index end |
Instance Method Details
#already_released? ⇒ Boolean
79 80 81 |
# File 'lib/release_manager/changelog.rb', line 79 def already_released? !!changelog_lines.each_index.find {|index| changelog_lines[index] =~ /\A\s*\#{2}\s*Version #{version}/i } end |
#changelog_file ⇒ Object
53 54 55 |
# File 'lib/release_manager/changelog.rb', line 53 def changelog_file [:file] || File.join(root_dir, 'CHANGELOG.md') end |
#changelog_lines ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/release_manager/changelog.rb', line 58 def changelog_lines unless @changelog_lines @changelog_lines = File.exists?(changelog_file) ? File.readlines(changelog_file) : empty_changelog_contents.lines end @changelog_lines end |
#commit_changelog(msg = nil, remote = false, branch = 'master') ⇒ String
Returns the oid of the commit that was created.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/release_manager/changelog.rb', line 112 def commit_changelog(msg = nil, remote = false, branch = 'master') = msg || "[ReleaseManager] - bump changelog to version #{version}" if remote actions = [{ action: 'update', file_path: changelog_file.split(repo.workdir).last, content: new_content }] obj = vcs_create_commit(source, branch, , actions) obj.id if obj else add_file(changelog_file) create_commit() end end |
#empty_changelog_contents ⇒ Object
26 27 28 |
# File 'lib/release_manager/changelog.rb', line 26 def empty_changelog_contents "# #{module_name}\n\n## Unreleased\n" end |
#get_unreleased_content ⇒ Array
Returns - array of lines of the unreleased content, text between unreleased and next version.
84 85 86 87 88 |
# File 'lib/release_manager/changelog.rb', line 84 def get_unreleased_content unreleased_index start_content = changelog_lines.slice((unreleased_index + 1), changelog_lines.count) start_content.slice_when {|a,b| b.downcase.start_with?('## version') }.map {|d| d}.first end |
#get_version_content(version) ⇒ Array
-
returns empty string if version is not found
Returns - array of lines of the specified version content, text between specified version and next version.
93 94 95 96 97 98 |
# File 'lib/release_manager/changelog.rb', line 93 def get_version_content(version) start_index = changelog_lines.find_index {|line| line.downcase.include?("version #{version}") } return nil unless start_index start_content = changelog_lines.slice((start_index + 1), changelog_lines.count) start_content.slice_when {|a,b| b.downcase.start_with?('## version') }.map {|d| d}.first end |
#module_name ⇒ Object
30 31 32 |
# File 'lib/release_manager/changelog.rb', line 30 def module_name ['name'] end |
#new_content ⇒ Object
107 108 109 |
# File 'lib/release_manager/changelog.rb', line 107 def new_content update_unreleased.join end |
#path ⇒ Object
34 35 36 |
# File 'lib/release_manager/changelog.rb', line 34 def path @root_dir end |
#run(remote = false, branch = 'master') ⇒ String
Create the changelog entries and commit
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/release_manager/changelog.rb', line 41 def run(remote = false, branch = 'master') if already_released? logger.fatal "Version #{version} had already been released, did you bump the version manually?" exit 1 end File.write(changelog_file, new_content) unless remote id = commit_changelog(nil, remote, branch) if [:commit] logger.info "The changelog has been updated to version #{version}" id end |
#unreleased_index ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/release_manager/changelog.rb', line 67 def unreleased_index begin linenum = changelog_lines.each_index.find {|index| changelog_lines[index] =~ /\A\s*\#{2}\s*Unreleased/i } rescue ArgumentError => e logger.fatal "Error with CHANGELOG.md #{e.}" exit 1 end raise NoUnreleasedLine unless linenum linenum end |
#update_unreleased ⇒ Object
101 102 103 104 |
# File 'lib/release_manager/changelog.rb', line 101 def update_unreleased time = Time.now.strftime("%B %d, %Y") changelog_lines.insert(unreleased_index + 1, "\n## Version #{version}\nReleased: #{time}\n") end |