gergich 1.1.1 → 2.0.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 +5 -5
 - data/{bin → exe}/gergich +0 -0
 - data/{bin → exe}/master_bouncer +0 -0
 - data/lib/gergich/capture/androidlint_capture.rb +10 -5
 - data/lib/gergich/capture/brakeman_capture.rb +3 -2
 - data/lib/gergich/capture/eslint_capture.rb +2 -1
 - data/lib/gergich/capture/flake8_capture.rb +1 -1
 - data/lib/gergich/capture/i18nliner_capture.rb +1 -1
 - data/lib/gergich/capture/rubocop_capture.rb +38 -3
 - data/lib/gergich/capture/shellcheck_capture.rb +2 -1
 - data/lib/gergich/capture/stylelint_capture.rb +2 -5
 - data/lib/gergich/capture/swiftlint_capture.rb +3 -3
 - data/lib/gergich/capture/yamllint_capture.rb +31 -0
 - data/lib/gergich/capture.rb +12 -5
 - data/lib/gergich/cli/gergich.rb +6 -4
 - data/lib/gergich/cli/master_bouncer.rb +6 -6
 - data/lib/gergich/cli.rb +1 -1
 - data/lib/gergich.rb +27 -28
 - metadata +65 -41
 - data/LICENSE +0 -20
 - data/README.md +0 -178
 - data/bin/check_coverage +0 -8
 - data/bin/run_tests.sh +0 -52
 - data/spec/gergich/capture/androidlint_capture_spec.rb +0 -61
 - data/spec/gergich/capture/brakeman_capture_spec.rb +0 -91
 - data/spec/gergich/capture/custom_capture_spec.rb +0 -41
 - data/spec/gergich/capture/eslint_capture_spec.rb +0 -31
 - data/spec/gergich/capture/flake8_capture_spec.rb +0 -23
 - data/spec/gergich/capture/i18nliner_capture_spec.rb +0 -25
 - data/spec/gergich/capture/rubocop_capture_spec.rb +0 -66
 - data/spec/gergich/capture/shellcheck_capture_spec.rb +0 -83
 - data/spec/gergich/capture/stylelint_capture_spec.rb +0 -54
 - data/spec/gergich/capture/swiftlint_capture_spec.rb +0 -42
 - data/spec/gergich/capture_spec.rb +0 -75
 - data/spec/gergich_spec.rb +0 -379
 - data/spec/spec_helper.rb +0 -92
 - data/spec/support/capture_shared_examples.rb +0 -19
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 49e238094aaf4cc412c50cff9e0704824f0460d28a38301a99ece910a9e4e3ca
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8a9d5bdf120832ef21c3a65bfc3e89e70ad0800eb6c76ec61ff32b866ae0a33c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 309de3347fb62da85de07807aa6b0f69913f756a69be2b515c928076077053378f5342961311adb17f07c7168413511ee42c95551f7029dfef36a00816fd6576
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: caae7f11e0f027d6bee1154b355dd04da9b3e149c3328bcf73016343724442e8b22454eaf47c869c392e983e941319bdf4a21e98fbf720a6d540fb9e688fc58b
         
     | 
    
        data/{bin → exe}/gergich
    RENAMED
    
    | 
         
            File without changes
         
     | 
    
        data/{bin → exe}/master_bouncer
    RENAMED
    
    | 
         
            File without changes
         
     | 
| 
         @@ -11,7 +11,7 @@ module Gergich 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  }.freeze
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                  def run(output)
         
     | 
| 
       14 
     | 
    
         
            -
                    # rubocop:disable  
     | 
| 
      
 14 
     | 
    
         
            +
                    # rubocop:disable Layout/LineLength
         
     | 
| 
       15 
15 
     | 
    
         
             
                    #
         
     | 
| 
       16 
16 
     | 
    
         
             
                    # Example:
         
     | 
| 
       17 
17 
     | 
    
         
             
                    # /path/to/some.xml:27: Warning: Consider adding android:drawableStart="@drawable/a_media" to better support right-to-left layouts [RtlHardcoded]
         
     | 
| 
         @@ -26,7 +26,7 @@ module Gergich 
     | 
|
| 
       26 
26 
     | 
    
         
             
                    #    <plurals name="number">
         
     | 
| 
       27 
27 
     | 
    
         
             
                    #    ^
         
     | 
| 
       28 
28 
     | 
    
         
             
                    #
         
     | 
| 
       29 
     | 
    
         
            -
                    # rubocop:enable  
     | 
| 
      
 29 
     | 
    
         
            +
                    # rubocop:enable Layout/LineLength
         
     | 
| 
       30 
30 
     | 
    
         
             
                    pattern = /
         
     | 
| 
       31 
31 
     | 
    
         
             
                      ^([^:\n]+):(\d+)?:?\s(\w+):\s(.*?)\n
         
     | 
| 
       32 
32 
     | 
    
         
             
                      ([^\n]+\n
         
     | 
| 
         @@ -34,9 +34,14 @@ module Gergich 
     | 
|
| 
       34 
34 
     | 
    
         
             
                    /mx
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                    output.scan(pattern).map { |file, line, severity, error, context|
         
     | 
| 
       37 
     | 
    
         
            -
                      context = "\n\n"  
     | 
| 
       38 
     | 
    
         
            -
                      { 
     | 
| 
       39 
     | 
    
         
            -
                         
     | 
| 
      
 37 
     | 
    
         
            +
                      context = "\n\n#{context}" if context
         
     | 
| 
      
 38 
     | 
    
         
            +
                      {
         
     | 
| 
      
 39 
     | 
    
         
            +
                        path: file,
         
     | 
| 
      
 40 
     | 
    
         
            +
                        message: "#{error}#{context}".strip,
         
     | 
| 
      
 41 
     | 
    
         
            +
                        position: (line || 0).to_i,
         
     | 
| 
      
 42 
     | 
    
         
            +
                        severity: SEVERITY_MAP[severity],
         
     | 
| 
      
 43 
     | 
    
         
            +
                        source: "androidlint"
         
     | 
| 
      
 44 
     | 
    
         
            +
                      }
         
     | 
| 
       40 
45 
     | 
    
         
             
                    }.compact
         
     | 
| 
       41 
46 
     | 
    
         
             
                  end
         
     | 
| 
       42 
47 
     | 
    
         
             
                end
         
     | 
| 
         @@ -14,7 +14,7 @@ module Gergich 
     | 
|
| 
       14 
14 
     | 
    
         
             
                  def run(output)
         
     | 
| 
       15 
15 
     | 
    
         
             
                    # See brakeman_example.json for sample output.
         
     | 
| 
       16 
16 
     | 
    
         
             
                    JSON.parse(output)["warnings"].map { |warning|
         
     | 
| 
       17 
     | 
    
         
            -
                      message = " 
     | 
| 
      
 17 
     | 
    
         
            +
                      message = "#{warning['warning_type']}: #{warning['message']}"
         
     | 
| 
       18 
18 
     | 
    
         
             
                      message += "\n  Code: #{warning['code']}" if warning["code"]
         
     | 
| 
       19 
19 
     | 
    
         
             
                      message += "\n  User Input: #{warning['user_input']}" if warning["user_input"]
         
     | 
| 
       20 
20 
     | 
    
         
             
                      message += "\n  See: #{warning['link']}" if warning["link"]
         
     | 
| 
         @@ -22,7 +22,8 @@ module Gergich 
     | 
|
| 
       22 
22 
     | 
    
         
             
                        path: warning["file"],
         
     | 
| 
       23 
23 
     | 
    
         
             
                        position: warning["line"] || 0,
         
     | 
| 
       24 
24 
     | 
    
         
             
                        message: message,
         
     | 
| 
       25 
     | 
    
         
            -
                        severity: SEVERITY_MAP[warning["confidence"]]
         
     | 
| 
      
 25 
     | 
    
         
            +
                        severity: SEVERITY_MAP[warning["confidence"]],
         
     | 
| 
      
 26 
     | 
    
         
            +
                        source: "brakeman"
         
     | 
| 
       26 
27 
     | 
    
         
             
                      }
         
     | 
| 
       27 
28 
     | 
    
         
             
                    }.compact
         
     | 
| 
       28 
29 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -16,7 +16,8 @@ module Gergich 
     | 
|
| 
       16 
16 
     | 
    
         
             
                    output.scan(pattern).map { |file, errors|
         
     | 
| 
       17 
17 
     | 
    
         
             
                      errors.scan(error_pattern).map { |line, severity, error|
         
     | 
| 
       18 
18 
     | 
    
         
             
                        severity = SEVERITY_MAP[severity]
         
     | 
| 
       19 
     | 
    
         
            -
                        { path: file, message: " 
     | 
| 
      
 19 
     | 
    
         
            +
                        { path: file, message: error, source: "eslint", position: line.to_i,
         
     | 
| 
      
 20 
     | 
    
         
            +
                          severity: severity }
         
     | 
| 
       20 
21 
     | 
    
         
             
                      }
         
     | 
| 
       21 
22 
     | 
    
         
             
                    }.compact.flatten
         
     | 
| 
       22 
23 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -16,7 +16,7 @@ module Gergich 
     | 
|
| 
       16 
16 
     | 
    
         
             
                        line = Regexp.last_match[1]
         
     | 
| 
       17 
17 
     | 
    
         
             
                        ""
         
     | 
| 
       18 
18 
     | 
    
         
             
                      end
         
     | 
| 
       19 
     | 
    
         
            -
                      { path: file, message: " 
     | 
| 
      
 19 
     | 
    
         
            +
                      { path: file, message: error, source: "i18n", position: line.to_i, severity: "error" }
         
     | 
| 
       20 
20 
     | 
    
         
             
                    }.compact
         
     | 
| 
       21 
21 
     | 
    
         
             
                  end
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
         @@ -16,10 +16,29 @@ module Gergich 
     | 
|
| 
       16 
16 
     | 
    
         
             
                    #   bin/gergich:47:8: C: Prefer double-quoted strings
         
     | 
| 
       17 
17 
     | 
    
         
             
                    #   if ENV['DEBUG']
         
     | 
| 
       18 
18 
     | 
    
         
             
                    #          ^^^^^^^
         
     | 
| 
      
 19 
     | 
    
         
            +
                    #
         
     | 
| 
      
 20 
     | 
    
         
            +
                    # 1 file inspected, 35 offenses detected, 27 offenses auto-correctable
         
     | 
| 
      
 21 
     | 
    
         
            +
                    #
         
     | 
| 
      
 22 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 23 
     | 
    
         
            +
                    # 2 files inspected, 40 offenses detected, 31 offenses auto-correctable
         
     | 
| 
      
 24 
     | 
    
         
            +
                    #
         
     | 
| 
      
 25 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 26 
     | 
    
         
            +
                    # 1 file inspected, no offenses detected
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       19 
28 
     | 
    
         
             
                    first_line_pattern = /^([^:\n]+):(\d+):\d+:\s(\w):\s/
         
     | 
| 
       20 
29 
     | 
    
         | 
| 
       21 
30 
     | 
    
         
             
                    parts = output.split(first_line_pattern)
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                    unless parts.last.match?(/^\d+ files? inspect/)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      raise "RuboCop failed to run properly:\n\n#{output}"
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                    # strip off the summary line from the last error
         
     | 
| 
      
 37 
     | 
    
         
            +
                    parts[-1] = parts[-1].split("\n")[0..-2].join("\n")
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    # strip off the header
         
     | 
| 
       22 
40 
     | 
    
         
             
                    parts.shift
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
       23 
42 
     | 
    
         
             
                    messages = []
         
     | 
| 
       24 
43 
     | 
    
         | 
| 
       25 
44 
     | 
    
         
             
                    until parts.empty?
         
     | 
| 
         @@ -30,15 +49,31 @@ module Gergich 
     | 
|
| 
       30 
49 
     | 
    
         
             
                      # if there is code context at the end, separate it and indent it
         
     | 
| 
       31 
50 
     | 
    
         
             
                      # so that gerrit preserves formatting
         
     | 
| 
       32 
51 
     | 
    
         
             
                      if /(?<context>[^\n]+\n *\^+\n)/m =~ message
         
     | 
| 
       33 
     | 
    
         
            -
                        message.sub!(context, "\n 
     | 
| 
      
 52 
     | 
    
         
            +
                        message.sub!(context, "\n#{context.gsub(/^/, ' ')}")
         
     | 
| 
       34 
53 
     | 
    
         
             
                      end
         
     | 
| 
      
 54 
     | 
    
         
            +
                      match = message.match(
         
     | 
| 
      
 55 
     | 
    
         
            +
                        %r{
         
     | 
| 
      
 56 
     | 
    
         
            +
                          \A
         
     | 
| 
      
 57 
     | 
    
         
            +
                          (?<corrected>\[Corrected\]\s)?
         
     | 
| 
      
 58 
     | 
    
         
            +
                          (?<correctable>\[Correctable\]\s)?
         
     | 
| 
      
 59 
     | 
    
         
            +
                          (?:(?<cop>[A-Za-z/]+):\s)?
         
     | 
| 
      
 60 
     | 
    
         
            +
                          (?<message>.*)
         
     | 
| 
      
 61 
     | 
    
         
            +
                          \z
         
     | 
| 
      
 62 
     | 
    
         
            +
                          }mx
         
     | 
| 
      
 63 
     | 
    
         
            +
                      )
         
     | 
| 
       35 
64 
     | 
    
         | 
| 
      
 65 
     | 
    
         
            +
                      # rubocop:disable Style/DoubleNegation
         
     | 
| 
       36 
66 
     | 
    
         
             
                      messages << {
         
     | 
| 
       37 
67 
     | 
    
         
             
                        path: file,
         
     | 
| 
       38 
68 
     | 
    
         
             
                        position: line.to_i,
         
     | 
| 
       39 
     | 
    
         
            -
                        message:  
     | 
| 
       40 
     | 
    
         
            -
                         
     | 
| 
      
 69 
     | 
    
         
            +
                        message: match[:message],
         
     | 
| 
      
 70 
     | 
    
         
            +
                        rule: match[:cop],
         
     | 
| 
      
 71 
     | 
    
         
            +
                        corrected: !!match[:corrected],
         
     | 
| 
      
 72 
     | 
    
         
            +
                        correctable: !!match[:correctable],
         
     | 
| 
      
 73 
     | 
    
         
            +
                        severity: SEVERITY_MAP[severity],
         
     | 
| 
      
 74 
     | 
    
         
            +
                        source: "rubocop"
         
     | 
| 
       41 
75 
     | 
    
         
             
                      }
         
     | 
| 
      
 76 
     | 
    
         
            +
                      # rubocop:enable Style/DoubleNegation
         
     | 
| 
       42 
77 
     | 
    
         
             
                    end
         
     | 
| 
       43 
78 
     | 
    
         | 
| 
       44 
79 
     | 
    
         
             
                    messages
         
     | 
| 
         @@ -6,7 +6,6 @@ module Gergich 
     | 
|
| 
       6 
6 
     | 
    
         
             
                  # stylelint is a css linter
         
     | 
| 
       7 
7 
     | 
    
         
             
                  # https://github.com/stylelint/stylelint
         
     | 
| 
       8 
8 
     | 
    
         
             
                  #
         
     | 
| 
       9 
     | 
    
         
            -
                  # rubocop:disable Style/AsciiComments
         
     | 
| 
       10 
9 
     | 
    
         
             
                  # example full output:
         
     | 
| 
       11 
10 
     | 
    
         
             
                  # app/stylesheets/base/_print.scss
         
     | 
| 
       12 
11 
     | 
    
         
             
                  #  3:17  ✖  Unexpected invalid hex color "#owiehfi"   color-no-invalid-hex
         
     | 
| 
         @@ -16,8 +15,6 @@ module Gergich 
     | 
|
| 
       16 
15 
     | 
    
         
             
                  #   2:15  ✖  Unexpected invalid hex color "#2D3B4"   color-no-invalid-hex
         
     | 
| 
       17 
16 
     | 
    
         
             
                  #  30:15  ⚠  Expected "#2d3b4a" to be "#2D3B4A"      color-hex-case
         
     | 
| 
       18 
17 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                  MESSAGE_PREFIX = "[stylelint]"
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
18 
     | 
    
         
             
                  SEVERITY_MAP = {
         
     | 
| 
       22 
19 
     | 
    
         
             
                    "✖" => "error",
         
     | 
| 
       23 
20 
     | 
    
         
             
                    "⚠" => "warn",
         
     | 
| 
         @@ -31,7 +28,6 @@ module Gergich 
     | 
|
| 
       31 
28 
     | 
    
         
             
                  # example error line:
         
     | 
| 
       32 
29 
     | 
    
         
             
                  #   1:15  ✖  Unexpected invalid hex color "#2D3B4"   color-no-invalid-hex
         
     | 
| 
       33 
30 
     | 
    
         
             
                  ERROR_PATTERN = /^\s+(\d+):\d+\s+(✖|⚠|ℹ)\s+(.*?)\s\s+[^\n]+\n/.freeze
         
     | 
| 
       34 
     | 
    
         
            -
                  # rubocop:enable Style/AsciiComments
         
     | 
| 
       35 
31 
     | 
    
         | 
| 
       36 
32 
     | 
    
         
             
                  PATTERN = /#{FILE_PATH_PATTERN}((#{ERROR_PATTERN})+)/.freeze
         
     | 
| 
       37 
33 
     | 
    
         | 
| 
         @@ -41,7 +37,8 @@ module Gergich 
     | 
|
| 
       41 
37 
     | 
    
         
             
                        severity = SEVERITY_MAP[severity]
         
     | 
| 
       42 
38 
     | 
    
         
             
                        {
         
     | 
| 
       43 
39 
     | 
    
         
             
                          path: file,
         
     | 
| 
       44 
     | 
    
         
            -
                          message:  
     | 
| 
      
 40 
     | 
    
         
            +
                          message: error,
         
     | 
| 
      
 41 
     | 
    
         
            +
                          source: "stylelint",
         
     | 
| 
       45 
42 
     | 
    
         
             
                          position: line.to_i,
         
     | 
| 
       46 
43 
     | 
    
         
             
                          severity: severity
         
     | 
| 
       47 
44 
     | 
    
         
             
                        }
         
     | 
| 
         @@ -12,19 +12,19 @@ module Gergich 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  }.freeze
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                  def run(output)
         
     | 
| 
       15 
     | 
    
         
            -
                    # rubocop:disable  
     | 
| 
      
 15 
     | 
    
         
            +
                    # rubocop:disable Layout/LineLength
         
     | 
| 
       16 
16 
     | 
    
         
             
                    #
         
     | 
| 
       17 
17 
     | 
    
         
             
                    # Example:
         
     | 
| 
       18 
18 
     | 
    
         
             
                    # /path/to/My.swift:13:22: warning: Colon Violation: Colons should be next to the identifier when specifying a type. (colon)
         
     | 
| 
       19 
19 
     | 
    
         
             
                    # /path/to/Fail.swift:80: warning: Line Length Violation: Line should be 100 characters or less: currently 108 characters (line_length)
         
     | 
| 
       20 
20 
     | 
    
         
             
                    #
         
     | 
| 
       21 
     | 
    
         
            -
                    # rubocop:enable  
     | 
| 
      
 21 
     | 
    
         
            +
                    # rubocop:enable Layout/LineLength
         
     | 
| 
       22 
22 
     | 
    
         
             
                    pattern = /
         
     | 
| 
       23 
23 
     | 
    
         
             
                      ^([^:\n]+):(\d+)(?::\d+)?:\s(\w+):\s(.*?)\n
         
     | 
| 
       24 
24 
     | 
    
         
             
                    /mx
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
                    output.scan(pattern).map { |file, line, severity, error, _context|
         
     | 
| 
       27 
     | 
    
         
            -
                      { path: file, message: " 
     | 
| 
      
 27 
     | 
    
         
            +
                      { path: file, message: error, source: "swiftlint",
         
     | 
| 
       28 
28 
     | 
    
         
             
                        position: line.to_i, severity: SEVERITY_MAP[severity] }
         
     | 
| 
       29 
29 
     | 
    
         
             
                    }.compact
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Gergich
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Capture
         
     | 
| 
      
 5 
     | 
    
         
            +
                class YamllintCapture < BaseCapture
         
     | 
| 
      
 6 
     | 
    
         
            +
                  SEVERITY_MAP = { "error" => "error", "warning" => "warn" }.freeze
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  def run(output)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    # e.g. "  9:5       error    string value redundantly  (quoted-strings)"
         
     | 
| 
      
 10 
     | 
    
         
            +
                    error_pattern = %r{\s\s+(\d+):\d+\s+(\w+)\s+(.*?)\s+\([\w/-]+\)\n}
         
     | 
| 
      
 11 
     | 
    
         
            +
                    pattern = %r{            # Example:
         
     | 
| 
      
 12 
     | 
    
         
            +
                      ^./([^\n]+)\n         #   ./api/config/lti/development/config.yml
         
     | 
| 
      
 13 
     | 
    
         
            +
                      ((#{error_pattern})+)  #     9:5       error    string value redundantly  (quoted-strings)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    }mx
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    output.scan(pattern).map { |file, errors|
         
     | 
| 
      
 17 
     | 
    
         
            +
                      errors.scan(error_pattern).map { |line, severity, error|
         
     | 
| 
      
 18 
     | 
    
         
            +
                        severity = SEVERITY_MAP[severity]
         
     | 
| 
      
 19 
     | 
    
         
            +
                        {
         
     | 
| 
      
 20 
     | 
    
         
            +
                          path: file,
         
     | 
| 
      
 21 
     | 
    
         
            +
                          message: error,
         
     | 
| 
      
 22 
     | 
    
         
            +
                          source: "yamllint",
         
     | 
| 
      
 23 
     | 
    
         
            +
                          position: line.to_i,
         
     | 
| 
      
 24 
     | 
    
         
            +
                          severity: severity
         
     | 
| 
      
 25 
     | 
    
         
            +
                        }
         
     | 
| 
      
 26 
     | 
    
         
            +
                      }
         
     | 
| 
      
 27 
     | 
    
         
            +
                    }.compact.flatten
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/gergich/capture.rb
    CHANGED
    
    | 
         @@ -7,6 +7,7 @@ module Gergich 
     | 
|
| 
       7 
7 
     | 
    
         
             
              module Capture
         
     | 
| 
       8 
8 
     | 
    
         
             
                class BaseCapture
         
     | 
| 
       9 
9 
     | 
    
         
             
                  def self.inherited(subclass)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    super
         
     | 
| 
       10 
11 
     | 
    
         
             
                    name = normalize_captor_class_name(subclass)
         
     | 
| 
       11 
12 
     | 
    
         
             
                    Capture.captors[name] = subclass
         
     | 
| 
       12 
13 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -38,8 +39,14 @@ module Gergich 
     | 
|
| 
       38 
39 
     | 
    
         
             
                      comments.each do |comment|
         
     | 
| 
       39 
40 
     | 
    
         
             
                        next if skip_paths.any? { |path| comment[:path].start_with?(path) }
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
                        message = +"[#{comment[:source]}] "
         
     | 
| 
      
 43 
     | 
    
         
            +
                        message << "#{comment[:rule]}: " if comment[:rule]
         
     | 
| 
      
 44 
     | 
    
         
            +
                        message << comment[:message]
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                        draft.add_comment comment[:path],
         
     | 
| 
      
 47 
     | 
    
         
            +
                                          comment[:position],
         
     | 
| 
      
 48 
     | 
    
         
            +
                                          message,
         
     | 
| 
      
 49 
     | 
    
         
            +
                                          comment[:severity]
         
     | 
| 
       43 
50 
     | 
    
         
             
                      end
         
     | 
| 
       44 
51 
     | 
    
         
             
                    end
         
     | 
| 
       45 
52 
     | 
    
         | 
| 
         @@ -47,7 +54,7 @@ module Gergich 
     | 
|
| 
       47 
54 
     | 
    
         
             
                  end
         
     | 
| 
       48 
55 
     | 
    
         | 
| 
       49 
56 
     | 
    
         
             
                  def base_path
         
     | 
| 
       50 
     | 
    
         
            -
                    @base_path ||= File.expand_path(GERGICH_GIT_PATH) 
     | 
| 
      
 57 
     | 
    
         
            +
                    @base_path ||= "#{File.expand_path(GERGICH_GIT_PATH)}/"
         
     | 
| 
       51 
58 
     | 
    
         
             
                  end
         
     | 
| 
       52 
59 
     | 
    
         | 
| 
       53 
60 
     | 
    
         
             
                  def relativize(path)
         
     | 
| 
         @@ -75,7 +82,7 @@ module Gergich 
     | 
|
| 
       75 
82 
     | 
    
         
             
                      $stdout.puts line unless suppress_output
         
     | 
| 
       76 
83 
     | 
    
         
             
                      output << line
         
     | 
| 
       77 
84 
     | 
    
         
             
                    end
         
     | 
| 
       78 
     | 
    
         
            -
                    output.join 
     | 
| 
      
 85 
     | 
    
         
            +
                    output.join
         
     | 
| 
       79 
86 
     | 
    
         
             
                  end
         
     | 
| 
       80 
87 
     | 
    
         | 
| 
       81 
88 
     | 
    
         
             
                  def load_captor(format)
         
     | 
| 
         @@ -109,4 +116,4 @@ module Gergich 
     | 
|
| 
       109 
116 
     | 
    
         
             
              end
         
     | 
| 
       110 
117 
     | 
    
         
             
            end
         
     | 
| 
       111 
118 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
            Dir[File.dirname(__FILE__) 
     | 
| 
      
 119 
     | 
    
         
            +
            Dir["#{File.dirname(__FILE__)}/capture/*.rb"].sort.each { |file| require file }
         
     | 
    
        data/lib/gergich/cli/gergich.rb
    CHANGED
    
    | 
         @@ -14,10 +14,11 @@ CI_TEST_ARGS = { 
     | 
|
| 
       14 
14 
     | 
    
         
             
              ],
         
     | 
| 
       15 
15 
     | 
    
         
             
              "label" => ["Code-Review", 1],
         
     | 
| 
       16 
16 
     | 
    
         
             
              "message" => ["this is a test"],
         
     | 
| 
       17 
     | 
    
         
            -
              "capture" => ["rubocop", "echo  
     | 
| 
      
 17 
     | 
    
         
            +
              "capture" => ["rubocop", format("echo %<output>s", output: Shellwords.escape(<<~OUTPUT))]
         
     | 
| 
       18 
18 
     | 
    
         
             
                bin/gergich:47:8: C: Prefer double-quoted strings
         
     | 
| 
       19 
19 
     | 
    
         
             
                if ENV['DEBUG']
         
     | 
| 
       20 
20 
     | 
    
         
             
                       ^^^^^^^
         
     | 
| 
      
 21 
     | 
    
         
            +
                1 file inspected, 35 offenses detected, 27 offenses auto-correctable
         
     | 
| 
       21 
22 
     | 
    
         
             
              OUTPUT
         
     | 
| 
       22 
23 
     | 
    
         
             
            }.freeze
         
     | 
| 
       23 
24 
     | 
    
         | 
| 
         @@ -40,7 +41,7 @@ def run_ci_test!(all_commands) 
     | 
|
| 
       40 
41 
     | 
    
         | 
| 
       41 
42 
     | 
    
         
             
              commands.each do |command, args = []|
         
     | 
| 
       42 
43 
     | 
    
         
             
                arglist = args.map { |arg| Shellwords.escape(arg.to_s) }
         
     | 
| 
       43 
     | 
    
         
            -
                output = ` 
     | 
| 
      
 44 
     | 
    
         
            +
                output = `bundle exec gergich #{command} #{arglist.join(" ")} 2>&1`
         
     | 
| 
       44 
45 
     | 
    
         
             
                unless $CHILD_STATUS.success?
         
     | 
| 
       45 
46 
     | 
    
         
             
                  error "`gergich citest` failed on step `#{command}`:\n\n#{output.gsub(/^/, '  ')}\n"
         
     | 
| 
       46 
47 
     | 
    
         
             
                end
         
     | 
| 
         @@ -108,8 +109,8 @@ commands["comment"] = { 
     | 
|
| 
       108 
109 
     | 
    
         
             
              action: ->(comment_data) {
         
     | 
| 
       109 
110 
     | 
    
         
             
                comment_data = begin
         
     | 
| 
       110 
111 
     | 
    
         
             
                  JSON.parse(comment_data)
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
      
 112 
     | 
    
         
            +
                rescue JSON::ParserError
         
     | 
| 
      
 113 
     | 
    
         
            +
                  error("Unable to parse <comment_data> json", "comment")
         
     | 
| 
       113 
114 
     | 
    
         
             
                end
         
     | 
| 
       114 
115 
     | 
    
         
             
                comment_data = [comment_data] unless comment_data.is_a?(Array)
         
     | 
| 
       115 
116 
     | 
    
         | 
| 
         @@ -209,6 +210,7 @@ commands["capture"] = { 
     | 
|
| 
       209 
210 
     | 
    
         
             
                                    * i18nliner
         
     | 
| 
       210 
211 
     | 
    
         
             
                                    * flake8
         
     | 
| 
       211 
212 
     | 
    
         
             
                                    * stylelint
         
     | 
| 
      
 213 
     | 
    
         
            +
                                    * yamllint
         
     | 
| 
       212 
214 
     | 
    
         
             
                                    * custom:<path>:<class_name> - file path and ruby
         
     | 
| 
       213 
215 
     | 
    
         
             
                                      class_name of a custom formatter.
         
     | 
| 
       214 
216 
     | 
    
         | 
| 
         @@ -15,11 +15,11 @@ ERROR_DISTANCE = ENV.fetch("MASTER_BOUNCER_ERROR_DISTANCE", 100).to_i 
     | 
|
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            def potentially_mergeable_changes
         
     | 
| 
       17 
17 
     | 
    
         
             
              url = "/changes/?q=status:open+" \
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
                    "p:#{PROJECT}+" \
         
     | 
| 
      
 19 
     | 
    
         
            +
                    "label:Verified=1+" \
         
     | 
| 
      
 20 
     | 
    
         
            +
                    "is:mergeable+" \
         
     | 
| 
      
 21 
     | 
    
         
            +
                    "branch:master" \
         
     | 
| 
      
 22 
     | 
    
         
            +
                    "&o=CURRENT_REVISION"
         
     | 
| 
       23 
23 
     | 
    
         
             
              changes = Gergich::API.get(url)
         
     | 
| 
       24 
24 
     | 
    
         
             
              changes.reject { |c| c["subject"] =~ /\Awip($|\W)/i }
         
     | 
| 
       25 
25 
     | 
    
         
             
            end
         
     | 
| 
         @@ -62,7 +62,7 @@ def maybe_bounce_commit!(commit) 
     | 
|
| 
       62 
62 
     | 
    
         
             
              # similarly, over time the same patchset will become more out of date,
         
     | 
| 
       63 
63 
     | 
    
         
             
              # so we allow_repost (so to speak) so we can add increasingly negative
         
     | 
| 
       64 
64 
     | 
    
         
             
              # reviews
         
     | 
| 
       65 
     | 
    
         
            -
              review.publish!(: 
     | 
| 
      
 65 
     | 
    
         
            +
              review.publish!(allow_repost: true)
         
     | 
| 
       66 
66 
     | 
    
         
             
            end
         
     | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
68 
     | 
    
         
             
            commands = {}
         
     | 
    
        data/lib/gergich/cli.rb
    CHANGED
    
    
    
        data/lib/gergich.rb
    CHANGED
    
    | 
         @@ -1,10 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require "erb"
         
     | 
| 
       4 
     | 
    
         
            -
            require "sqlite3"
         
     | 
| 
       5 
4 
     | 
    
         
             
            require "json"
         
     | 
| 
       6 
5 
     | 
    
         
             
            require "fileutils"
         
     | 
| 
       7 
     | 
    
         
            -
            require "httparty"
         
     | 
| 
       8 
6 
     | 
    
         
             
            require "base64"
         
     | 
| 
       9 
7 
     | 
    
         | 
| 
       10 
8 
     | 
    
         
             
            GERGICH_REVIEW_LABEL = ENV.fetch("GERGICH_REVIEW_LABEL", "Code-Review")
         
     | 
| 
         @@ -53,15 +51,13 @@ module Gergich 
     | 
|
| 
       53 
51 
     | 
    
         
             
                end
         
     | 
| 
       54 
52 
     | 
    
         | 
| 
       55 
53 
     | 
    
         
             
                def files
         
     | 
| 
       56 
     | 
    
         
            -
                  @files ||=  
     | 
| 
       57 
     | 
    
         
            -
                     
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                     
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                       
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                        .flatten
         
     | 
| 
       64 
     | 
    
         
            -
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @files ||= if Gergich.use_git?
         
     | 
| 
      
 55 
     | 
    
         
            +
                    Gergich.git("diff-tree --no-commit-id --name-only -r #{ref}").split
         
     | 
| 
      
 56 
     | 
    
         
            +
                  else
         
     | 
| 
      
 57 
     | 
    
         
            +
                    raw = API.get("/changes/#{change_id}/revisions/#{revision_id}/patch", raw: true)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    Base64.decode64(raw)
         
     | 
| 
      
 59 
     | 
    
         
            +
                      .scan(%r{^diff --git a/.*? b/(.*?)$})
         
     | 
| 
      
 60 
     | 
    
         
            +
                      .flatten
         
     | 
| 
       65 
61 
     | 
    
         
             
                  end
         
     | 
| 
       66 
62 
     | 
    
         
             
                end
         
     | 
| 
       67 
63 
     | 
    
         | 
| 
         @@ -72,7 +68,7 @@ module Gergich 
     | 
|
| 
       72 
68 
     | 
    
         
             
                def revision_number
         
     | 
| 
       73 
69 
     | 
    
         
             
                  @revision_number ||= begin
         
     | 
| 
       74 
70 
     | 
    
         
             
                    patchset_number = ENV["GERRIT_PATCHSET_NUMBER"]
         
     | 
| 
       75 
     | 
    
         
            -
                    return patchset_number unless patchset_number.nil?
         
     | 
| 
      
 71 
     | 
    
         
            +
                    return patchset_number unless patchset_number.nil? # rubocop:disable Lint/NoReturnInBeginEndBlocks
         
     | 
| 
       76 
72 
     | 
    
         | 
| 
       77 
73 
     | 
    
         
             
                    gerrit_info = API.get("/changes/?q=#{change_id}&o=ALL_REVISIONS")[0]
         
     | 
| 
       78 
74 
     | 
    
         
             
                    raise GergichError, "Gerrit patchset not found" unless gerrit_info
         
     | 
| 
         @@ -99,7 +95,7 @@ module Gergich 
     | 
|
| 
       99 
95 
     | 
    
         
             
                end
         
     | 
| 
       100 
96 
     | 
    
         | 
| 
       101 
97 
     | 
    
         
             
                # Public: publish all draft comments/labels/messages
         
     | 
| 
       102 
     | 
    
         
            -
                def publish!(allow_repost  
     | 
| 
      
 98 
     | 
    
         
            +
                def publish!(allow_repost: false)
         
     | 
| 
       103 
99 
     | 
    
         
             
                  # only publish if we have something to say or if our last score was negative
         
     | 
| 
       104 
100 
     | 
    
         
             
                  return unless anything_to_publish?
         
     | 
| 
       105 
101 
     | 
    
         | 
| 
         @@ -202,13 +198,11 @@ module Gergich 
     | 
|
| 
       202 
198 
     | 
    
         
             
                # currently, cover message only supports the GERGICH_REVIEW_LABEL.
         
     | 
| 
       203 
199 
     | 
    
         
             
                # i.e., even if gergich has "Code-Review: -2"
         
     | 
| 
       204 
200 
     | 
    
         
             
                def current_label
         
     | 
| 
       205 
     | 
    
         
            -
                  @current_label ||=  
     | 
| 
       206 
     | 
    
         
            -
                     
     | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
             
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
                      .first
         
     | 
| 
       211 
     | 
    
         
            -
                  end
         
     | 
| 
      
 201 
     | 
    
         
            +
                  @current_label ||= API.get("/changes/#{commit.change_id}/detail")["labels"]
         
     | 
| 
      
 202 
     | 
    
         
            +
                    .fetch(GERGICH_REVIEW_LABEL, {})
         
     | 
| 
      
 203 
     | 
    
         
            +
                    .fetch("all", [])
         
     | 
| 
      
 204 
     | 
    
         
            +
                    .select { |label| label["username"] == GERGICH_USER }
         
     | 
| 
      
 205 
     | 
    
         
            +
                    .first
         
     | 
| 
       212 
206 
     | 
    
         
             
                end
         
     | 
| 
       213 
207 
     | 
    
         | 
| 
       214 
208 
     | 
    
         
             
                def current_label_date
         
     | 
| 
         @@ -234,7 +228,7 @@ module Gergich 
     | 
|
| 
       234 
228 
     | 
    
         
             
                end
         
     | 
| 
       235 
229 
     | 
    
         | 
| 
       236 
230 
     | 
    
         
             
                def current_score
         
     | 
| 
       237 
     | 
    
         
            -
                  current_label && current_label["value"] || 0
         
     | 
| 
      
 231 
     | 
    
         
            +
                  (current_label && current_label["value"]) || 0
         
     | 
| 
       238 
232 
     | 
    
         
             
                end
         
     | 
| 
       239 
233 
     | 
    
         | 
| 
       240 
234 
     | 
    
         
             
                def cover_message
         
     | 
| 
         @@ -292,6 +286,8 @@ module Gergich 
     | 
|
| 
       292 
286 
     | 
    
         
             
                  private
         
     | 
| 
       293 
287 
     | 
    
         | 
| 
       294 
288 
     | 
    
         
             
                  def perform(method, url, options)
         
     | 
| 
      
 289 
     | 
    
         
            +
                    # delay requiring httparty until here, to make local command line runs as fast as possible
         
     | 
| 
      
 290 
     | 
    
         
            +
                    require "httparty"
         
     | 
| 
       295 
291 
     | 
    
         
             
                    options = prepare_options(options)
         
     | 
| 
       296 
292 
     | 
    
         
             
                    ret = HTTParty.send(method, url, options).body
         
     | 
| 
       297 
293 
     | 
    
         
             
                    return ret if options[:raw]
         
     | 
| 
         @@ -314,7 +310,7 @@ module Gergich 
     | 
|
| 
       314 
310 
     | 
    
         
             
                  def base_uri
         
     | 
| 
       315 
311 
     | 
    
         
             
                    @base_uri ||= \
         
     | 
| 
       316 
312 
     | 
    
         
             
                      ENV["GERRIT_BASE_URL"] ||
         
     | 
| 
       317 
     | 
    
         
            -
                      ENV.key?("GERRIT_HOST") && "https://#{ENV['GERRIT_HOST']}" ||
         
     | 
| 
      
 313 
     | 
    
         
            +
                      (ENV.key?("GERRIT_HOST") && "https://#{ENV['GERRIT_HOST']}") ||
         
     | 
| 
       318 
314 
     | 
    
         
             
                      raise(GergichError, "need to set GERRIT_BASE_URL or GERRIT_HOST")
         
     | 
| 
       319 
315 
     | 
    
         
             
                  end
         
     | 
| 
       320 
316 
     | 
    
         | 
| 
         @@ -338,7 +334,7 @@ module Gergich 
     | 
|
| 
       338 
334 
     | 
    
         | 
| 
       339 
335 
     | 
    
         
             
                  def prepare_options(options)
         
     | 
| 
       340 
336 
     | 
    
         
             
                    options = {
         
     | 
| 
       341 
     | 
    
         
            -
                      base_uri: base_uri 
     | 
| 
      
 337 
     | 
    
         
            +
                      base_uri: "#{base_uri}/a"
         
     | 
| 
       342 
338 
     | 
    
         
             
                    }.merge(auth_config).merge(options)
         
     | 
| 
       343 
339 
     | 
    
         
             
                    if options[:body]
         
     | 
| 
       344 
340 
     | 
    
         
             
                      options[:headers] ||= {}
         
     | 
| 
         @@ -363,11 +359,14 @@ module Gergich 
     | 
|
| 
       363 
359 
     | 
    
         
             
                end
         
     | 
| 
       364 
360 
     | 
    
         | 
| 
       365 
361 
     | 
    
         
             
                def db_file
         
     | 
| 
       366 
     | 
    
         
            -
                  @db_file ||= File.expand_path( 
     | 
| 
      
 362 
     | 
    
         
            +
                  @db_file ||= File.expand_path(
         
     | 
| 
      
 363 
     | 
    
         
            +
                    "#{ENV.fetch('GERGICH_DB_PATH', '/tmp')}/#{GERGICH_USER}-#{commit.revision_id}.sqlite3"
         
     | 
| 
      
 364 
     | 
    
         
            +
                  )
         
     | 
| 
       367 
365 
     | 
    
         
             
                end
         
     | 
| 
       368 
366 
     | 
    
         | 
| 
       369 
367 
     | 
    
         
             
                def db
         
     | 
| 
       370 
368 
     | 
    
         
             
                  @db ||= begin
         
     | 
| 
      
 369 
     | 
    
         
            +
                    require "sqlite3"
         
     | 
| 
       371 
370 
     | 
    
         
             
                    db_exists = File.exist?(db_file)
         
     | 
| 
       372 
371 
     | 
    
         
             
                    db = SQLite3::Database.new(db_file)
         
     | 
| 
       373 
372 
     | 
    
         
             
                    db.results_as_hash = true
         
     | 
| 
         @@ -512,7 +511,7 @@ module Gergich 
     | 
|
| 
       512 
511 
     | 
    
         | 
| 
       513 
512 
     | 
    
         
             
                def info
         
     | 
| 
       514 
513 
     | 
    
         
             
                  @info ||= begin
         
     | 
| 
       515 
     | 
    
         
            -
                    comments =  
     | 
| 
      
 514 
     | 
    
         
            +
                    comments = inline_comments.map { |file| [file.path, file.to_a] }.to_h
         
     | 
| 
       516 
515 
     | 
    
         | 
| 
       517 
516 
     | 
    
         
             
                    {
         
     | 
| 
       518 
517 
     | 
    
         
             
                      comments: comments,
         
     | 
| 
         @@ -530,9 +529,9 @@ module Gergich 
     | 
|
| 
       530 
529 
     | 
    
         | 
| 
       531 
530 
     | 
    
         
             
                def orphaned_message
         
     | 
| 
       532 
531 
     | 
    
         
             
                  messages = ["NOTE: I couldn't create inline comments for everything. " \
         
     | 
| 
       533 
     | 
    
         
            -
             
     | 
| 
       534 
     | 
    
         
            -
             
     | 
| 
       535 
     | 
    
         
            -
             
     | 
| 
      
 532 
     | 
    
         
            +
                              "Although this isn't technically part of your commit, you " \
         
     | 
| 
      
 533 
     | 
    
         
            +
                              "should still check it out (i.e. side effects or auto-" \
         
     | 
| 
      
 534 
     | 
    
         
            +
                              "generated from stuff you *did* change):"]
         
     | 
| 
       536 
535 
     | 
    
         | 
| 
       537 
536 
     | 
    
         
             
                  other_comments.each do |file|
         
     | 
| 
       538 
537 
     | 
    
         
             
                    file.comments.each do |position, comments|
         
     |