Class: Fastlane::Actions::UpdateGoogleDriveFileAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



94
95
96
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 94

def self.authors
  ['Bumsoo Kim (@bskim45)']
end

.available_optionsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 47

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :drive_keyfile,
                                env_name: 'GDRIVE_KEY_FILE',
                                description: 'Json config file',
                                type: String,
                                default_value: 'drive_key.json',
                                verify_block: proc do |value|
                                  UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
                                end),
    FastlaneCore::ConfigItem.new(key: :service_account,
                                env_name: 'GDRIVE_SERVICE_ACCOUNT',
                                description: 'Credential is service account',
                                optional: true,
                                is_string: false,
                                default_value: false),
    FastlaneCore::ConfigItem.new(key: :file_id,
                                env_name: "GDRIVE_UPDATE_FILE_ID",
                                description: "Target file id to update the content",
                                optional: false,
                                type: String,
                                verify_block: proc do |value|
                                  UI.user_error!("No target file id given, pass using `file_id: 'some_id'`") unless value and !value.empty?
                                end),
    FastlaneCore::ConfigItem.new(key: :upload_file,
                                env_name: "GDRIVE_UPLOAD_FILE",
                                description: "Path to a file to be uploaded",
                                optional: false,
                                is_string: false,
                                verify_block: proc do |value|
                                  UI.user_error!("No upload file is given, pass using `upload_file: 'some/path/a.txt'`") unless value and !value.empty?
                                  UI.user_error!("Couldn't find upload file at path '#{value}'") unless File.exist?(value)
                                end)
  ]
end

.descriptionObject



36
37
38
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 36

def self.description
  'Update a Google Drive file'
end

.detailsObject



40
41
42
43
44
45
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 40

def self.details
  [
    'Update a Google Drive file',
    'See https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md to get a keyfile'
  ].join("\n")
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 98

def self.is_supported?(platform)
  true
end

.outputObject



83
84
85
86
87
88
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 83

def self.output
  [
    ['GDRIVE_UPDATED_FILE_NAME', 'The name of the uploaded file'],
    ['GDRIVE_UPDATED_FILE_URL', 'The link to the uploaded file']
  ]
end

.return_valueObject



90
91
92
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 90

def self.return_value
  # nothing
end

.run(params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb', line 11

def self.run(params)
  UI.message("Using config file: #{params[:drive_keyfile]}")

  session = Helper::GoogleDriveHelper.setup(
    keyfile: params[:drive_keyfile],
    service_account: params[:service_account]
  )

  file = Helper::GoogleDriveHelper.file_by_id(
    session: session, fid: params[:file_id]
  )

  upload_file = params[:upload_file]
  UI.abort_with_message!("No file to upload") if upload_file.nil? or upload_file.empty?

  UI.message('------------------')
  UI.important("Uploading #{upload_file}")
  Helper::GoogleDriveHelper.update_file(file: file, file_name: upload_file)
  UI.success('Success')
  UI.message('------------------')

  Actions.lane_context[SharedValues::GDRIVE_UPDATED_FILE_NAME] = file.title
  Actions.lane_context[SharedValues::GDRIVE_UPDATED_FILE_URL] = file.human_url
end