danger-app_size_report 0.0.1 → 0.0.3
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 +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +170 -0
- data/Guardfile +2 -0
- data/LICENSE +21 -0
- data/README.md +46 -8
- data/Rakefile +2 -0
- data/Resources/App Thinning Size Report.txt +57 -0
- data/Resources/expectedReportJSON.json +590 -0
- data/danger-app_size_report.gemspec +13 -11
- data/lib/app_size_report/gem_version.rb +3 -1
- data/lib/app_size_report/plugin.rb +152 -78
- data/lib/converter/helper/json_converter.rb +14 -0
- data/lib/converter/helper/memory_size.rb +107 -0
- data/lib/converter/helper/result_factory.rb +34 -0
- data/lib/converter/models/app_size_model.rb +32 -0
- data/lib/converter/models/device_model.rb +17 -0
- data/lib/converter/models/variant_model.rb +24 -0
- data/lib/converter/parser/app_size_parser.rb +48 -0
- data/lib/converter/parser/model_parser.rb +13 -0
- data/lib/converter/parser/report_parser.rb +65 -0
- data/lib/converter/parser/variant_descriptor_parser.rb +53 -0
- data/lib/converter/parser/variant_parser.rb +10 -0
- data/lib/danger_app_size_report.rb +3 -1
- data/lib/danger_plugin.rb +3 -1
- data/spec/app_size_report_spec.rb +18 -27
- data/spec/spec_helper.rb +19 -17
- metadata +35 -21
- data/LICENSE.txt +0 -22
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            # frozen_string_literal: false
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative '../models/device_model'
         | 
| 4 | 
            +
            require 'securerandom'
         | 
| 5 | 
            +
            require_relative './model_parser'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            class VariantDescriptorParser < ModelParser
         | 
| 8 | 
            +
              def parse
         | 
| 9 | 
            +
                @text = @text.strip
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                if @text.empty?
         | 
| 12 | 
            +
                  @result = nil
         | 
| 13 | 
            +
                elsif @text == 'Universal'
         | 
| 14 | 
            +
                  @result = [parse_to_device_model(@text)]
         | 
| 15 | 
            +
                else
         | 
| 16 | 
            +
                  models = []
         | 
| 17 | 
            +
                  splitter_id = SecureRandom.uuid
         | 
| 18 | 
            +
                  @text.sub!('and ', '')
         | 
| 19 | 
            +
                  @text.gsub!('],', "],#{splitter_id}")
         | 
| 20 | 
            +
                  descriptors = @text.split(",#{splitter_id} ")
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  descriptors.each do |descriptor|
         | 
| 23 | 
            +
                    descriptor = descriptor[/\[(.*?)\]/m, 1]
         | 
| 24 | 
            +
                    model = parse_to_device_model(descriptor)
         | 
| 25 | 
            +
                    models.append(model) if model
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  @result = models
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def parse_to_device_model(text)
         | 
| 33 | 
            +
                return nil unless text
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                return DeviceModel.new(text, '') if text == 'Universal'
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                attributes = text.split(', ')
         | 
| 38 | 
            +
                parsing_keys = DeviceModel::PARSING_KEYS
         | 
| 39 | 
            +
                dict = {}
         | 
| 40 | 
            +
                attributes.each do |attribute|
         | 
| 41 | 
            +
                  parsing_keys.each do |_property, key|
         | 
| 42 | 
            +
                    next unless attribute.include? key
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    # clean the key from the text
         | 
| 45 | 
            +
                    parseable_text = attribute.gsub(key, '')
         | 
| 46 | 
            +
                    dict[key] = parseable_text
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                DeviceModel.new(dict.fetch(parsing_keys[:device], 'Unknown'),
         | 
| 51 | 
            +
                                dict.fetch(parsing_keys[:os_version], 'Unknown'))
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
    
        data/lib/danger_plugin.rb
    CHANGED
    
    
| @@ -1,46 +1,37 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            # frozen_string_literal: false
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require File.expand_path('spec_helper', __dir__)
         | 
| 2 4 |  | 
| 3 5 | 
             
            module Danger
         | 
| 4 6 | 
             
              describe Danger::DangerAppSizeReport do
         | 
| 5 | 
            -
                it  | 
| 7 | 
            +
                it 'should be a plugin' do
         | 
| 6 8 | 
             
                  expect(Danger::DangerAppSizeReport.new(nil)).to be_a Danger::Plugin
         | 
| 7 9 | 
             
                end
         | 
| 8 10 |  | 
| 9 | 
            -
                 | 
| 10 | 
            -
                # You should test your custom attributes and methods here
         | 
| 11 | 
            -
                #
         | 
| 12 | 
            -
                describe "with Dangerfile" do
         | 
| 11 | 
            +
                describe 'with Dangerfile' do
         | 
| 13 12 | 
             
                  before do
         | 
| 14 13 | 
             
                    @dangerfile = testing_dangerfile
         | 
| 15 | 
            -
                    @ | 
| 16 | 
            -
             | 
| 17 | 
            -
                    # mock the PR data
         | 
| 18 | 
            -
                    # you can then use this, eg. github.pr_author, later in the spec
         | 
| 19 | 
            -
                    json = File.read(File.dirname(__FILE__) + '/support/fixtures/github_pr.json') # example json: `curl https://api.github.com/repos/danger/danger-plugin-template/pulls/18 > github_pr.json`
         | 
| 20 | 
            -
                    allow(@my_plugin.github).to receive(:pr_json).and_return(json)
         | 
| 14 | 
            +
                    @app_size_report = @dangerfile.app_size_report
         | 
| 21 15 | 
             
                  end
         | 
| 22 16 |  | 
| 23 | 
            -
                   | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
                  it "Warns on a monday" do
         | 
| 27 | 
            -
                    monday_date = Date.parse("2016-07-11")
         | 
| 28 | 
            -
                    allow(Date).to receive(:today).and_return monday_date
         | 
| 17 | 
            +
                  it 'Converts App Size Report to JSON' do
         | 
| 18 | 
            +
                    json_string = @app_size_report.report_json("#{File.dirname(__dir__)}/Resources/App\ Thinning\ Size\ Report.txt")
         | 
| 29 19 |  | 
| 30 | 
            -
                     | 
| 20 | 
            +
                    expected_json = File.read("#{File.dirname(__dir__)}/Resources/expectedReportJSON.json")
         | 
| 31 21 |  | 
| 32 | 
            -
                    expect( | 
| 22 | 
            +
                    expect(json_string).to eq(expected_json)
         | 
| 33 23 | 
             
                  end
         | 
| 34 24 |  | 
| 35 | 
            -
                  it  | 
| 36 | 
            -
                     | 
| 37 | 
            -
             | 
| 25 | 
            +
                  it 'Generates App Size Danger Report' do
         | 
| 26 | 
            +
                    @app_size_report.flag_violations(
         | 
| 27 | 
            +
                      "#{File.dirname(__dir__)}/Resources/App\ Thinning\ Size\ Report.txt",
         | 
| 28 | 
            +
                      build_type: 'Clip',
         | 
| 29 | 
            +
                      size_limit: 12,
         | 
| 30 | 
            +
                      limit_unit: 'MB'
         | 
| 31 | 
            +
                    )
         | 
| 38 32 |  | 
| 39 | 
            -
                    @ | 
| 40 | 
            -
             | 
| 41 | 
            -
                    expect(@dangerfile.status_report[:warnings]).to eq([])
         | 
| 33 | 
            +
                    expect(@dangerfile.status_report[:warnings]).to eq(['The size limit of 10 MB has been exceeded by one or more variants'])
         | 
| 42 34 | 
             
                  end
         | 
| 43 | 
            -
             | 
| 44 35 | 
             
                end
         | 
| 45 36 | 
             
              end
         | 
| 46 37 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1,28 +1,30 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            ROOT = Pathname.new(File.expand_path("../../", __FILE__))
         | 
| 3 | 
            -
            $:.unshift((ROOT + "lib").to_s)
         | 
| 4 | 
            -
            $:.unshift((ROOT + "spec").to_s)
         | 
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 5 2 |  | 
| 6 | 
            -
            require  | 
| 7 | 
            -
             | 
| 3 | 
            +
            require 'pathname'
         | 
| 4 | 
            +
            ROOT = Pathname.new(File.expand_path('..', __dir__))
         | 
| 5 | 
            +
            $LOAD_PATH.unshift("#{ROOT}lib".to_s)
         | 
| 6 | 
            +
            $LOAD_PATH.unshift("#{ROOT}spec".to_s)
         | 
| 8 7 |  | 
| 9 | 
            -
            require  | 
| 10 | 
            -
            require  | 
| 8 | 
            +
            require 'bundler/setup'
         | 
| 9 | 
            +
            require 'pry'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            require 'rspec'
         | 
| 12 | 
            +
            require 'danger'
         | 
| 11 13 |  | 
| 12 14 | 
             
            if `git remote -v` == ''
         | 
| 13 | 
            -
              puts  | 
| 15 | 
            +
              puts 'You cannot run tests without setting a local git remote on this repo'
         | 
| 14 16 | 
             
              puts "It's a weird side-effect of Danger's internals."
         | 
| 15 17 | 
             
              exit(0)
         | 
| 16 18 | 
             
            end
         | 
| 17 19 |  | 
| 18 20 | 
             
            # Use coloured output, it's the best.
         | 
| 19 21 | 
             
            RSpec.configure do |config|
         | 
| 20 | 
            -
              config.filter_gems_from_backtrace  | 
| 22 | 
            +
              config.filter_gems_from_backtrace 'bundler'
         | 
| 21 23 | 
             
              config.color = true
         | 
| 22 24 | 
             
              config.tty = true
         | 
| 23 25 | 
             
            end
         | 
| 24 26 |  | 
| 25 | 
            -
            require  | 
| 27 | 
            +
            require 'danger_plugin'
         | 
| 26 28 |  | 
| 27 29 | 
             
            # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
         | 
| 28 30 | 
             
            # If you are expanding these files, see if it's already been done ^.
         | 
| @@ -40,7 +42,7 @@ def testing_ui | |
| 40 42 |  | 
| 41 43 | 
             
              cork = Cork::Board.new(out: @output)
         | 
| 42 44 | 
             
              def cork.string
         | 
| 43 | 
            -
                out.string.gsub(/\e\[([;\d]+)?m/,  | 
| 45 | 
            +
                out.string.gsub(/\e\[([;\d]+)?m/, '')
         | 
| 44 46 | 
             
              end
         | 
| 45 47 | 
             
              cork
         | 
| 46 48 | 
             
            end
         | 
| @@ -50,11 +52,11 @@ end | |
| 50 52 | 
             
            # running a PR on TravisCI
         | 
| 51 53 | 
             
            def testing_env
         | 
| 52 54 | 
             
              {
         | 
| 53 | 
            -
                 | 
| 54 | 
            -
                 | 
| 55 | 
            -
                 | 
| 56 | 
            -
                 | 
| 57 | 
            -
                 | 
| 55 | 
            +
                'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
         | 
| 56 | 
            +
                'TRAVIS_PULL_REQUEST' => '800',
         | 
| 57 | 
            +
                'TRAVIS_REPO_SLUG' => 'artsy/eigen',
         | 
| 58 | 
            +
                'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
         | 
| 59 | 
            +
                'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
         | 
| 58 60 | 
             
              }
         | 
| 59 61 | 
             
            end
         | 
| 60 62 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: danger-app_size_report
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 | 
            -
            -  | 
| 7 | 
            +
            - Rishab Sukumar
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2022-02-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: danger-plugin-api
         | 
| @@ -70,30 +70,30 @@ dependencies: | |
| 70 70 | 
             
              name: rubocop
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                requirements:
         | 
| 73 | 
            -
                - - " | 
| 73 | 
            +
                - - "~>"
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version:  | 
| 75 | 
            +
                    version: 1.25.0
         | 
| 76 76 | 
             
              type: :development
         | 
| 77 77 | 
             
              prerelease: false
         | 
| 78 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 79 | 
             
                requirements:
         | 
| 80 | 
            -
                - - " | 
| 80 | 
            +
                - - "~>"
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            -
                    version:  | 
| 82 | 
            +
                    version: 1.25.0
         | 
| 83 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 84 | 
             
              name: yard
         | 
| 85 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
                requirements:
         | 
| 87 | 
            -
                - - " | 
| 87 | 
            +
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version:  | 
| 89 | 
            +
                    version: 0.9.27
         | 
| 90 90 | 
             
              type: :development
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 | 
            -
                - - " | 
| 94 | 
            +
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version:  | 
| 96 | 
            +
                    version: 0.9.27
         | 
| 97 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 98 | 
             
              name: guard
         | 
| 99 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -140,32 +140,46 @@ dependencies: | |
| 140 140 | 
             
              name: pry
         | 
| 141 141 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 142 | 
             
                requirements:
         | 
| 143 | 
            -
                - - " | 
| 143 | 
            +
                - - "~>"
         | 
| 144 144 | 
             
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            -
                    version:  | 
| 145 | 
            +
                    version: 0.14.1
         | 
| 146 146 | 
             
              type: :development
         | 
| 147 147 | 
             
              prerelease: false
         | 
| 148 148 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 149 | 
             
                requirements:
         | 
| 150 | 
            -
                - - " | 
| 150 | 
            +
                - - "~>"
         | 
| 151 151 | 
             
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            -
                    version:  | 
| 153 | 
            -
            description: A  | 
| 152 | 
            +
                    version: 0.14.1
         | 
| 153 | 
            +
            description: A Danger plugin for reporting iOS app size violations.
         | 
| 154 154 | 
             
            email:
         | 
| 155 | 
            -
            -  | 
| 155 | 
            +
            - rishab.sukumar@chargepoint.com
         | 
| 156 156 | 
             
            executables: []
         | 
| 157 157 | 
             
            extensions: []
         | 
| 158 158 | 
             
            extra_rdoc_files: []
         | 
| 159 159 | 
             
            files:
         | 
| 160 160 | 
             
            - ".gitignore"
         | 
| 161 161 | 
             
            - Gemfile
         | 
| 162 | 
            +
            - Gemfile.lock
         | 
| 162 163 | 
             
            - Guardfile
         | 
| 163 | 
            -
            - LICENSE | 
| 164 | 
            +
            - LICENSE
         | 
| 164 165 | 
             
            - README.md
         | 
| 165 166 | 
             
            - Rakefile
         | 
| 167 | 
            +
            - Resources/App Thinning Size Report.txt
         | 
| 168 | 
            +
            - Resources/expectedReportJSON.json
         | 
| 166 169 | 
             
            - danger-app_size_report.gemspec
         | 
| 167 170 | 
             
            - lib/app_size_report/gem_version.rb
         | 
| 168 171 | 
             
            - lib/app_size_report/plugin.rb
         | 
| 172 | 
            +
            - lib/converter/helper/json_converter.rb
         | 
| 173 | 
            +
            - lib/converter/helper/memory_size.rb
         | 
| 174 | 
            +
            - lib/converter/helper/result_factory.rb
         | 
| 175 | 
            +
            - lib/converter/models/app_size_model.rb
         | 
| 176 | 
            +
            - lib/converter/models/device_model.rb
         | 
| 177 | 
            +
            - lib/converter/models/variant_model.rb
         | 
| 178 | 
            +
            - lib/converter/parser/app_size_parser.rb
         | 
| 179 | 
            +
            - lib/converter/parser/model_parser.rb
         | 
| 180 | 
            +
            - lib/converter/parser/report_parser.rb
         | 
| 181 | 
            +
            - lib/converter/parser/variant_descriptor_parser.rb
         | 
| 182 | 
            +
            - lib/converter/parser/variant_parser.rb
         | 
| 169 183 | 
             
            - lib/danger_app_size_report.rb
         | 
| 170 184 | 
             
            - lib/danger_plugin.rb
         | 
| 171 185 | 
             
            - spec/app_size_report_spec.rb
         | 
| @@ -189,11 +203,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 189 203 | 
             
                - !ruby/object:Gem::Version
         | 
| 190 204 | 
             
                  version: '0'
         | 
| 191 205 | 
             
            requirements: []
         | 
| 192 | 
            -
            rubygems_version: 3. | 
| 206 | 
            +
            rubygems_version: 3.3.6
         | 
| 193 207 | 
             
            signing_key:
         | 
| 194 208 | 
             
            specification_version: 4
         | 
| 195 | 
            -
            summary:  | 
| 196 | 
            -
               | 
| 209 | 
            +
            summary: A Danger plugin for reporting iOS app size violations. A valid App Thinning
         | 
| 210 | 
            +
              Size Report must be passed to the plugin for accurate functionality.
         | 
| 197 211 | 
             
            test_files:
         | 
| 198 212 | 
             
            - spec/app_size_report_spec.rb
         | 
| 199 213 | 
             
            - spec/spec_helper.rb
         | 
    
        data/LICENSE.txt
    DELETED
    
    | @@ -1,22 +0,0 @@ | |
| 1 | 
            -
            Copyright (c) 2021 Vido Shaweddy <vido.shaweddy@chargepoint.com>
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            MIT License
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            -
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            -
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            -
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            -
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            -
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            -
            the following conditions:
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            -
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            -
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            -
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            -
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            -
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            -
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            -
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         |