Class: Fastlane::Actions::RedmineFilePostAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::RedmineFilePostAction
- Defined in:
- lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
69 70 71 |
# File 'lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb', line 69 def self. ["Mattia Salvetti"] end |
.available_options ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb', line 82 def self. [ FastlaneCore::ConfigItem.new(key: :redmine_host, env_name: "REDMINE_HOST", description: "Redmine host where upload file. e.g. ", optional: false, type: String), FastlaneCore::ConfigItem.new(key: :redmine_username, env_name: "REDMINE_USERNAME", description: "Redmine username (optional). An API key can be provided instead", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :redmine_password, env_name: "REDMINE_PASSWORD", description: "Redmine password (optional). An API key can be provided instead", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :redmine_api_key, env_name: "REDMINE_API_KEY", description: "Redmine API key (optional). username and password can be provided instead", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :redmine_project, env_name: "REDMINE_PROJECT", description: "Project of redmine", optional: false, type: String), FastlaneCore::ConfigItem.new(key: :file_token, env_name: "FILE_TOKEN", description: "Token of file previously released", optional: false, type: String), FastlaneCore::ConfigItem.new(key: :file_name, env_name: "FILE_NAME", description: "FIle name", optional: false, type: String), FastlaneCore::ConfigItem.new(key: :file_version, env_name: "FILE_VERSION", description: "Version of file", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :file_description, env_name: "FILE_DESCRIPTION", description: "Description of file to upload", optional: true, type: String) ] end |
.description ⇒ Object
65 66 67 |
# File 'lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb', line 65 def self.description "Uploads a file in a Redmine Files section of a given Redmine project" end |
.details ⇒ Object
77 78 79 80 |
# File 'lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb', line 77 def self.details # Optional: "Uploads a file in a Redmine host under files section of specified Redmine project." end |
.is_supported?(platform) ⇒ Boolean
133 134 135 136 137 138 139 |
# File 'lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb', line 133 def self.is_supported?(platform) # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform # # [:ios, :mac, :android].include?(platform) true end |
.return_value ⇒ Object
73 74 75 |
# File 'lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb', line 73 def self.return_value # If your method provides a return value, you can describe here what it does end |
.run(params) ⇒ Object
4 5 6 7 8 9 10 11 12 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb', line 4 def self.run(params) require 'net/http' require 'uri' require 'json' redmine_url = params[:redmine_host] api_key = params[:redmine_api_key] username = params[:redmine_username] password = params[:redmine_password] project = params[:redmine_project] token = params[:file_token] file_name = params[:file_name] file_version = params[:file_version] file_description = params[:file_description] upload_file_uri = URI.parse(redmine_url + "/projects/#{project}/files.json") # prepare request with token previously got from upload json_content = { "file" => { "token" => token } } if file_version != nil json_content["file"]["version_id"] = file_version end if file_name != nil json_content["file"]["filename"] = file_name end if file_description != nil json_content["file"]["description"] = file_description end file_body = JSON.pretty_generate(json_content) UI.("File post with content #{file_body}") # Create the HTTP objects http_file_post = Net::HTTP.new(upload_file_uri.host, upload_file_uri.port) request_file = Net::HTTP::Post.new(upload_file_uri.request_uri) request_file["Content-Type"] = "application/json" unless api_key.nil? request_file["X-Redmine-API-Key"] = api_key.to_s end unless username.nil? || password.nil? request_file.basic_auth(username, password) end request_file.body = file_body # Send the request request_file = http_file_post.request(request_file) case request_file when Net::HTTPSuccess UI.success("File uploaded successfully") else UI.error(request_file.value) end end |