knife-github-cookbooks 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,158 @@
1
+ knife-github-cookbooks
2
+ ======================
3
+
4
+ Description
5
+ -----------
6
+
7
+ A knife plugin facilitating installing, updating, and tracking Chef cookbooks
8
+ found on Github.
9
+
10
+ Installation
11
+ ------------
12
+
13
+ gem install knife-github-cookbooks
14
+
15
+ Motivation
16
+ ----------
17
+
18
+ The current "repo of cookbooks" pattern of sharing neglects Chef's core unit
19
+ of currency: the cookbook. Excellent cookbooks that developers have labored
20
+ over for hours are lost in the sea of forks of `opscode/cookbooks`, hidden
21
+ from the prying eyes of Google. Just look at this mess:
22
+
23
+ https://github.com/opscode/cookbooks/network/members
24
+
25
+ There's also the Opscode Community, which presents users with a cookbook, but
26
+ no way to see what it contains without downloading a tarball. This feels
27
+ vauguely like ... SourceForge.
28
+
29
+ For pete's sake, folks, I thought this was DevOps! I'm a developer. I spend
30
+ hours on Github everyday. Cookbooks should be individual Github repos, with
31
+ all of the bells and whistles that come along with it. The network graph! Pull
32
+ requests! Issues! The tools of a developer! Tarballs? Tarballs are what a
33
+ smelly sysadmin downloads between games of Quake.
34
+
35
+ The hedgehog knows what I'm talking about:
36
+
37
+ https://github.com/cookbooks
38
+
39
+ And this:
40
+
41
+ https://github.com/papercavalier/mongodb-cookbook/network
42
+
43
+ Usage
44
+ -----
45
+
46
+ ### Installing Cookbooks
47
+
48
+ Say you wanted to install the `yum` cookbook located at
49
+ https://github.com/cookbooks/yum. To do so, you'd run the following command:
50
+
51
+ knife cookbook github install cookbooks/yum
52
+
53
+ The repo at https://github.com/cookbooks/yum will be cloned into a temporary
54
+ directory, moved into `cookbooks/yum` using the familiar vendor branch
55
+ pattern, and the resulting files committed into the repo with a log message
56
+ like so:
57
+
58
+ Import cookbooks/yum version 8c6f4082482b5f9d93e9b8256c23a7add03aa0fb
59
+
60
+ By default, the public `git://` URI will be used. To clone a private repo via
61
+ the `git@` URI, pass the `-S` option:
62
+
63
+ knife cookbook github install my_stealthy_startup/secret_sauce -S
64
+
65
+ ### Tracking Cookbook Changes
66
+
67
+ Say you've seen some activity on one of the cookbooks you're using and you
68
+ want to see what's new. There's magic for that too! Say you installed
69
+ papercavalier's mongodb cookbook on May 1st, and want to see what's new. When
70
+ you run the following command:
71
+
72
+ knife cookbook github compare mongodb
73
+
74
+ The local git log will be parsed to see what revision the cookbook was at when
75
+ it was installed, and the Github compare view will be launched:
76
+
77
+ https://github.com/papercavalier/mongodb-cookbook/compare/9d413996b3db93f94bafc462e6dbdb092fac534a...master
78
+
79
+ If you want to get up to date, another quick call to the install command will
80
+ get the cookbook updated:
81
+
82
+ knife cookbook github install papercavalier/mongodb-cookbook
83
+
84
+ But wait! Say you've noticed that someone (in this case, `erkki`) has forked
85
+ the mongo cookbook. To see what they've added, just run the following:
86
+
87
+ knife cookbook github compare mongodb erkki
88
+
89
+ https://github.com/papercavalier/mongodb-cookbook/compare/9d413996b3db93f94bafc462e6dbdb092fac534a...erkki:master
90
+
91
+ ### Working with branches other than master
92
+
93
+ If someone's made changes in another branch, you can compare the changes like
94
+ so:
95
+
96
+ knife cookbook github compare mongodb jnewland/fix-bug
97
+
98
+ Then install those changes like so:
99
+
100
+ knife cookbook github install jnewland/mongodb/fix-bug
101
+
102
+ Epic. The tools of a developer.
103
+
104
+ Conventions
105
+ -----------
106
+
107
+ This plugin only supports installing repositories that contain a single
108
+ repository at the top-level. I do not plan to support installing cookbooks
109
+ contained in a repository like `opscode/cookbooks`, because I feel this
110
+ is a broken pattern for storing and sharing cookbooks.
111
+
112
+ If the repo you're trying to install is prefixed or suffixed with `chef`
113
+ and/or `cookbook`, this will be stripped from the repo name. For example,
114
+ running:
115
+
116
+ knife cookbook github install my_stealthy_startup/chef-nosql_cookbook
117
+
118
+ ...will create the cookbook in the `cookbooks/nosql` directory.
119
+
120
+ Caveats
121
+ -------
122
+
123
+ This plugin does not support automatically fetching cookbook dependencies,
124
+ since version constraints are numeric and cookbook names can't specify the
125
+ Github user. If you have an clever ideas for how this should work, hit me up.
126
+
127
+ Requirements
128
+ ------------
129
+
130
+ * `git`
131
+ * `chef ~> 0.10.0`
132
+
133
+ Author
134
+ ------
135
+
136
+ Jesse Newland
137
+ jesse@websterclay.com
138
+ @jnewland
139
+ jnewland on freenode
140
+
141
+ License
142
+ -------
143
+
144
+ Author:: Jesse Newland (<jesse@websterclay.com>)
145
+ Copyright:: Copyright (c) 2011 Webster Clay, LLC
146
+ License:: Apache License, Version 2.0
147
+
148
+ Licensed under the Apache License, Version 2.0 (the "License");
149
+ you may not use this file except in compliance with the License.
150
+ You may obtain a copy of the License at
151
+
152
+ http://www.apache.org/licenses/LICENSE-2.0
153
+
154
+ Unless required by applicable law or agreed to in writing, software
155
+ distributed under the License is distributed on an "AS IS" BASIS,
156
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
157
+ See the License for the specific language governing permissions and
158
+ limitations under the License.
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "knife-github-cookbooks/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "knife-github-cookbooks"
7
+ s.version = Knife::GithubCookbooks::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = false
10
+ s.extra_rdoc_files = ["LICENSE" ]
11
+ s.authors = ["Jesse Newland"]
12
+ s.email = ["jesse@websterclay.com"]
13
+ s.homepage = "https://github.com/websterclay/knife-github-cookbooks"
14
+ s.summary = %q{Github Cookbook installation support for Chef's Knife Command}
15
+ s.description = s.summary
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "launchy", "~> 0.4.0"
22
+ s.add_dependency "chef", "~> 0.10.0"
23
+ end
@@ -0,0 +1,107 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Jesse Newland (<jesse@websterclay.com>)
4
+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
5
+ # Copyright:: Copyright (c) 2011 Webster Clay, LLC.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'chef/knife'
22
+
23
+ class Chef
24
+ class Knife
25
+
26
+ class CookbookGithubCompare < Knife
27
+
28
+ deps do
29
+ require 'chef/mixin/shell_out'
30
+ require 'chef/knife/core/cookbook_scm_repo'
31
+ require File.join(File.dirname(__FILE__), 'core', 'coobook_scm_repo_extensions')
32
+ end
33
+
34
+ banner "knife cookbook github compare COOKBOOK [USER/BRANCH] (options)"
35
+ category "cookbook site"
36
+
37
+ option :cookbook_path,
38
+ :short => "-o PATH:PATH",
39
+ :long => "--cookbook-path PATH:PATH",
40
+ :description => "A colon-separated path to look for cookbooks in",
41
+ :proc => lambda { |o| o.split(":") }
42
+
43
+ attr_reader :cookbook_name
44
+ attr_reader :github_path
45
+ attr_reader :current_sha
46
+
47
+ def run
48
+ extend Chef::Mixin::ShellOut
49
+
50
+ if config[:cookbook_path]
51
+ Chef::Config[:cookbook_path] = config[:cookbook_path]
52
+ else
53
+ config[:cookbook_path] = Chef::Config[:cookbook_path]
54
+ end
55
+
56
+ @cookbook_name = parse_name_args!
57
+
58
+ @install_path = config[:cookbook_path].first
59
+
60
+ @repo = CookbookSCMRepoExtensions.new(@install_path, ui, config)
61
+
62
+ match = @repo.last_log_message_from_cookbook(@cookbook_name).match("Import (.*) version (.*)")
63
+ @github_path = match[1]
64
+ @current_sha = match[2]
65
+ visit_or_print(compare_uri)
66
+ end
67
+
68
+ def visit_or_print(url)
69
+ STDOUT.puts url
70
+ begin
71
+ gem 'launchy'
72
+ require 'launchy'
73
+ Launchy::Browser.new.visit url
74
+ rescue Gem::LoadError
75
+ STDERR.puts "Install launchy to automatically open this in the future: `gem install launchy`"
76
+ end
77
+ end
78
+
79
+ def parse_name_args!
80
+ if name_args.empty?
81
+ ui.error("please specify a cookbook to download and install")
82
+ exit 1
83
+ elsif name_args.size > 2
84
+ ui.error("USAGE: knife cookbook github compare COOKBOOK [USER/BRANCH] (options)")
85
+ exit 1
86
+ else
87
+ name_args.first
88
+ end
89
+ end
90
+
91
+ def compare_uri
92
+ "https://github.com/#{@github_path}/compare/#{@current_sha}...#{user_and_branch}"
93
+ end
94
+
95
+ def user_and_branch
96
+ if name_args.size > 1
97
+ user, branch = name_args.last.split(/[:\/]/)
98
+ branch ||= 'master'
99
+ "#{user}:#{branch}"
100
+ else
101
+ 'master'
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,151 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Jesse Newland (<jesse@websterclay.com>)
4
+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
5
+ # Copyright:: Copyright (c) 2011 Webster Clay, LLC.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'chef/knife'
22
+
23
+ class Chef
24
+ class Knife
25
+
26
+ class CookbookGithubInstall < Knife
27
+
28
+ deps do
29
+ require 'chef/mixin/shell_out'
30
+ require 'chef/knife/core/cookbook_scm_repo'
31
+ require File.join(File.dirname(__FILE__), 'core', 'coobook_scm_repo_extensions')
32
+ end
33
+
34
+ banner "knife cookbook github install USER/REPO [USER/REPO/BRANCH] (options)"
35
+ category "cookbook site"
36
+
37
+ option :ssh,
38
+ :short => "-S",
39
+ :long => "--ssh",
40
+ :boolean => true,
41
+ :description => "Use the git@ style url. Defaults to true if $USER matches user/repo"
42
+
43
+ option :cookbook_path,
44
+ :short => "-o PATH:PATH",
45
+ :long => "--cookbook-path PATH:PATH",
46
+ :description => "A colon-separated path to look for cookbooks in",
47
+ :proc => lambda { |o| o.split(":") }
48
+
49
+ option :default_branch,
50
+ :short => "-B BRANCH",
51
+ :long => "--branch BRANCH",
52
+ :description => "Default branch to work with",
53
+ :default => "master"
54
+
55
+ attr_reader :github_user
56
+ attr_reader :github_repo
57
+ attr_reader :github_branch
58
+ attr_reader :cookbook_name
59
+
60
+ def run
61
+ extend Chef::Mixin::ShellOut
62
+
63
+ if config[:cookbook_path]
64
+ Chef::Config[:cookbook_path] = config[:cookbook_path]
65
+ else
66
+ config[:cookbook_path] = Chef::Config[:cookbook_path]
67
+ end
68
+
69
+ parse_name_args!
70
+
71
+ @install_path = config[:cookbook_path].first
72
+ ui.info "Installing #@cookbook_name from #{github_uri} to #{@install_path}"
73
+
74
+ @repo = CookbookSCMRepoExtensions.new(@install_path, ui, config)
75
+
76
+ @repo.sanity_check
77
+ @repo.reset_to_default_state
78
+ @repo.prepare_to_import(@cookbook_name)
79
+
80
+ clone_cookbook
81
+ clear_existing_files(File.join(@install_path, @cookbook_name))
82
+ move_cookbook
83
+
84
+ if @repo.finalize_updates_from_github(@cookbook_name, "#{@github_user}/#{@github_repo}", sha)
85
+ @repo.reset_to_default_state
86
+ @repo.merge_updates_from(@cookbook_name, sha)
87
+ else
88
+ @repo.reset_to_default_state
89
+ end
90
+ end
91
+
92
+ def parse_name_args!
93
+ if name_args.empty?
94
+ ui.error("please specify a cookbook to download and install")
95
+ exit 1
96
+ elsif name_args.size > 1
97
+ ui.error("Usage: knife cookbook github install USER/REPO [USER/REPO/BRANCH] (options)")
98
+ exit 1
99
+ else
100
+ @github_user, @github_repo, @github_branch = name_args.first.split('/')
101
+ unless @github_user && @github_repo
102
+ ui.error("Expected a github user and a repo to download from: jnewland/chef_ipmi")
103
+ exit 1
104
+ end
105
+ @cookbook_name = @github_repo.gsub(/[_-]?chef[-_]?/, '').gsub(/[_-]?cookbook[-_]?/, '')
106
+ end
107
+ end
108
+
109
+ def temp_clone_path
110
+ "_tmp_chef_#{@cookbook_name}"
111
+ end
112
+
113
+ def tmpdir
114
+ ENV['TMPDIR']
115
+ end
116
+
117
+ def clone_cookbook
118
+ shell_out!("rm -rf #{temp_clone_path}", :cwd => tmpdir) if File.exists?(File.join(tmpdir, temp_clone_path))
119
+ shell_out!("git clone #{github_uri} #{temp_clone_path}", :cwd => tmpdir)
120
+ shell_out!("git checkout #{github_branch}", :cwd => File.join(tmpdir, temp_clone_path))
121
+ shell_out!("rm -rf .git", :cwd => File.join(tmpdir, temp_clone_path))
122
+ end
123
+
124
+ def move_cookbook
125
+ shell_out!("mv #{temp_clone_path} #{File.join(@install_path, @cookbook_name)}", :cwd => tmpdir)
126
+ end
127
+
128
+ def clear_existing_files(cookbook_path)
129
+ ui.info("Removing pre-existing version.")
130
+ shell_out!("rm -r #{cookbook_path}", :cwd => @install_path) if File.directory?(cookbook_path)
131
+ end
132
+
133
+ def github_uri
134
+ if config[:ssh] || @github_user == ENV['USER']
135
+ "git@github.com:#{@github_user}/#{@github_repo}.git"
136
+ else
137
+ "git://github.com/#{@github_user}/#{@github_repo}.git"
138
+ end
139
+ end
140
+
141
+ def sha
142
+ @sha ||= noauth_rest.get_rest("http://github.com/api/v2/json/repos/show/#{@github_user}/#{@github_repo}/branches")['branches'][github_branch]
143
+ end
144
+
145
+ def github_branch
146
+ @github_branch ||= 'master'
147
+ end
148
+
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,25 @@
1
+ class Chef
2
+ class Knife
3
+ class CookbookSCMRepoExtensions < CookbookSCMRepo
4
+
5
+ def finalize_updates_from_github(cookbook_name, github_path, sha)
6
+ if update_count = updated?(cookbook_name)
7
+ ui.info "#{update_count} files updated, committing changes"
8
+ git("add #{cookbook_name}")
9
+ git("commit -m 'Import #{github_path} version #{sha}' -- #{cookbook_name}")
10
+ ui.info("Creating tag cookbook-site-imported-#{cookbook_name}-#{sha}")
11
+ git("tag -f cookbook-site-imported-#{cookbook_name}-#{sha}")
12
+ true
13
+ else
14
+ ui.info("No changes made to #{cookbook_name}")
15
+ false
16
+ end
17
+ end
18
+
19
+ def last_log_message_from_cookbook(cookbook_name)
20
+ git("log chef-vendor-#{cookbook_name} -n 1").stdout.split("\n").last.strip
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ module Knife
2
+ module GithubCookbooks
3
+ VERSION = "0.1.3"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-github-cookbooks
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 3
10
+ version: 0.1.3
11
+ platform: ruby
12
+ authors:
13
+ - Jesse Newland
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-11 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: launchy
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 0
34
+ version: 0.4.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: chef
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 55
46
+ segments:
47
+ - 0
48
+ - 10
49
+ - 0
50
+ version: 0.10.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Github Cookbook installation support for Chef's Knife Command
54
+ email:
55
+ - jesse@websterclay.com
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - LICENSE
62
+ files:
63
+ - .gitignore
64
+ - LICENSE
65
+ - README.md
66
+ - knife-github-cookbooks.gemspec
67
+ - lib/chef/knife/cookbook_github_compare.rb
68
+ - lib/chef/knife/cookbook_github_install.rb
69
+ - lib/chef/knife/core/coobook_scm_repo_extensions.rb
70
+ - lib/knife-github-cookbooks/version.rb
71
+ has_rdoc: true
72
+ homepage: https://github.com/websterclay/knife-github-cookbooks
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.6.2
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Github Cookbook installation support for Chef's Knife Command
105
+ test_files: []
106
+