Class: Fastlane::Actions::ReportAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::ReportAction
- Defined in:
- lib/fastlane/plugin/report/actions/report_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .pdf(options) ⇒ Object
- .run(options) ⇒ Object
Class Method Details
.authors ⇒ Object
90 91 92 |
# File 'lib/fastlane/plugin/report/actions/report_action.rb', line 90 def self. ["Bruno Miguè‚ns"] end |
.available_options ⇒ Object
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fastlane/plugin/report/actions/report_action.rb', line 94 def self. [FastlaneCore::ConfigItem.new(key: :slack_api_token, env_name: "REPORT_SLACK_API_TOKEN", description: "Token of slack rest api. Need to be generated at 'https://api.slack.com'", optional: false, type: String, verify_block: proc do |value| UI.user_error!("You need to provide a 'slack_api_token' parameter") if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :path, env_name: "REPORT_PATH", description: "Relative path to report file (ex. .../report/20170603140211.html)", optional: false, type: String, verify_block: proc do |value| UI.user_error!("You need to provide a 'path' parameter") if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :path_type, env_name: "REPORT_PATH_TYPE", description: "Multipart type of your report file (ex. text/html)", optional: false, type: String, verify_block: proc do |value| UI.user_error!("You need to provide a 'path_type' parameter") if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :file_name, env_name: "REPORT_FILE_NAME", description: "Name of your file (ex. 20170603140211.html)", optional: false, type: String, verify_block: proc do |value| UI.user_error!("You need to provide a 'file_name' parameter") if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :channels, env_name: "REPORT_SLACK_CHANNELS", description: "Selected channels to upload and post your report (default: '#channel')", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :title, env_name: "REPORT_TITLE", description: "Title that will be shown on Slack (default: 'Report!')", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :message, env_name: "REPORT_MESSAGE", description: "Message that will be shown on Slack (default: 'This is your report.')", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :scan_as_pdf, env_name: "REPORT_SCAN_AS_PDF", description: "Message that will be shown on Slack (default: 'true' if was a HTML file)", optional: true, type: TrueClass) ] end |
.category ⇒ Object
150 151 152 |
# File 'lib/fastlane/plugin/report/actions/report_action.rb', line 150 def self.category :notifications end |
.description ⇒ Object
83 84 85 86 87 88 |
# File 'lib/fastlane/plugin/report/actions/report_action.rb', line 83 def self.description [ "After an action, like scan for instance, you're able to generate a report file.", "This fastlane plugin gives you a way to upload and share your report using Slack." ].join('\n') end |
.example_code ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/fastlane/plugin/report/actions/report_action.rb', line 158 def self.example_code [ "report( slack_api_token: 'xxxx-0000000000-11111111111-222222222222-xxxxxxxxx33333333xxxxxxxx3333333', path: './some/path/report.html', path_type: 'text/html', file_name: 'report.html' )" ] end |
.is_supported?(platform) ⇒ Boolean
154 155 156 |
# File 'lib/fastlane/plugin/report/actions/report_action.rb', line 154 def self.is_supported?(platform) true end |
.pdf(options) ⇒ Object
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/report/actions/report_action.rb', line 47 def self.pdf() require 'pdfkit' require 'nokogiri' PDFKit.configure do |config| config. = { page_size: "Letter", encoding: "UTF-8", disable_smart_shrinking: false, footer_spacing: 2, footer_center: "Page [page] of [toPage]" } end path = [:path] ||= '' html = File.open(path, "r") # Will be removed the segmented bar in case of you are uploading a Fastlane Scan report html_doc = Nokogiri::HTML(html) html_doc.css('section#segment-bar').remove html = html_doc.to_html kit = PDFKit.new(html, :page_size => 'Letter') if !kit.nil? path = path.gsub('.html', '.pdf') file = kit.to_file(path) return file else return path end end |
.run(options) ⇒ 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 |
# File 'lib/fastlane/plugin/report/actions/report_action.rb', line 4 def self.run() require 'slack-ruby-client' if .nil? UI.user_error!("Is mandatory to provide a 'Slack API Token'.") else token = [:slack_api_token] ||= '' Slack.configure do |config| config.token = token end channel = [:channels] ||= '#channel' title = [:title] ||= 'Report!' = [:message] ||= 'This is your report.' path = [:path] path_type = [:path_type] file_name = [:file_name] scan_as_pdf = [:scan_as_pdf] ||= path_type == 'text/html' if scan_as_pdf path = pdf(path: path) end client = Slack::Web::Client.new client.files_upload( channels: channel, as_user: false, file: Faraday::UploadIO.new(path, path_type), title: title, filename: file_name, initial_comment: ) UI.success("Report successfully uploaded and sent to Slack channel '" + channel + "'.") UI.success("Title: " + title + " and messsage: " + [:message]) end end |