bugsnag_sourcemap_uploader 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +52 -0
- data/LICENSE +21 -0
- data/README.md +45 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/rake +29 -0
- data/bin/setup +8 -0
- data/bugsnag_sourcemap_uploader.gemspec +32 -0
- data/examples/webpacker_asset_repository.rb +95 -0
- data/lib/bugsnag_sourcemap_uploader.rb +91 -0
- data/lib/bugsnag_sourcemap_uploader/upload_task.rb +118 -0
- data/lib/bugsnag_sourcemap_uploader/version.rb +5 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3ee3d07e9ff42067679369032d166482470b4e291927413a08a8f389e8cb471
|
4
|
+
data.tar.gz: a39c50a2b02d82d2e39cb62e47fe8c6c14ad37dbfea251f1ab2a7c4c1c079c59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ae31e25fa1f4aacdf7072de250c2b166022c4182cc3dad68349255bdd57749ba788e4073b85f8fd8a0e990e5e9c0a0038f29d05b1ebd9db4d0a66d8d7a2423e
|
7
|
+
data.tar.gz: 89a4404a75a7c435edc91c5bfbc81b6fc3a319316c913d93c5c86f0db455e3c833c0ba5f0e1d10698c14711ee7f3fcd6a409375f27772df9a1b2ffd06a0be62a
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Layout/LineLength:
|
2
|
+
Max: 120
|
3
|
+
AllowHeredoc: true
|
4
|
+
AllowURI: true
|
5
|
+
URISchemes:
|
6
|
+
- http
|
7
|
+
- https
|
8
|
+
IgnoredPatterns:
|
9
|
+
- '\A\s*(remote_)?test(_\w+)?\s.*(do|->)(\s|\Z)'
|
10
|
+
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Enabled: false
|
16
|
+
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
gemspec
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'mocha'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :development do
|
14
|
+
gem 'rubocop'
|
15
|
+
gem 'yard'
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bugsnag_sourcemap_uploader (0.1.0)
|
5
|
+
concurrent-ruby (~> 1.1.4)
|
6
|
+
httparty (~> 0.17.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
concurrent-ruby (1.1.5)
|
13
|
+
httparty (0.17.3)
|
14
|
+
mime-types (~> 3.0)
|
15
|
+
multi_xml (>= 0.5.2)
|
16
|
+
jaro_winkler (1.5.4)
|
17
|
+
mime-types (3.3.1)
|
18
|
+
mime-types-data (~> 3.2015)
|
19
|
+
mime-types-data (3.2019.1009)
|
20
|
+
minitest (5.14.0)
|
21
|
+
mocha (1.11.2)
|
22
|
+
multi_xml (0.6.0)
|
23
|
+
parallel (1.19.1)
|
24
|
+
parser (2.7.0.2)
|
25
|
+
ast (~> 2.4.0)
|
26
|
+
rainbow (3.0.0)
|
27
|
+
rake (10.5.0)
|
28
|
+
rubocop (0.79.0)
|
29
|
+
jaro_winkler (~> 1.5.1)
|
30
|
+
parallel (~> 1.10)
|
31
|
+
parser (>= 2.7.0.1)
|
32
|
+
rainbow (>= 2.2.2, < 4.0)
|
33
|
+
ruby-progressbar (~> 1.7)
|
34
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
35
|
+
ruby-progressbar (1.10.1)
|
36
|
+
unicode-display_width (1.6.1)
|
37
|
+
yard (0.9.24)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bugsnag_sourcemap_uploader!
|
44
|
+
bundler (~> 1.17)
|
45
|
+
minitest (~> 5.0)
|
46
|
+
mocha
|
47
|
+
rake (~> 10.0)
|
48
|
+
rubocop
|
49
|
+
yard
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
1.17.3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Bernardo Araujo
|
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,45 @@
|
|
1
|
+
# BugsnagSourcemapUploader
|
2
|
+
|
3
|
+
Upload your sourcemaps to Bugsnag in parallel.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bugsnag_sourcemap_uploader'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bugsnag_sourcemap_uploader
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
BugsnagSourcemapUploader.upload(assets_metadata, bugsnag_api_key)
|
25
|
+
```
|
26
|
+
|
27
|
+
### Asset Metadata
|
28
|
+
|
29
|
+
Any object that responds to the following methods:
|
30
|
+
|
31
|
+
* #script_path
|
32
|
+
* #source_map_path
|
33
|
+
* #cdn_url
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bernardoamc/bugsnag_sourcemap_uploader.
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
42
|
+
|
43
|
+
## Code of Conduct
|
44
|
+
|
45
|
+
Everyone interacting in the BugsnagSourcemapUploader project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bernardoamc/bugsnag_sourcemap_uploader/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'bugsnag_sourcemap_uploader'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'bugsnag_sourcemap_uploader/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'bugsnag_sourcemap_uploader'
|
9
|
+
spec.version = BugsnagSourcemapUploader::VERSION
|
10
|
+
spec.authors = ['Bernardo Chaves']
|
11
|
+
spec.email = ['bernardo.amc@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Upload sourcemaps to Bugsnag in parallel.'
|
14
|
+
spec.homepage = 'https://rubygems.org/gems/bugsnag_sourcemap_uploader'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
|
30
|
+
spec.add_dependency 'concurrent-ruby', '~> 1.1.4'
|
31
|
+
spec.add_dependency 'httparty', '~> 0.17.0'
|
32
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BugsnagSourcemapUploader
|
4
|
+
# Aggregates assets generated by Webpacker
|
5
|
+
class WebpackerAssetRepository
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
# @param path [Pathname] the path where assets can be found
|
9
|
+
# @return [WebpackerAssetRepository] the instance of this class
|
10
|
+
def initialize(path)
|
11
|
+
@path = path
|
12
|
+
end
|
13
|
+
|
14
|
+
# Aggregates every .js file in the path with its respective .js.map file
|
15
|
+
#
|
16
|
+
# @return [Array<AssetMetadata>] the list of aggregated JS and Sourcemap files.
|
17
|
+
def assets_metadata
|
18
|
+
scripts_by_prefix.each_with_object([]) do |(prefix, script), assets|
|
19
|
+
unless source_maps_by_prefix.key?(prefix)
|
20
|
+
Rails.logger.info("Found script without source map: #{script}")
|
21
|
+
next
|
22
|
+
end
|
23
|
+
|
24
|
+
assets << AssetMetadata.new(script, source_maps_by_prefix[prefix])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def scripts
|
31
|
+
@scripts ||= Dir.glob("#{path}/**/*.js")
|
32
|
+
end
|
33
|
+
|
34
|
+
def source_maps
|
35
|
+
@source_maps ||= Dir.glob("#{path}/**/*.js.map")
|
36
|
+
end
|
37
|
+
|
38
|
+
def scripts_by_prefix
|
39
|
+
@scripts_by_prefix ||= begin
|
40
|
+
scripts.each_with_object({}) do |script, prefixes|
|
41
|
+
match_data = script.match(/\A(.*)-[a-f0-9]{64}\.js\z/)
|
42
|
+
next if match_data.nil?
|
43
|
+
|
44
|
+
prefix = match_data[1]
|
45
|
+
prefixes[prefix] = script
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def source_maps_by_prefix
|
51
|
+
@source_maps_by_prefix ||= begin
|
52
|
+
source_maps.each_with_object({}) do |source_map, prefixes|
|
53
|
+
match_data = source_map.match(/\A(.*)-[a-f0-9]{64}\.js\.map\z/)
|
54
|
+
next if match_data.nil?
|
55
|
+
|
56
|
+
prefix = match_data[1]
|
57
|
+
prefixes[prefix] = source_map
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# A Class with an instance that responds to methods required by BugsnagSourcemapUploader
|
64
|
+
class AssetMetadata
|
65
|
+
CDN_HOST_URL = 'https://cdn.sourcemap.com/bundles/'
|
66
|
+
|
67
|
+
attr_reader :script_path, :source_map_path
|
68
|
+
|
69
|
+
def initialize(script_path, source_map_path)
|
70
|
+
@script_path = script_path
|
71
|
+
@source_map_path = source_map_path
|
72
|
+
end
|
73
|
+
|
74
|
+
def script_name
|
75
|
+
@script_name ||= File.basename(script_path)
|
76
|
+
end
|
77
|
+
|
78
|
+
def cdn_url
|
79
|
+
@cdn_url ||= begin
|
80
|
+
Addressable::URI
|
81
|
+
.parse(CDN_HOST_URL)
|
82
|
+
.join("#{parent_dir}/")
|
83
|
+
.join(script_name)
|
84
|
+
.to_s
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def parent_dir
|
91
|
+
File.dirname(script_path).split('/').last
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bugsnag_sourcemap_uploader/version'
|
4
|
+
require 'bugsnag_sourcemap_uploader/upload_task'
|
5
|
+
require 'concurrent'
|
6
|
+
|
7
|
+
##
|
8
|
+
# BugsnagSourcemapUploader is a library to enable parallel sourcemap uploads to Bugsnag.
|
9
|
+
module BugsnagSourcemapUploader
|
10
|
+
TASK_TIMEOUT_IN_SECONDS = 10 # Task timeout in seconds
|
11
|
+
|
12
|
+
# Upload sourcemaps to Bugsnag.
|
13
|
+
#
|
14
|
+
# @param assets_metadata [Array] object
|
15
|
+
# Each item in this Array must be an object that responds to
|
16
|
+
# `#script_path`, `#source_map_path` and `#cdn_url`.
|
17
|
+
# @param bugsnag_api_key [String] key
|
18
|
+
# The Bugsnag API key.
|
19
|
+
# @param http_options [Hash] HTTP options
|
20
|
+
# Options accepted by HTTParty.
|
21
|
+
# Useful to set headers or logging details.
|
22
|
+
#
|
23
|
+
# @return [BugsnagSourcemapUploader::Result] The object with the results of our operation.
|
24
|
+
def self.upload(assets_metadata:, bugsnag_api_key:, http_options: {})
|
25
|
+
pool = Concurrent::ThreadPoolExecutor.new(
|
26
|
+
min_threads: 4,
|
27
|
+
max_threads: Concurrent.processor_count
|
28
|
+
)
|
29
|
+
|
30
|
+
futures = assets_metadata.map do |asset_metadata|
|
31
|
+
Concurrent::Promise.execute(executor: pool) do
|
32
|
+
UploadTask.new(
|
33
|
+
asset_metadata: asset_metadata,
|
34
|
+
bugsnag_api_key: bugsnag_api_key
|
35
|
+
).run(http_options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
responses = futures.map do |future|
|
40
|
+
future.value(TASK_TIMEOUT_IN_SECONDS)
|
41
|
+
end
|
42
|
+
|
43
|
+
Result.new(responses)
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Represents the result of the BugsnagSourcemapUploader.upload operation
|
48
|
+
class Result
|
49
|
+
attr_reader :tasks_results
|
50
|
+
|
51
|
+
def initialize(tasks_results)
|
52
|
+
@tasks_results = tasks_results
|
53
|
+
end
|
54
|
+
|
55
|
+
# Answers whether every upload task was successful or not.
|
56
|
+
#
|
57
|
+
# @return [Boolean] value.
|
58
|
+
def success?
|
59
|
+
@success ||= @tasks_results.all?(&:success?)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Answers whether we had failures among upload tasks.
|
63
|
+
#
|
64
|
+
# @return [Boolean] value.
|
65
|
+
def failure?
|
66
|
+
!success?
|
67
|
+
end
|
68
|
+
|
69
|
+
# Filters upload tasks that were successful.
|
70
|
+
#
|
71
|
+
# @return [Array] The list of tasks that were succesful.
|
72
|
+
def successful_tasks
|
73
|
+
@successful_tasks ||= @tasks_results.select(&:success?)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Filters upload tasks that failed with HTTP errors. This includes HTTP failures
|
77
|
+
# or execution errors.
|
78
|
+
#
|
79
|
+
# @return [Array] The list of tasks that failed.
|
80
|
+
def failed_tasks
|
81
|
+
@failed_tasks ||= @tasks_results.select(&:failure?)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Filters upload tasks that had execution errors.
|
85
|
+
#
|
86
|
+
# @return [Array] The list of tasks with execution errors.
|
87
|
+
def execution_error_tasks
|
88
|
+
@execution_error_tasks ||= failed_tasks.select(&:execution_error?)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module BugsnagSourcemapUploader
|
6
|
+
# The unit of work to send a sourcemap with its associated minified javascript
|
7
|
+
# file to Bugsnag.
|
8
|
+
class UploadTask
|
9
|
+
UPLOAD_URL = 'https://upload.bugsnag.com/' # Bugsnag upload URL
|
10
|
+
|
11
|
+
def initialize(asset_metadata:, bugsnag_api_key:)
|
12
|
+
@asset_metadata = asset_metadata
|
13
|
+
@bugsnag_api_key = bugsnag_api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def run(http_options: {})
|
17
|
+
body_payload = {
|
18
|
+
'apiKey' => @bugsnag_api_key,
|
19
|
+
'minifiedUrl' => @asset_metadata.cdn_url,
|
20
|
+
'sourceMap' => source_map_contents,
|
21
|
+
'minifiedFile' => script_contents,
|
22
|
+
'overwrite' => true
|
23
|
+
}
|
24
|
+
|
25
|
+
payload = http_options.merge(body: body_payload)
|
26
|
+
|
27
|
+
Result.new(
|
28
|
+
@asset_metadata,
|
29
|
+
HTTParty.post(UPLOAD_URL, payload)
|
30
|
+
)
|
31
|
+
rescue StandardError => e
|
32
|
+
ExecutionErrorResult.new(@asset_metadata, e)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def source_map_contents
|
38
|
+
File.open(@asset_metadata.source_map_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def script_contents
|
42
|
+
File.open(@asset_metadata.script_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Represents the result of the UploadTask#upload method.
|
46
|
+
class Result
|
47
|
+
HTTP_TIMEOUT_CODE = 408 # HTTP status code for timeouts
|
48
|
+
HTTP_TOO_MANY_REQUESTS_CODE = 429 # HTTP status code for too many requests
|
49
|
+
|
50
|
+
attr_reader :asset_metadata
|
51
|
+
|
52
|
+
def initialize(asset_metadata, http_response)
|
53
|
+
@asset_metadata = asset_metadata
|
54
|
+
@http_response = http_response
|
55
|
+
end
|
56
|
+
|
57
|
+
def reason
|
58
|
+
@http_response.body
|
59
|
+
end
|
60
|
+
|
61
|
+
def status_code
|
62
|
+
@http_response.code
|
63
|
+
end
|
64
|
+
|
65
|
+
def success?
|
66
|
+
@http_response.success?
|
67
|
+
end
|
68
|
+
|
69
|
+
def failure?
|
70
|
+
!success?
|
71
|
+
end
|
72
|
+
|
73
|
+
def execution_error?
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
def retryable?
|
78
|
+
status_code < 400 ||
|
79
|
+
status_code > 499 ||
|
80
|
+
[HTTP_TIMEOUT_CODE, HTTP_TOO_MANY_REQUESTS_CODE].include?(status_code)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Represents the result of the UploadTask#upload method when an exception occurred.
|
85
|
+
class ExecutionErrorResult
|
86
|
+
attr_reader :asset_metadata, :exception
|
87
|
+
|
88
|
+
def initialize(asset_metadata, exception)
|
89
|
+
@asset_metadata = asset_metadata
|
90
|
+
@exception = exception
|
91
|
+
end
|
92
|
+
|
93
|
+
def status_code
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
|
97
|
+
def reason
|
98
|
+
@exception.message
|
99
|
+
end
|
100
|
+
|
101
|
+
def success?
|
102
|
+
false
|
103
|
+
end
|
104
|
+
|
105
|
+
def failure?
|
106
|
+
true
|
107
|
+
end
|
108
|
+
|
109
|
+
def execution_error?
|
110
|
+
true
|
111
|
+
end
|
112
|
+
|
113
|
+
def retryable?
|
114
|
+
true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bugsnag_sourcemap_uploader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bernardo Chaves
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: concurrent-ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.17.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.17.0
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- bernardo.amc@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/rake
|
102
|
+
- bin/setup
|
103
|
+
- bugsnag_sourcemap_uploader.gemspec
|
104
|
+
- examples/webpacker_asset_repository.rb
|
105
|
+
- lib/bugsnag_sourcemap_uploader.rb
|
106
|
+
- lib/bugsnag_sourcemap_uploader/upload_task.rb
|
107
|
+
- lib/bugsnag_sourcemap_uploader/version.rb
|
108
|
+
homepage: https://rubygems.org/gems/bugsnag_sourcemap_uploader
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.0.3
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Upload sourcemaps to Bugsnag in parallel.
|
131
|
+
test_files: []
|