fastlane-plugin-redmine_upload 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: 8466b95d920a50c4882fd22369a596494934aa3d
4
- data.tar.gz: 5b35df0458b5e8a1ac15bf5ac67ebd9fd2b7ee27
3
+ metadata.gz: 46a7f033827701fe488af2b19e2446d531663290
4
+ data.tar.gz: be6c5a66c60377440062a8ae66e27c138ccda13b
5
5
  SHA512:
6
- metadata.gz: c6a8c5cc03a317f7fc0364d7482578c568a880feb474f2706444dcb00ef268f952effa4233c40c9a29367636e413c7c0f5e36f6a7555244e75fbc7af460d9c69
7
- data.tar.gz: cfe23f4aaeab20951a9ab38eccafe7c0041fe8638be77e7882f4f2d5591898c6928937276bb6d2e3803187463eab9d94f091e4e5b2bf05480c18691c07d4327d
6
+ metadata.gz: e939967a1ff0a794a45723b7a3f8249c92970367e9c5e4bf62679157133eee85b18513ad02b155e0b48da090b9252109d468e1c37244d63588e546420f045c49
7
+ data.tar.gz: 9fd7f77720edea13c6aeccf35a6ad4ebc0e7beb1d8ce558cb17e95e4cae238056d1eb9e515c6a72bb6d084c86ad8af5a4f5a31b16ee79717ad1ea8f68f2942f2
@@ -0,0 +1,126 @@
1
+ module Fastlane
2
+ module Actions
3
+ class RedmineFilePostAction < Action
4
+ def self.run(params)
5
+ require 'net/http'
6
+ require 'net/http/uploadprogress'
7
+ require 'uri'
8
+ require 'json'
9
+
10
+ redmine_url = params[:redmine_host]
11
+ api_key = params[:redmine_api_key]
12
+ username = params[:redmine_username]
13
+ password = params[:redmine_password]
14
+ project = params[:redmine_project]
15
+ token = params[:file_token]
16
+ file_version = params[:file_version]
17
+ file_description = params[:file_description]
18
+
19
+ file_post_uri = URI.parse(redmine_url + "/projects/#{project}/files.json")
20
+ # prepare request with token previously got from upload
21
+ json_content = {
22
+ "file" => file_data = {
23
+ "token" => token,
24
+ "filename" => file_name,
25
+ "version" => file_version,
26
+ "description" => file_description
27
+ }
28
+ }
29
+ file_body = JSON.pretty_generate(json_content)
30
+ UI.message("File post with content #{file_body}")
31
+
32
+ # Create the HTTP objects
33
+ http_file_post = Net::HTTP.new(upload_file_uri.host, upload_file_uri.port)
34
+ request_file = _post(Net::HTTP::Post.new(upload_file_uri.request_uri))
35
+
36
+ request_file["Content-Type"] = "application/json"
37
+ unless api_key.nil?
38
+ request_upload_content["X-Redmine-API-Key"] = api_key.to_s
39
+ end
40
+ unless username.nil? || password.nil?
41
+ request_upload_content.basic_auth(username, password)
42
+ end
43
+
44
+ case response_upload_file
45
+ when Net::HTTPSuccess
46
+ UI.success("File uploaded successfully")
47
+ when Net::HTTPRedirection
48
+
49
+ else
50
+ UI.error(response_upload_file.value)
51
+ end
52
+ end
53
+
54
+ def self.description
55
+ "Uploads a file in a Redmine Files section of a given Redmine project"
56
+ end
57
+
58
+ def self.authors
59
+ ["Mattia Salvetti"]
60
+ end
61
+
62
+ def self.return_value
63
+ # If your method provides a return value, you can describe here what it does
64
+ end
65
+
66
+ def self.details
67
+ # Optional:
68
+ "Uploads a file in a Redmine host under files section of specified Redmine project."
69
+ end
70
+
71
+ def self.available_options
72
+ [
73
+ FastlaneCore::ConfigItem.new(key: :redmine_host,
74
+ env_name: "REDMINE_HOST",
75
+ description: "Redmine host where upload file. e.g. ",
76
+ optional: false,
77
+ type: String),
78
+ FastlaneCore::ConfigItem.new(key: :redmine_username,
79
+ env_name: "REDMINE_USERNAME",
80
+ description: "Redmine username (optional). An API key can be provided instead",
81
+ optional: true,
82
+ type: String),
83
+ FastlaneCore::ConfigItem.new(key: :redmine_password,
84
+ env_name: "REDMINE_PASSWORD",
85
+ description: "Redmine password (optional). An API key can be provided instead",
86
+ optional: true,
87
+ type: String),
88
+ FastlaneCore::ConfigItem.new(key: :redmine_api_key,
89
+ env_name: "REDMINE_API_KEY",
90
+ description: "Redmine API key (optional). username and password can be provided instead",
91
+ optional: true,
92
+ type: String),
93
+ FastlaneCore::ConfigItem.new(key: :redmine_project,
94
+ env_name: "REDMINE_PROJECT",
95
+ description: "Project of redmine",
96
+ optional: false,
97
+ type: String),
98
+ FastlaneCore::ConfigItem.new(key: :file_token,
99
+ env_name: "FILE_TOKEN",
100
+ description: "Token of file previously released",
101
+ optional: false,
102
+ type: String),
103
+ FastlaneCore::ConfigItem.new(key: :file_version,
104
+ env_name: "FILE_VERSION",
105
+ description: "Version of file",
106
+ optional: true,
107
+ type: String),
108
+ FastlaneCore::ConfigItem.new(key: :file_description,
109
+ env_name: "FILE_DESCRIPTION",
110
+ description: "Description of file to upload",
111
+ optional: true,
112
+ type: String)
113
+
114
+ ]
115
+ end
116
+
117
+ def self.is_supported?(platform)
118
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
119
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
120
+ #
121
+ # [:ios, :mac, :android].include?(platform)
122
+ true
123
+ end
124
+ end
125
+ end
126
+ end
@@ -16,8 +16,8 @@ module Fastlane
16
16
 
17
17
  # getting parameters
18
18
  file_path = params[:file_path]
19
- file_name = File.basename(file_path) unless file_path == nil
20
-
19
+ file_name = File.basename(file_path) unless file_path.nil?
20
+
21
21
  Actions.lane_context[SharedValues::REDMINE_UPLOAD_FILE_NAME] = file_name
22
22
 
23
23
  redmine_url = params[:redmine_host]
@@ -25,9 +25,9 @@ module Fastlane
25
25
  username = params[:redmine_username]
26
26
  password = params[:redmine_password]
27
27
 
28
- upload_content_uri = URI.parse(redmine_url+'/uploads.json')
28
+ upload_content_uri = URI.parse(redmine_url + '/uploads.json')
29
29
  UI.message("Start file upload \"#{file_name}\" to Redmine API #{upload_content_uri}")
30
-
30
+
31
31
  token = nil
32
32
  response_upload_content = nil
33
33
  File.open(file_path, 'rb') do |io|
@@ -36,31 +36,31 @@ module Fastlane
36
36
  request_upload_content = Net::HTTP::Post.new(upload_content_uri.request_uri)
37
37
 
38
38
  request_upload_content["Content-Type"] = "application/octet-stream"
39
- unless api_key == nil
40
- request_upload_content["X-Redmine-API-Key"] = "#{api_key}"
39
+ unless api_key.nil?
40
+ request_upload_content["X-Redmine-API-Key"] = api_key.to_s
41
41
  end
42
- unless username == nil || password == nil
43
- request_upload_content.basic_auth username, password
42
+ unless username.nil? || password.nil?
43
+ request_upload_content.basic_auth(username, password)
44
44
  end
45
45
 
46
46
  request_upload_content.content_length = io.size
47
47
  request_upload_content.body_stream = io
48
48
  # print upload progress
49
49
  Net::HTTP::UploadProgress.new(request_upload_content) do |progress|
50
- printf("\rUploading \"#{file_name}\"... #{ 100 * progress.upload_size / io.size }%")
50
+ printf("\rUploading \"#{file_name}\"... #{100 * progress.upload_size / io.size}%")
51
51
  end
52
52
  # Send the request
53
53
  response_upload_content = http_upload_content.request(request_upload_content)
54
54
  printf("\n")
55
55
  end
56
56
  case response_upload_content
57
- when Net::HTTPSuccess
58
- # get token from upload content response
59
- token=JSON.parse(response_upload_content.body)['upload']['token']
60
- UI.success("Content uploaded! File token released: #{token}")
61
- Actions.lane_context[SharedValues::REDMINE_UPLOAD_FILE_TOKEN] = token
62
- else
63
- UI.error(response_upload_content.value)
57
+ when Net::HTTPSuccess
58
+ # get token from upload content response
59
+ token = JSON.parse(response_upload_content.body)['upload']['token']
60
+ UI.success("Content uploaded! File token released: #{token}")
61
+ Actions.lane_context[SharedValues::REDMINE_UPLOAD_FILE_TOKEN] = token
62
+ else
63
+ UI.error(response_upload_content.value)
64
64
  end
65
65
  end
66
66
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module RedmineUpload
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-redmine_upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Salvetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-14 00:00:00.000000000 Z
11
+ date: 2018-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -145,6 +145,7 @@ files:
145
145
  - LICENSE
146
146
  - README.md
147
147
  - lib/fastlane/plugin/redmine_upload.rb
148
+ - lib/fastlane/plugin/redmine_upload/actions/redmine_file_post.rb
148
149
  - lib/fastlane/plugin/redmine_upload/actions/redmine_upload_action.rb
149
150
  - lib/fastlane/plugin/redmine_upload/helper/redmine_upload_helper.rb
150
151
  - lib/fastlane/plugin/redmine_upload/version.rb