Class: Stove::Cookbook

Inherits:
Object
  • Object
show all
Includes:
Git
Defined in:
lib/stove/cookbook.rb,
lib/stove/cookbook/metadata.rb

Defined Under Namespace

Classes: Metadata

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • options (Hash) (defaults to: {})

    the list of options



47
48
49
50
51
52
53
# File 'lib/stove/cookbook.rb', line 47

def initialize(options = {})
  @path = options[:path] || Dir.pwd
  @new_version = options[:new_version]
  @options = options

  load_metadata!
end

Instance Attribute Details

#metadataStove::Cookbook::Metadata (readonly)

The metadata for this cookbook.



36
37
38
# File 'lib/stove/cookbook.rb', line 36

def 
  @metadata
end

#nameString (readonly)

The name of the cookbook (must correspond to the name of the cookbook on the community site).

Returns:

  • (String)


21
22
23
# File 'lib/stove/cookbook.rb', line 21

def name
  @name
end

#new_versionString (readonly)

The new version of the cookbook.

Returns:

  • (String)


31
32
33
# File 'lib/stove/cookbook.rb', line 31

def new_version
  @new_version
end

#optionsHash (readonly)

The list of options passed to the cookbook.

Returns:

  • (Hash)


41
42
43
# File 'lib/stove/cookbook.rb', line 41

def options
  @options
end

#pathString (readonly)

The path to this cookbook.

Returns:

  • (String)


15
16
17
# File 'lib/stove/cookbook.rb', line 15

def path
  @path
end

#versionString (readonly)

The version of this cookbook (originally).

Returns:

  • (String)


26
27
28
# File 'lib/stove/cookbook.rb', line 26

def version
  @version
end

Instance Method Details

#categoryString

The category for this cookbook on the community site.

Returns:

  • (String)


58
59
60
61
62
# File 'lib/stove/cookbook.rb', line 58

def category
  @category ||= options[:category] || Stove::CommunitySite.cookbook(name)['category']
rescue
  raise Stove::CookbookCategoryNotFound
end

#changesetString

The set of changes for this diff/patch in markdown format.

Returns:

  • (String)


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 options[: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 options[:git]
    Stove::Logger.info "Running validations"
    validate_git_repo!
    validate_git_clean!
    validate_remote_updated!
  end

  Stove::Logger.info "Bumping version"
  version_bump

  if options[:changelog]
    Stove::Logger.info "Updating changelog"
    update_changelog
  end

  if options[: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 #{options[:remote]} #{options[:branch]}"

      if options[: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 #{options[:remote]} #{tag_version}"
      end
    end
  end

  if options[:upload]
    Stove::Logger.info "Uploading cookbook"
    retryable(tries: 3) do
      upload
    end
  end

  if options[:jira]
    Stove::Logger.info "Resolving JIRA issues"
    resolve_jira_issues
  end

  if options[:devodd]
    Stove::Logger.info "Bumping devodd release"
    split = version.split('.').map(&:to_i)
    split[2] += 1
    devodd = split.join('.')

    version_bump(devodd)

    if options[:git]
      Dir.chdir(path) do
        git "add metadata.rb"
        git "commit -m 'Version bump to #{tag_version}'"
        git "push #{options[:remote]} #{options[:branch]}"
      end
    end
  end
end

#released?Boolean

Deterine if this cookbook version is released on the community site

Returns:

  • (Boolean)


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_urlString

The URL for this repository on GitHub. This method automatically translates SSH and git:// URLs to https:// URLs.

Returns:

  • (String)


181
182
183
184
185
186
187
188
# File 'lib/stove/cookbook.rb', line 181

def repository_url
  @repository_url ||= git("config --get remote.#{options[:remote]}.url")
                        .strip
                        .gsub(/\.git$/, '')
                        .gsub(':', '/')
                        .gsub('@', '://')
                        .gsub('git://', 'https://')
end

#tag_versionObject



155
156
157
# File 'lib/stove/cookbook.rb', line 155

def tag_version
  "v#{version}"
end

#tarballFile

So there’s this really really crazy bug that the tmp directory could be deleted mid-request…

Returns:

  • (File)


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_ticketsHashie::Dash, Array

The unreleased JIRA tickets for this cookbook.

Returns:

  • (Hashie::Dash, Array)


84
85
86
# File 'lib/stove/cookbook.rb', line 84

def unreleased_tickets
  @unreleased_tickets ||= Stove::JIRA.unreleased_tickets_for(name)
end

#uploadObject



173
174
175
# File 'lib/stove/cookbook.rb', line 173

def upload
  Stove::Uploader.new(self).upload!
end

#urlString

The URL for the cookbook on the Community Site.

Returns:

  • (String)


67
68
69
# File 'lib/stove/cookbook.rb', line 67

def url
  "#{Stove::CommunitySite.http_uri}/cookbooks/#{name}"
end