Class: Fastlane::Flint::Nuke

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/flint/helper/nuke.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filesObject

Returns the value of attribute files.



14
15
16
# File 'lib/fastlane/plugin/flint/helper/nuke.rb', line 14

def files
  @files
end

#paramsObject

Returns the value of attribute params.



11
12
13
# File 'lib/fastlane/plugin/flint/helper/nuke.rb', line 11

def params
  @params
end

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/fastlane/plugin/flint/helper/nuke.rb', line 12

def type
  @type
end

Instance Method Details

#nuke_it_now!Object



95
96
97
98
99
100
101
102
103
# File 'lib/fastlane/plugin/flint/helper/nuke.rb', line 95

def nuke_it_now!
  if self.files.count > 0
    delete_files!
  end

  # Now we need to commit and push all this too
  message = ["[fastlane]", "Nuked", "files", "for", type.to_s].join(" ")
  GitHelper.commit_changes(params[:workspace], message, self.params[:git_url], params[:git_branch], nil, Encrypt.new)
end

#prepare_listObject

Collect all the keystores



67
68
69
70
71
72
73
74
# File 'lib/fastlane/plugin/flint/helper/nuke.rb', line 67

def prepare_list
  UI.message("Fetching keystores...")
  cert_type = Flint.cert_type_sym(type)

  certs = Dir[File.join(params[:workspace], "**", "*-#{cert_type.to_s}.keystore")]

  self.files = certs
end

Print tables to ask the user



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fastlane/plugin/flint/helper/nuke.rb', line 77

def print_tables
  puts("")
  if self.files.count > 0
    rows = self.files.collect do |f|
      components = f.split(File::SEPARATOR)[-3..-1]
      file_type = components[0..1].reverse.join(" ")[0..-2]

      [file_type, components[2]]
    end
    puts(Terminal::Table.new({
      title: "Files that are going to be deleted".green,
      headings: ["Type", "File Name"],
      rows: rows
    }))
    puts("")
  end
end

#run(params, type: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/flint/helper/nuke.rb', line 16

def run(params, type: nil)
  self.params = params
  self.type = type

  params[:workspace] = GitHelper.clone(params[:git_url],
                                      params[:shallow_clone],
                                      skip_docs: params[:skip_docs],
                                      branch: params[:git_branch],
                                      git_full_name: params[:git_full_name],
                                      git_user_email: params[:git_user_email],
                                      clone_branch_directly: params[:clone_branch_directly],
                                      encrypt: Encrypt.new)

  had_app_identifier = self.params.fetch(:app_identifier, ask: false)
  self.params[:app_identifier] = '' # we don't really need a value here
  FastlaneCore::PrintTable.print_values(config: params,
                                    hide_keys: [:app_identifier, :workspace],
                                        title: "Summary for flint nuke #{Fastlane::VERSION}")

  prepare_list
  print_tables

  if params[:readonly]
    UI.user_error!("`fastlane flint nuke` doesn't delete anything when running with --readonly enabled")
  end

  if (self.files).count > 0
    unless params[:skip_confirmation]
      if type == "release"
        UI.confirm(
          "DANGER: By nuking release keys you might not " + 
          "be able to update your app in the play store. Are you sure?"
        )
      end
      UI.error("---")
      UI.error("Are you sure you want to completely delete and revoke all the")
      UI.error("keystores listed above? (y/n)")
      UI.error("---")
    end
    if params[:skip_confirmation] || UI.confirm("Do you really want to nuke everything listed above?")
      nuke_it_now!
      UI.success("Successfully cleaned up ♻️")
    else
      UI.success("Cancelled nuking #thanks 🏠 👨 ‍👩 ‍👧")
    end
  else
    UI.success("No relevant keystores found, nothing to nuke here :)")
  end
end