lib/orgupdatematrix.rb in orgupdatematrix-0.1.2 vs lib/orgupdatematrix.rb in orgupdatematrix-0.2.0

- old
+ new

@@ -18,40 +18,46 @@ def log(message, indent = 6) puts("#{' ' * indent}#{message}") end - def update(app, stage, branch, commit, app_url, repo_url, extras = nil) - file = get_file_contents + def sort_data(hash) + hash.sort.to_h.each { |app, stage| hash[app] = stage.sort.to_h } + end + + def update_yaml(file, app, stage, state) data = YAML::load(Base64.decode64(file.content)) + data[app] ||= {} + data[app][stage] = state + sort_data(data) + end + def update(app, stage, branch, commit, app_url, repo_url, extras = nil) app = app.to_s stage = stage.to_s state = { 'branch' => branch.to_s, 'commit' => commit, 'updated' => Time.now.utc.to_s, 'app_url' => app_url, - 'github_url' => repo_url.gsub('git@', 'https://').gsub(':', '/'), + 'github_url' => repo_url.gsub('git@', 'https://').gsub(/(\w):(\w)/, '\1/\2'), } + state['extras'] = extras if extras - data[app] ||= {} - data[app][stage] = state - data[app][stage]['extras'] = extras if extras - log("app: #{app}", 9) log("stage: #{stage}", 9) state.each { |key, value| log("#{key}: #{value}", 9) } + message = "update deploy matrix: #{app}:#{stage}" Octopoller.poll(wait: :exponentially, retries: 6) do begin - message = "update deploy matrix: #{app}:#{stage}" + file = get_file_contents + data = update_yaml(file, app, stage, state) result = @client.update_contents(@repo, @file_path, message, file[:sha], data.to_yaml) log('Update complete!') if result[:commit] rescue StandardError => e log("Error: #{e.message}") log('Retrying with latest commit...') - file = get_file_contents :re_poll end end end end