fastlane-plugin-screenshot_notifier 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ffa76f65c4d14cfeec1c37d5add43cd0983532f942cb53acd5b8cc319367f2fa
4
+ data.tar.gz: 3da1f83f3206b4fe18d014c83a8c5505c34b95b8817fc322cd19afd5f9b76eae
5
+ SHA512:
6
+ metadata.gz: 31b9bbcf59b34fce031c196fd44dc156557586351f2ecf425d00a478390ab1c63456374dc2ae7d558841db6936df4844056e544b8d07374d2591b96a3c4417e5
7
+ data.tar.gz: d36ded2a517f76f34afed9d66ab8438e4c692ab456a77079c2e5c4373eb51b17ea3d5d315966c8de218f1fb059de8867d2aeed399ca7c1e4a4ec39356bb22271
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 CATS Open Source Softwares
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # screenshot_notifier plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-screenshot_notifier)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-screenshot_notifier`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin screenshot_notifier
11
+ ```
12
+
13
+ This plugin depends Firebase Cloud Storage to store snapshots. If you don't have a Firebase account, see [this](https://github.com/cats-oss/fastlane-plugin-firebase_test_lab_android#if-you-are-not-current-user-of-firebase) and create a bucket.
14
+
15
+ ## About screenshot_notifier
16
+
17
+ Post screenshots to a pull request
18
+
19
+ ## Example
20
+
21
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
22
+
23
+ In case of `screenshot_dir` like below,
24
+
25
+ ```
26
+ .screenshot
27
+ ├ Nexus6
28
+ | ├ MainPage.jpg
29
+ | └ SubPage.jpg
30
+ └ Nexus6P
31
+ ├ MainPage.jpg
32
+ └ SubPage.jpg
33
+ ```
34
+
35
+ this plugin generates following table of screenshots.
36
+
37
+ | Screen Name | Nexus6 | Nexus6P |
38
+ | --- | --- | --- |
39
+ | MainPage.jpg | (Screenshot) | (Screenshot) |
40
+ | SubPage.jpg | (Screenshot) | (Screenshot) |
41
+
42
+ ## Run tests for this plugin
43
+
44
+ To run both the tests, and code style validation, run
45
+
46
+ ```
47
+ rake
48
+ ```
49
+
50
+ To automatically fix many of the styling issues, use
51
+ ```
52
+ rubocop -a
53
+ ```
54
+
55
+ ## Issues and Feedback
56
+
57
+ For any other issues and feedback about this plugin, please submit it to this repository.
58
+
59
+ ## Troubleshooting
60
+
61
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
62
+
63
+ ## Using _fastlane_ Plugins
64
+
65
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
66
+
67
+ ## About _fastlane_
68
+
69
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/screenshot_notifier/version'
2
+
3
+ module Fastlane
4
+ module ScreenshotNotifier
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::ScreenshotNotifier.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,159 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/screenshot_notifier_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class ScreenshotNotifierAction < Action
7
+ def self.run(params)
8
+ Helper.authenticate(params[:gcloud_service_key_file])
9
+ commit_hash = Helper.get_current_commit_hash
10
+
11
+ UI.message "Upload screenshots to cloud storage"
12
+ Action.sh "gsutil -m rsync -d -r #{params[:screenshot_dir]} gs://#{params[:screenshot_bucket]}/#{commit_hash}"
13
+
14
+ UI.message "Delete previous PR comments"
15
+ GitHubNotifier.delete_comments(
16
+ params[:github_owner],
17
+ params[:github_repository],
18
+ params[:github_pr_number],
19
+ "## Screenshots of each devices",
20
+ params[:github_api_token]
21
+ )
22
+
23
+ UI.message "Post screenshots as PR comments"
24
+ screenshot_dir = params[:screenshot_dir]
25
+ devices = Dir.chdir("#{screenshot_dir}") do
26
+ Dir.glob("*").select {|path| FileTest.directory? path}.sort
27
+ end
28
+ header = "<tr><td>Screen Name</td>\n#{devices.map {|device| "<td>#{device}</td>\n"}.inject(&:+)}</tr>"
29
+ rows = Dir.glob("#{screenshot_dir}/#{devices[0]}/*.jpg")
30
+ .map {|path| File.basename(path)}
31
+ .map {|file_name|
32
+ cells = devices.map {|device|
33
+ ratio = Helper.calc_aspect_ratio("#{screenshot_dir}/#{device}/#{file_name}")
34
+ is_portrait = ratio >= 1.0
35
+ size_attr = if params[:image_length] != nil
36
+ if is_portrait
37
+ height = params[:image_length]
38
+ width = height / ratio
39
+ "height=\"#{height}px\" width=\"#{width}px\""
40
+ else
41
+ width = params[:image_length] * ratio
42
+ height = width * ratio
43
+ "height=\"#{height}px\" width=\"#{width}px\""
44
+ end
45
+ else
46
+ ""
47
+ end
48
+
49
+ url = object_url(params[:screenshot_bucket], "#{commit_hash}/#{device}/#{file_name}")
50
+ "<td><img src=\"#{url}\" #{size_attr}/></td>\n"
51
+ }.inject(&:+)
52
+ "<tr><td>#{file_name}</td>\n#{cells}</tr>\n"
53
+ }
54
+ .inject(&:+)
55
+
56
+ table = "<table>#{header}#{rows}</table>"
57
+ comment = if params[:fold_result]
58
+ "## Screenshots of each devices\n\n"\
59
+ "<details>"\
60
+ "<summary>Open</summary>"\
61
+ "#{table}"\
62
+ "</details>"
63
+ else
64
+ "## Screenshots of each devices\n\n"\
65
+ "#{table}"
66
+ end
67
+ UI.message comment
68
+ GitHubNotifier.put_comment(
69
+ params[:github_owner],
70
+ params[:github_repository],
71
+ params[:github_pr_number],
72
+ comment,
73
+ params[:github_api_token]
74
+ )
75
+ end
76
+
77
+ def self.object_url(bucket, path)
78
+ Helper.firebase_object_url(bucket, path)
79
+ end
80
+
81
+ def self.description
82
+ "Post Screenshots to Pull Request"
83
+ end
84
+
85
+ def self.details
86
+ "Post Screenshots to Pull Request"
87
+ end
88
+
89
+ def self.available_options
90
+ [
91
+ FastlaneCore::ConfigItem.new(key: :gcloud_service_key_file,
92
+ env_name: "GCLOUD_SERVICE_KEY_FILE",
93
+ description: "File path containing the gcloud auth key. Default: Created from GCLOUD_SERVICE_KEY environment variable",
94
+ type: String,
95
+ optional: false),
96
+ FastlaneCore::ConfigItem.new(key: :screenshot_bucket,
97
+ env_name: "SCREENSHOT_BUCKET",
98
+ description: "Bucket name to store screenshots",
99
+ type: String,
100
+ optional: false),
101
+ FastlaneCore::ConfigItem.new(key: :screenshot_dir,
102
+ env_name: "SCREENSHOT_DIR",
103
+ description: "Directory that has screenshots",
104
+ type: String,
105
+ optional: false),
106
+ FastlaneCore::ConfigItem.new(key: :fold_result,
107
+ env_name: "FOLD_RESULT",
108
+ description: "Fold screenshots table",
109
+ type: Boolean,
110
+ optional: false,
111
+ default_value: false),
112
+ FastlaneCore::ConfigItem.new(key: :github_owner,
113
+ env_name: "GITHUB_OWNER",
114
+ description: "Owner name",
115
+ type: String,
116
+ optional: false),
117
+ FastlaneCore::ConfigItem.new(key: :github_repository,
118
+ env_name: "GITHUB_REPOSITORY",
119
+ description: "Repository name",
120
+ type: String,
121
+ optional: false),
122
+ FastlaneCore::ConfigItem.new(key: :github_pr_number,
123
+ env_name: "GITHUB_PR_NUMBER",
124
+ description: "Pull request number",
125
+ type: String,
126
+ optional: false),
127
+ FastlaneCore::ConfigItem.new(key: :github_api_token,
128
+ env_name: "GITHUB_API_TOKEN",
129
+ description: "GitHub API Token",
130
+ type: String,
131
+ optional: false),
132
+ FastlaneCore::ConfigItem.new(key: :image_length,
133
+ env_name: "IMAGE_LENGTH",
134
+ description: "Length px of the long side of screenshots",
135
+ is_string: false,
136
+ optional: true)
137
+ ]
138
+ end
139
+
140
+ def self.output
141
+ # Define the shared values you are going to provide
142
+ # Example
143
+ []
144
+ end
145
+
146
+ def self.return_value
147
+ # If your method provides a return value, you can describe here what it does
148
+ end
149
+
150
+ def self.authors
151
+ ["MoyuruAizawa"]
152
+ end
153
+
154
+ def self.is_supported?(platform)
155
+ platform == :android
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,87 @@
1
+ require 'fastlane_core/ui/ui'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module Fastlane
7
+ module GitHubNotifier
8
+ def self.fold_comments(github_owner, github_repository, github_pr_number, comment_prefix, summary, github_api_token)
9
+ res = get_comments(github_owner, github_repository, github_pr_number, github_api_token)
10
+ JSON.parse(res.body)
11
+ .select {|comment| comment["body"] != nil && comment["body"].start_with?(comment_prefix)}
12
+ .each {|comment|
13
+ body = "<details><summary>#{summary}</summary>\n#{comment["body"]}\n\n</details>\n"
14
+ patch_comment(github_owner, github_repository, comment["id"], body, github_api_token)
15
+ }
16
+ end
17
+
18
+ def self.delete_comments(github_owner, github_repository, github_pr_number, comment_prefix, github_api_token)
19
+ res = get_comments(github_owner, github_repository, github_pr_number, github_api_token)
20
+ JSON.parse(res.body)
21
+ .select {|comment| comment["body"] != nil && comment["body"].start_with?(comment_prefix)}
22
+ .each {|comment| delete_comment(github_owner, github_repository, comment["id"], github_api_token)}
23
+ end
24
+
25
+ def self.get_comments(github_owner, github_repository, github_pr_number, github_api_token)
26
+ api_url = "https://api.github.com/repos/#{github_owner}/#{github_repository}/issues/#{github_pr_number}/comments"
27
+ UI.message "get comments #{api_url}"
28
+
29
+ uri = URI.parse(api_url)
30
+ req = Net::HTTP::Get.new(uri)
31
+ req["Content-Type"] = "application/json"
32
+ req["Authorization"] = "token #{github_api_token}"
33
+
34
+ res = Net::HTTP.start(uri.hostname, uri.port, {use_ssl: uri.scheme = "https"}) {|http| http.request(req)}
35
+ UI.message "#{res.code}\n#{res.body}"
36
+
37
+ res
38
+ end
39
+
40
+ def self.put_comment(github_owner, github_repository, github_pr_number, body, github_api_token)
41
+ api_url = "https://api.github.com/repos/#{github_owner}/#{github_repository}/issues/#{github_pr_number}/comments"
42
+ UI.message "put comment #{api_url}"
43
+
44
+ uri = URI.parse(api_url)
45
+ req = Net::HTTP::Post.new(uri)
46
+ req["Content-Type"] = "application/json"
47
+ req["Authorization"] = "token #{github_api_token}"
48
+ req.body = {:body => body}.to_json
49
+
50
+ res = Net::HTTP.start(uri.hostname, uri.port, {use_ssl: uri.scheme = "https"}) {|http| http.request(req)}
51
+ UI.message "#{res.code}\n#{res.body}"
52
+
53
+ res
54
+ end
55
+
56
+ def self.patch_comment(github_owner, github_repository, comment_id, body, github_api_token)
57
+ api_url = "https://api.github.com/repos/#{github_owner}/#{github_repository}/issues/comments/#{comment_id}"
58
+ UI.message "patch comment #{api_url}"
59
+
60
+ uri = URI.parse(api_url)
61
+ req = Net::HTTP::Patch.new(uri)
62
+ req["Content-Type"] = "application/json"
63
+ req["Authorization"] = "token #{github_api_token}"
64
+ req.body = {:body => body}.to_json
65
+
66
+ res = Net::HTTP.start(uri.hostname, uri.port, {use_ssl: uri.scheme = "https"}) {|http| http.request(req)}
67
+ UI.message "#{res.code}\n#{res.body}"
68
+
69
+ res
70
+ end
71
+
72
+ def self.delete_comment(github_owner, github_repository, comment_id, github_api_token)
73
+ api_url = "https://api.github.com/repos/#{github_owner}/#{github_repository}/issues/comments/#{comment_id}"
74
+ UI.message "delete comment #{api_url}"
75
+
76
+ uri = URI.parse(api_url)
77
+ req = Net::HTTP::Delete.new(uri)
78
+ req["Content-Type"] = "application/json"
79
+ req["Authorization"] = "token #{github_api_token}"
80
+
81
+ res = Net::HTTP.start(uri.hostname, uri.port, {use_ssl: uri.scheme = "https"}) {|http| http.request(req)}
82
+ UI.message "#{res.code}\n#{res.body}"
83
+
84
+ res
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,25 @@
1
+ require 'fastlane_core/ui/ui'
2
+
3
+ module Fastlane
4
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
5
+ module Helper
6
+ def self.authenticate(gcloud_key_file)
7
+ UI.message "Authenticate with GCP"
8
+ Action.sh("gcloud auth activate-service-account --key-file #{gcloud_key_file}")
9
+ end
10
+
11
+ def self.get_current_commit_hash
12
+ Action.sh("git rev-parse HEAD").chomp!
13
+ end
14
+
15
+ def self.firebase_object_url(bucket, path)
16
+ "https://firebasestorage.googleapis.com/v0/b/#{bucket}/o/#{CGI.escape(path)}?alt=media"
17
+ end
18
+
19
+ def self.calc_aspect_ratio(imagePath)
20
+ width, height = FastImage.size(imagePath)
21
+ UI.message "Image(#{imagePath}) size #{width} * #{height}"
22
+ height / width.to_f
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module ScreenshotNotifier
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-screenshot_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Moyuru Aizawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.49.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.49.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-require_tools
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fastlane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.121.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.121.1
139
+ description:
140
+ email: lvla0805@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/screenshot_notifier.rb
148
+ - lib/fastlane/plugin/screenshot_notifier/actions/screenshot_notifier_action.rb
149
+ - lib/fastlane/plugin/screenshot_notifier/helper/github_notifier.rb
150
+ - lib/fastlane/plugin/screenshot_notifier/helper/screenshot_notifier_helper.rb
151
+ - lib/fastlane/plugin/screenshot_notifier/version.rb
152
+ homepage:
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubygems_version: 3.0.3
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Post screenshots to a pull request
175
+ test_files: []