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



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

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.



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

def 
  @metadata
end

#nameString (readonly)

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

Returns:

  • (String)


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

def name
  @name
end

#new_versionString (readonly)

The new version of the cookbook.

Returns:

  • (String)


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

def new_version
  @new_version
end

#optionsHash (readonly)

The list of options passed to the cookbook.

Returns:

  • (Hash)


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

def options
  @options
end

#pathString (readonly)

The path to this cookbook.

Returns:

  • (String)


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

def path
  @path
end

#versionString (readonly)

The version of this cookbook (originally).

Returns:

  • (String)


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

def version
  @version
end

Instance Method Details

#categoryString

The category for this cookbook on the community site.

Returns:

  • (String)


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

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)


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 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



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 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)


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_urlString

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

Returns:

  • (String)


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

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

#tag_versionObject



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

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)


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

The unreleased JIRA tickets for this cookbook.

Returns:

  • (Hashie::Dash, Array)


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

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

#uploadObject



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

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

#urlString

The URL for the cookbook on the Community Site.

Returns:

  • (String)


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

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