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.
46 47 48 49 50 51 52 |
# File 'lib/stove/cookbook.rb', line 46 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.
35 36 37 |
# File 'lib/stove/cookbook.rb', line 35 def @metadata end |
#name ⇒ String (readonly)
The name of the cookbook (must correspond to the name of the cookbook on the community site).
20 21 22 |
# File 'lib/stove/cookbook.rb', line 20 def name @name end |
#new_version ⇒ String (readonly)
The new version of the cookbook.
30 31 32 |
# File 'lib/stove/cookbook.rb', line 30 def new_version @new_version end |
#options ⇒ Hash (readonly)
The list of options passed to the cookbook.
40 41 42 |
# File 'lib/stove/cookbook.rb', line 40 def @options end |
#path ⇒ String (readonly)
The path to this cookbook.
14 15 16 |
# File 'lib/stove/cookbook.rb', line 14 def path @path end |
#version ⇒ String (readonly)
The version of this cookbook (originally).
25 26 27 |
# File 'lib/stove/cookbook.rb', line 25 def version @version end |
Instance Method Details
#category ⇒ String
The category for this cookbook on the community site.
57 58 59 60 61 |
# File 'lib/stove/cookbook.rb', line 57 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.
192 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 |
# File 'lib/stove/cookbook.rb', line 192 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
88 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 |
# File 'lib/stove/cookbook.rb', line 88 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
71 72 73 74 75 76 77 78 |
# File 'lib/stove/cookbook.rb', line 71 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.
180 181 182 183 184 185 186 187 |
# File 'lib/stove/cookbook.rb', line 180 def repository_url @repository_url ||= git("config --get remote.#{[:remote]}.url") .strip .gsub(/\.git$/, '') .gsub(':', '/') .gsub('@', '://') .gsub('git://', 'https://') end |
#tag_version ⇒ Object
154 155 156 |
# File 'lib/stove/cookbook.rb', line 154 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…
162 163 164 165 166 167 168 169 |
# File 'lib/stove/cookbook.rb', line 162 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.
83 84 85 |
# File 'lib/stove/cookbook.rb', line 83 def unreleased_tickets @unreleased_tickets ||= Stove::JIRA.unreleased_tickets_for(name) end |
#upload ⇒ Object
172 173 174 |
# File 'lib/stove/cookbook.rb', line 172 def upload Stove::Uploader.new(self).upload! end |
#url ⇒ String
The URL for the cookbook on the Community Site.
66 67 68 |
# File 'lib/stove/cookbook.rb', line 66 def url "#{Stove::CommunitySite.http_uri}/cookbooks/#{name}" end |