Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-doing Bump_comment for version 1.4 #145

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ role_path: "/home/me/roles"
custom_plugin_path: "/home/me/spork-plugins"
always_promote_remote: true
skip_berkshelf: false
bump_config: true
json_options:
indent: " "
plugins:
Expand Down Expand Up @@ -121,6 +122,9 @@ The `always_promote_remote` directive allows you to tell spork promote to always
#### Skip Berkshelf
The `skip_berkshelf` directive is a temporary flag added in [#138](https://github.com/jonlives/knife-spork/issues/138) to allow Berkshelf functionality to be optionally bypassed until Berkshelf 3 support has been added to knife-spork per [#85](https://github.com/jonlives/knife-spork/issues/85). It simply removed the :Berkshelf constant from the namespace used by knife-spork.

#### Bump Comment
The 'bump_comment` directive tells spork to always prompt the user for a comment reguarding the changes to this version of the cookbook. This comment will be appended to the CHANGELOG.md file along with the new version # and the user name. This can also be done with the "--bump_comment" on the command line.

#### JSON Options
The `json_options` directive allows you to tell spork to pass options to [pretty_generate](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/json/rdoc/JSON.html#method-i-pretty_generate) to control the format of the resulting json

Expand Down Expand Up @@ -236,18 +240,28 @@ Everything looks good!

Spork Bump
----------
This function lets you easily version your cookbooks without having to manually edit the cookbook's `metadata.rb` file. You can either specify the version level you'd like to bump (`major`, `minor`, or `patch`), or you can manually specify a version number. This might be used if, for example, you want to jump several version numbers in one go and don't want to have to run knife bump once for each number. If no bump level is specified, a patch level bump will be performed.
This function lets you easily version your cookbooks without having to manually edit the cookbook's `metadata.rb` & `CHANGELOG.md` files. You can either specify the version level you'd like to bump (`major`, `minor`, or `patch`), or you can manually specify a version number. This might be used if, for example, you want to jump several version numbers in one go and don't want to have to run knife bump once for each number. If no bump level is specified, a patch level bump will be performed.

Spork Bump can also be configured promt the user for a comment reguarding thier change. This comment will be appended to the CHANGELOG.md file along with the new version, and the current username. This is done either by using the '--bump_comment' option on the command line or by setting the bump_comment: directive to true.

#### Usage
```bash
knife spork bump COOKBOOK [major | minor | patch | manual x.x.x]
knife spork bump COOKBOOK [major | minor | patch | manual x.x.x] [--bump_commment]
````

#### Example (No patch level specified - defaulting to patch)
```text
$ knife spork bump apache2
$ knife spork bump apache2 --bump_comment
Enter Change Log comment, then press Ctrl-D:
"Bug #111 fixed."
Successfully bumped apache2 to v2.0.4!
```
``` CHANGELOG.md will be appended with the following:

2.0.4
------
<user> - Bug #111 fixed.
```

#### Example (Bumping patch level)
```text
Expand Down
19 changes: 18 additions & 1 deletion lib/chef/knife/spork-bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class SporkBump < Chef::Knife
:description => 'A colon-separated path to look for cookbooks in',
:proc => lambda { |o| o.split(':') }

option :bump_comment,
:long => '--bump_comment',
:description => 'Bump will prompt for a Change comment, which will be appended to CHANGELOG.md along with the new version # and username',
:default => nil

if defined?(::Berkshelf)
option :berksfile,
:short => '-b',
Expand All @@ -29,12 +34,13 @@ class SporkBump < Chef::Knife
:default => true
end

banner 'knife spork bump COOKBOOK [major|minor|patch|manual]'
banner 'knife spork bump COOKBOOK [major|minor|patch|manual] [--bump_comment]'

def run
self.class.send(:include, KnifeSpork::Runner)
self.config = Chef::Config.merge!(config)
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
config[:bump_comment] ||= spork_config.bump_comment

if @name_args.empty?
show_usage
Expand Down Expand Up @@ -78,6 +84,17 @@ def bump
new_contents = File.read(metadata_file).gsub(/(version\s+['"])[0-9\.]+(['"])/, "\\1#{new_version}\\2")
File.open(metadata_file, 'w'){ |f| f.write(new_contents) }

if config[:bump_comment]
changelog_file = "#{@cookbook.root_dir}/CHANGELOG.md"
ui.info "Enter Change Log comment, then press Ctrl-D: "
change_comment = $stdin.read
File.open(changelog_file, 'a') { |cl|
cl.write("\n#{new_version}\n")
cl.write("---------\n")
cl.write("#{ENV['USER']} - #{change_comment}\n")
}
end

ui.info "Successfully bumped #{@cookbook.name} to v#{new_version}!"
end

Expand Down
1 change: 1 addition & 0 deletions lib/knife-spork/plugins/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def before_promote
def after_bump
cookbooks.each do |cookbook|
git_add(cookbook_path_for(cookbook),"metadata.rb")
git_add(cookbook_path_for(cookbook),"CHANGELOG.md")
end
end

Expand Down
4 changes: 4 additions & 0 deletions lib/knife-spork/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ def all_cookbooks
::Chef::CookbookLoader.new(::Chef::Config.cookbook_path)
end

def bump_comment
spork_config[:bump_comment] || false
end

def load_cookbook(name)
return name if name.is_a?(Chef::CookbookVersion)

Expand Down