Class: Jets::CLI::Release::History

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/cli/release/history.rb

Direct Known Subclasses

Info

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #paginate, #paging_params, rescue_api_error

Methods included from Util::Logging

#log

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods included from Api

#api, #api_key

Constructor Details

This class inherits a constructor from Jets::CLI::Base

Instance Method Details

#format_time(string) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/jets/cli/release/history.rb', line 46

def format_time(string)
  if string.include?("ago") # IE: 5 minutes ago
    string
  else
    utc = DateTime.parse(string)

    tz_override = ENV["JETS_TZ"] # IE: America/Los_Angeles
    local = if tz_override
      tz = TZInfo::Timezone.get(tz_override)
      tz.utc_to_local(utc)
    else
      utc.new_offset(DateTime.now.offset) # local time
    end

    if tz_override
      local.strftime("%b %-d, %Y %-l:%M:%S%P")
    else
      local.strftime("%b %-d, %Y %H:%M:%S")
    end
  end
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jets/cli/release/history.rb', line 8

def run
  resp = Jets::Api::Stack.retrieve(:current)

  name = "#{resp[:name]} #{resp[:location]}"
  resp = Jets::Api::Release.list(@options)

  data = resp[:data]
  if data.empty?
    log.info "No releases found for stack: #{name}"
  else
    log.info "Releases for stack: #{name}"
    show_items(data)
    paginate(resp)
  end
end

#show_items(items) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jets/cli/release/history.rb', line 24

def show_items(items)
  presenter = CliFormat::Presenter.new(@options)
  header = ["Version", "Status", "Released At", "Message"]
  header << "Git Sha" if @options[:sha]
  presenter.header = header
  items.each do |item|
    version = item[:version]
    status = item[:stack_status]
    released_at = item[:pretty_created_at] || item[:created_at]
    message = item[:message] || "Deployed"
    message = message[0..50]

    row = [version, status, format_time(released_at), message]
    if @options[:sha]
      sha = item[:git_sha].to_s[0..7] if item[:git_sha]
      row << sha
    end
    presenter.rows << row
  end
  presenter.show
end