fastlane-plugin-google_drive 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6de403d0e5f2266e62059e359322a6babbb1d88905e3708130bae977d7078167
4
- data.tar.gz: 4e94204d3832150ed389197b2fa3316c3cc2c44bc29ad5a9ca67fdb599831d64
3
+ metadata.gz: 538f68214b71146ef64f4a99e01bc75ccc2fd8b146837d966aa354bf932b4c9a
4
+ data.tar.gz: a93cc09b8149798b1cc0f8f5457aec6add54b3cb408f523c426d13cc1e26838f
5
5
  SHA512:
6
- metadata.gz: 00f9a29bca7b319178aae13706bde63808e25fca4613fa5d626067966f5721bb2b39045bd4103c55bb57aa088b1dec88dc731a280268ad12f9ea8c0fe72dc4ef
7
- data.tar.gz: 357df4c4b4bfdc0bd07c5fafa588533d98e5c11f02ae193d10e800de0330f58623d5fcab1f48326a019011eb0b91fa01e57e5f62faa4fc4031e027e1c56bf36e
6
+ metadata.gz: 902b3d02aabd9ef980767370367d906405acf6ceadfd01fc75035624810dce42434746e0a339e63e32257acf0d43521c0c55f709562b09d857fb5e91c01b5b51
7
+ data.tar.gz: 0162a8cc7f27baf481d49c0beaad418a518b9d02b7213ce8774b41756c6aad1d84912cb2d1615eed9f1212e6ee01d3c41dfa60fe922c5fdfe783f4c8be6a5c2d
data/README.md CHANGED
@@ -50,6 +50,23 @@ update_google_drive_file(
50
50
  )
51
51
  ```
52
52
 
53
+ Find the existing file or folder:
54
+
55
+ ```ruby
56
+ # find the file or folder by ID
57
+ find_google_drive_file_by_id(
58
+ drive_keyfile: 'drive_key.json',
59
+ file_id: 'file_or_folder_id'
60
+ )
61
+
62
+ # find the file or folder by title
63
+ find_google_drive_file_by_title(
64
+ drive_keyfile: 'drive_key.json',
65
+ parent_folder_id: 'parent_folder_id',
66
+ file_title: 'file_or_folder_title'
67
+ )
68
+ ```
69
+
53
70
  Download feature is not implemented yet. PR is always welcome.
54
71
 
55
72
  ## Example
@@ -9,7 +9,7 @@ module Fastlane
9
9
  end
10
10
  class CreateGoogleDriveFolderAction < Action
11
11
  def self.run(params)
12
- UI.message("Using config file: #{params[:drive_keyfile]}")
12
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
13
13
 
14
14
  session = Helper::GoogleDriveHelper.setup(
15
15
  keyfile: params[:drive_keyfile],
@@ -0,0 +1,106 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/google_drive_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GDRIVE_FILE_ID = :GDRIVE_FILE_ID
8
+ GDRIVE_FILE_TITLE = :GDRIVE_FILE_TITLE
9
+ GDRIVE_FILE_URL = :GDRIVE_FILE_URL
10
+ end
11
+
12
+ class FindGoogleDriveFileByIdAction < Action
13
+ def self.run(params)
14
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
15
+
16
+ session = Helper::GoogleDriveHelper.setup(
17
+ keyfile: params[:drive_keyfile],
18
+ service_account: params[:service_account]
19
+ )
20
+
21
+ # parameter validation
22
+ target_file_id = params[:file_id]
23
+
24
+ begin
25
+ file = Helper::GoogleDriveHelper.file_by_id(
26
+ session: session, fid: target_file_id
27
+ )
28
+ rescue FastlaneCore::Interface::FastlaneError
29
+ file = nil
30
+ end
31
+
32
+ if file.nil?
33
+ UI.error("No file or folder was found.")
34
+ else
35
+ Actions.lane_context[SharedValues::GDRIVE_FILE_ID] = file.resource_id.split(':').last
36
+ Actions.lane_context[SharedValues::GDRIVE_FILE_TITLE] = file.title
37
+ Actions.lane_context[SharedValues::GDRIVE_FILE_URL] = file.human_url
38
+ end
39
+ end
40
+
41
+ def self.description
42
+ 'Find a Google Drive file or folder by ID'
43
+ end
44
+
45
+ def self.details
46
+ [
47
+ 'Find a Google Drive file or folder by ID',
48
+ 'See https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md to get a keyfile'
49
+ ].join("\n")
50
+ end
51
+
52
+ def self.available_options
53
+ [
54
+ FastlaneCore::ConfigItem.new(
55
+ key: :drive_keyfile,
56
+ env_name: 'GDRIVE_KEY_FILE',
57
+ description: 'The path to the json keyfile',
58
+ type: String,
59
+ default_value: 'drive_key.json',
60
+ verify_block: proc do |value|
61
+ UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
62
+ end
63
+ ),
64
+ FastlaneCore::ConfigItem.new(
65
+ key: :service_account,
66
+ env_name: 'GDRIVE_SERVICE_ACCOUNT',
67
+ description: 'Whether the credential file is for the google service account',
68
+ optional: true,
69
+ is_string: false,
70
+ default_value: false
71
+ ),
72
+ FastlaneCore::ConfigItem.new(
73
+ key: :file_id,
74
+ env_name: 'GDRIVE_TARGET_FILE_ID',
75
+ description: 'Target file or folder ID to check the existence',
76
+ optional: false,
77
+ type: String,
78
+ verify_block: proc do |value|
79
+ UI.user_error!("No `file_id` was given. Pass it using `file_id: 'some_id'`") if value.nil? || value.empty?
80
+ end
81
+ )
82
+ ]
83
+ end
84
+
85
+ def self.output
86
+ [
87
+ ['GDRIVE_FILE_ID', 'The file ID of the file or folder.'],
88
+ ['GDRIVE_FILE_TITLE', 'The title of the file or folder.'],
89
+ ['GDRIVE_FILE_URL', 'The link to the file or folder.']
90
+ ]
91
+ end
92
+
93
+ def self.return_value
94
+ # nothing
95
+ end
96
+
97
+ def self.authors
98
+ ['Bumsoo Kim (@bskim45)']
99
+ end
100
+
101
+ def self.is_supported?(platform)
102
+ true
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,120 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/google_drive_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ end
8
+
9
+ class FindGoogleDriveFileByTitleAction < Action
10
+ def self.run(params)
11
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
12
+
13
+ session = Helper::GoogleDriveHelper.setup(
14
+ keyfile: params[:drive_keyfile],
15
+ service_account: params[:service_account]
16
+ )
17
+
18
+ # parameter validation
19
+ parent_folder_id = params[:parent_folder_id]
20
+ file_title = params[:file_title]
21
+
22
+ parent_folder = Helper::GoogleDriveHelper.file_by_id(
23
+ session: session, fid: parent_folder_id
24
+ )
25
+
26
+ UI.abort_with_message!('The parent folder was not found.') if parent_folder.nil?
27
+
28
+ begin
29
+ file = Helper::GoogleDriveHelper.file_by_title(
30
+ root_folder: parent_folder, title: file_title
31
+ )
32
+ rescue FastlaneCore::Interface::FastlaneError
33
+ file = nil
34
+ end
35
+
36
+ if file.nil?
37
+ UI.error('No file or folder was found.')
38
+ else
39
+ Actions.lane_context[SharedValues::GDRIVE_FILE_ID] = file.resource_id.split(':').last
40
+ Actions.lane_context[SharedValues::GDRIVE_FILE_TITLE] = file.title
41
+ Actions.lane_context[SharedValues::GDRIVE_FILE_URL] = file.human_url
42
+ end
43
+ end
44
+
45
+ def self.description
46
+ 'Find a Google Drive file or folder by title'
47
+ end
48
+
49
+ def self.details
50
+ [
51
+ 'Find a Google Drive file or folder by title',
52
+ 'See https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md to get a keyfile'
53
+ ].join("\n")
54
+ end
55
+
56
+ def self.available_options
57
+ [
58
+ FastlaneCore::ConfigItem.new(
59
+ key: :drive_keyfile,
60
+ env_name: 'GDRIVE_KEY_FILE',
61
+ description: 'The path to the json keyfile',
62
+ type: String,
63
+ default_value: 'drive_key.json',
64
+ verify_block: proc do |value|
65
+ UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
66
+ end
67
+ ),
68
+ FastlaneCore::ConfigItem.new(
69
+ key: :service_account,
70
+ env_name: 'GDRIVE_SERVICE_ACCOUNT',
71
+ description: 'Whether the credential file is for the google service account',
72
+ optional: true,
73
+ is_string: false,
74
+ default_value: false
75
+ ),
76
+ FastlaneCore::ConfigItem.new(
77
+ key: :parent_folder_id,
78
+ env_name: 'GDRIVE_PARENT_FOLDER_ID',
79
+ description: 'The parent folder ID of the target file or folder to check the existence',
80
+ optional: false,
81
+ type: String,
82
+ verify_block: proc do |value|
83
+ UI.user_error!("No `parent_folder_id` was given. Pass it using `parent_folder_id: 'some_id'`") unless value and !value.empty?
84
+ end
85
+ ),
86
+ FastlaneCore::ConfigItem.new(
87
+ key: :file_title,
88
+ env_name: 'GDRIVE_TARGET_FILE_TITLE',
89
+ description: 'Target file or folder title to check the existence',
90
+ optional: false,
91
+ type: String,
92
+ verify_block: proc do |value|
93
+ UI.user_error!("No `file_title` was given. Pass it using `file_title: 'some_title'`") unless value and !value.empty?
94
+ end
95
+ ),
96
+ ]
97
+ end
98
+
99
+ def self.output
100
+ [
101
+ ['GDRIVE_FILE_ID', 'The file title of the file or folder'],
102
+ ['GDRIVE_FILE_TITLE', 'The title of the file or folder'],
103
+ ['GDRIVE_FILE_URL', 'The link to the file or folder']
104
+ ]
105
+ end
106
+
107
+ def self.return_value
108
+ # nothing
109
+ end
110
+
111
+ def self.authors
112
+ ['Bumsoo Kim (@bskim45)']
113
+ end
114
+
115
+ def self.is_supported?(platform)
116
+ true
117
+ end
118
+ end
119
+ end
120
+ end
@@ -9,7 +9,7 @@ module Fastlane
9
9
  end
10
10
  class UpdateGoogleDriveFileAction < Action
11
11
  def self.run(params)
12
- UI.message("Using config file: #{params[:drive_keyfile]}")
12
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
13
13
 
14
14
  session = Helper::GoogleDriveHelper.setup(
15
15
  keyfile: params[:drive_keyfile],
@@ -9,7 +9,7 @@ module Fastlane
9
9
  end
10
10
  class UploadToGoogleDriveAction < Action
11
11
  def self.run(params)
12
- UI.message("Using config file: #{params[:drive_keyfile]}")
12
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
13
13
 
14
14
  session = Helper::GoogleDriveHelper.setup(
15
15
  keyfile: params[:drive_keyfile],
@@ -24,6 +24,14 @@ module Fastlane
24
24
  UI.user_error!("File with id '#{fid}' not found in Google Drive")
25
25
  end
26
26
 
27
+ def self.file_by_title(root_folder:, title:)
28
+ file = root_folder.file_by_title(title)
29
+ file
30
+ rescue Exception => e
31
+ UI.error(e.message)
32
+ UI.user_error!("File with title '#{title}' not found in Google Drive")
33
+ end
34
+
27
35
  def self.upload_file(file: nil, file_name: nil, title: nil)
28
36
  raise "Not Google Drive file" unless file.kind_of?(::GoogleDrive::File)
29
37
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module GoogleDrive
3
- VERSION = "0.8.0"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-google_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bumsoo Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-17 00:00:00.000000000 Z
11
+ date: 2022-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive2
@@ -220,6 +220,8 @@ files:
220
220
  - README.md
221
221
  - lib/fastlane/plugin/google_drive.rb
222
222
  - lib/fastlane/plugin/google_drive/actions/create_google_drive_folder_action.rb
223
+ - lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb
224
+ - lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_title_action.rb
223
225
  - lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb
224
226
  - lib/fastlane/plugin/google_drive/actions/upload_to_google_drive_action.rb
225
227
  - lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb