Class: Stove::Cookbook
- Inherits:
-
Object
- Object
- Stove::Cookbook
- Includes:
- Git
- Defined in:
- lib/stove/cookbook.rb,
lib/stove/cookbook/metadata.rb
Defined Under Namespace
Classes: Metadata
Instance Attribute Summary collapse
-
#metadata ⇒ Stove::Cookbook::Metadata
readonly
The metadata for this cookbook.
-
#name ⇒ String
readonly
The name of the cookbook (must correspond to the name of the cookbook on the community site).
-
#new_version ⇒ String
readonly
The new version of the cookbook.
-
#options ⇒ Hash
readonly
The list of options passed to the cookbook.
-
#path ⇒ String
readonly
The path to this cookbook.
-
#version ⇒ String
readonly
The version of this cookbook (originally).
Instance Method Summary collapse
-
#category ⇒ String
The category for this cookbook on the community site.
-
#changeset ⇒ String
The set of changes for this diff/patch in markdown format.
-
#initialize(options = {}) ⇒ Cookbook
constructor
Create a new wrapper around the cookbook object.
- #release! ⇒ Object
-
#released? ⇒ Boolean
Deterine if this cookbook version is released on the community site.
-
#repository_url ⇒ String
The URL for this repository on GitHub.
- #tag_version ⇒ Object
-
#tarball ⇒ File
So there’s this really really crazy bug that the tmp directory could be deleted mid-request…
-
#unreleased_tickets ⇒ Hashie::Dash, Array
The unreleased JIRA tickets for this cookbook.
- #upload ⇒ Object
-
#url ⇒ String
The URL for the cookbook on the Community Site.
Methods included from Git
#git, #git_remote_uptodate?, #git_repo?, #git_repo_clean?, #shellout
Constructor Details
#initialize(options = {}) ⇒ Cookbook
Create a new wrapper around the cookbook object.
47 48 49 50 51 52 53 |
# File 'lib/stove/cookbook.rb', line 47 def initialize( = {}) @path = [:path] || Dir.pwd @new_version = [:new_version] @options = end |
Instance Attribute Details
#metadata ⇒ Stove::Cookbook::Metadata (readonly)
The metadata for this cookbook.
36 37 38 |
# File 'lib/stove/cookbook.rb', line 36 def @metadata end |
#name ⇒ String (readonly)
The name of the cookbook (must correspond to the name of the cookbook on the community site).
21 22 23 |
# File 'lib/stove/cookbook.rb', line 21 def name @name end |
#new_version ⇒ String (readonly)
The new version of the cookbook.
31 32 33 |
# File 'lib/stove/cookbook.rb', line 31 def new_version @new_version end |
#options ⇒ Hash (readonly)
The list of options passed to the cookbook.
41 42 43 |
# File 'lib/stove/cookbook.rb', line 41 def @options end |
#path ⇒ String (readonly)
The path to this cookbook.
15 16 17 |
# File 'lib/stove/cookbook.rb', line 15 def path @path end |
#version ⇒ String (readonly)
The version of this cookbook (originally).
26 27 28 |
# File 'lib/stove/cookbook.rb', line 26 def version @version end |
Instance Method Details
#category ⇒ String
The category for this cookbook on the community site.
58 59 60 61 62 |
# File 'lib/stove/cookbook.rb', line 58 def category @category ||= [:category] || Stove::CommunitySite.cookbook(name)['category'] rescue raise Stove::CookbookCategoryNotFound end |
#changeset ⇒ String
The set of changes for this diff/patch in markdown format.
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 |
# File 'lib/stove/cookbook.rb', line 193 def changeset return @changeset if @changeset contents = [] contents << "v#{version}" contents << '-'*(version.length+1) if [:jira] by_type = unreleased_tickets.inject({}) do |hash, ticket| issue_type = ticket.fields.current['issuetype']['name'] hash[issue_type] ||= [] hash[issue_type] << { number: ticket.jira_key, details: ticket.fields.current['summary'], } hash end by_type.each do |issue_type, tickets| contents << "### #{issue_type}" tickets.sort { |a,b| b[:number].to_i <=> a[:number].to_i }.each do |ticket| contents << "- **[#{ticket[:number]}](#{Stove::JIRA::JIRA_URL}/browse/#{ticket[:number]})** - #{ticket[:details]}" end contents << "" end else contents << "_Enter CHANGELOG for #{name} (#{version}) here_" contents << "" end @changeset = contents.join("\n") @changeset end |
#release! ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/stove/cookbook.rb', line 89 def release! if [:git] Stove::Logger.info "Running validations" validate_git_repo! validate_git_clean! validate_remote_updated! end Stove::Logger.info "Bumping version" version_bump if [:changelog] Stove::Logger.info "Updating changelog" update_changelog end if [:git] Dir.chdir(path) do Stove::Logger.info "Committing git changes in '#{path}'" git "add metadata.rb" git "add CHANGELOG.md" git "commit -m 'Version bump to #{tag_version}'" git "push #{[:remote]} #{[:branch]}" if [:github] Stove::Logger.info "Pushing release to GitHub" Stove::GitHub.new(self).publish_release! else Stove::Logger.info "Tagging a release" git "tag #{tag_version}" git "push #{[:remote]} #{tag_version}" end end end if [:upload] Stove::Logger.info "Uploading cookbook" retryable(tries: 3) do upload end end if [:jira] Stove::Logger.info "Resolving JIRA issues" resolve_jira_issues end if [:devodd] Stove::Logger.info "Bumping devodd release" split = version.split('.').map(&:to_i) split[2] += 1 devodd = split.join('.') version_bump(devodd) if [:git] Dir.chdir(path) do git "add metadata.rb" git "commit -m 'Version bump to #{tag_version}'" git "push #{[:remote]} #{[:branch]}" end end end end |
#released? ⇒ Boolean
Deterine if this cookbook version is released on the community site
72 73 74 75 76 77 78 79 |
# File 'lib/stove/cookbook.rb', line 72 def released? @_released ||= begin Stove::CommunitySite.cookbook(name, version) true rescue Stove::BadResponse false end end |
#repository_url ⇒ String
The URL for this repository on GitHub. This method automatically translates SSH and git:// URLs to https:// URLs.
181 182 183 184 185 186 187 188 |
# File 'lib/stove/cookbook.rb', line 181 def repository_url @repository_url ||= git("config --get remote.#{[:remote]}.url") .strip .gsub(/\.git$/, '') .gsub(':', '/') .gsub('@', '://') .gsub('git://', 'https://') end |
#tag_version ⇒ Object
155 156 157 |
# File 'lib/stove/cookbook.rb', line 155 def tag_version "v#{version}" end |
#tarball ⇒ File
So there’s this really really crazy bug that the tmp directory could be deleted mid-request…
163 164 165 166 167 168 169 170 |
# File 'lib/stove/cookbook.rb', line 163 def tarball return @tarball if @tarball && File.exists?(@tarball) begin @tarball = Stove::Packager.new(self).package_path end until File.exists?(@tarball) @tarball end |
#unreleased_tickets ⇒ Hashie::Dash, Array
The unreleased JIRA tickets for this cookbook.
84 85 86 |
# File 'lib/stove/cookbook.rb', line 84 def unreleased_tickets @unreleased_tickets ||= Stove::JIRA.unreleased_tickets_for(name) end |
#upload ⇒ Object
173 174 175 |
# File 'lib/stove/cookbook.rb', line 173 def upload Stove::Uploader.new(self).upload! end |
#url ⇒ String
The URL for the cookbook on the Community Site.
67 68 69 |
# File 'lib/stove/cookbook.rb', line 67 def url "#{Stove::CommunitySite.http_uri}/cookbooks/#{name}" end |