Class: Fastlane::Actions::FindGoogleDriveFileByIdAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



118
119
120
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 118

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

.available_optionsObject



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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 55

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :drive_keyfile,
      env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
      description: 'Path to the JSON keyfile',
      conflicting_options: [:drive_key_json],
      type: String,
      optional: true,
      verify_block: proc do |value|
        UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
        UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :drive_key_json,
      env_name: 'GDRIVE_KEY_JSON',
      description: 'Credential key in stringified JSON format',
      optional: true,
      conflicting_options: [:drive_keyfile],
      type: String,
      sensitive: true,
      verify_block: proc do |value|
        begin
          JSON.parse(value)
        rescue JSON::ParserError
          UI.user_error!("Provided credential key is not a valid JSON")
        end
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :service_account,
      env_name: 'GDRIVE_SERVICE_ACCOUNT',
      description: 'true if the credential is for a service account, false otherwise',
      optional: true,
      is_string: false,
      default_value: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :file_id,
      env_name: 'GDRIVE_TARGET_FILE_ID',
      description: 'Target file or folder ID to check the existence',
      optional: false,
      type: String,
      verify_block: proc do |value|
        UI.user_error!("No `file_id` was given. Pass it using `file_id: 'some_id'`") if value.nil? || value.empty?
      end
    )
  ]
end

.descriptionObject



44
45
46
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 44

def self.description
  'Find a Google Drive file or folder by ID'
end

.detailsObject



48
49
50
51
52
53
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 48

def self.details
  [
    'Find a Google Drive file or folder by ID',
    '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)


122
123
124
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 122

def self.is_supported?(platform)
  true
end

.outputObject



106
107
108
109
110
111
112
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 106

def self.output
  [
    ['GDRIVE_FILE_ID', 'The file ID of the file or folder.'],
    ['GDRIVE_FILE_TITLE', 'The title of the file or folder.'],
    ['GDRIVE_FILE_URL', 'The link to the file or folder.']
  ]
end

.return_valueObject



114
115
116
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 114

def self.return_value
  # nothing
end

.run(params) ⇒ Object



13
14
15
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
# File 'lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb', line 13

def self.run(params)
  unless params[:drive_keyfile].nil?
    UI.message("Using credential file: #{params[:drive_keyfile]}")
  end

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

  # parameter validation
  target_file_id = params[:file_id]

  begin
    file = Helper::GoogleDriveHelper.file_by_id(
      session: session, fid: target_file_id
    )
  rescue FastlaneCore::Interface::FastlaneError
    file = nil
  end

  if file.nil?
    UI.error("No file or folder was found.")
  else
    Actions.lane_context[SharedValues::GDRIVE_FILE_ID] = file.resource_id.split(':').last
    Actions.lane_context[SharedValues::GDRIVE_FILE_TITLE] = file.title
    Actions.lane_context[SharedValues::GDRIVE_FILE_URL] = file.human_url
  end
end