arangamani/jenkins_api_client

View on GitHub
lib/jenkins_api_client/client.rb

Summary

Maintainability
F
4 days
Test Coverage

File client.rb has 485 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rubygems'
require 'json'
require 'net/http'
require 'net/https'
require 'nokogiri'
Severity: Minor
Found in lib/jenkins_api_client/client.rb - About 7 hrs to fix

    Method initialize has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(args)
          args = symbolize_keys(args)
          args.each do |key, value|
            if value && VALID_PARAMS.include?(key.to_s)
              instance_variable_set("@#{key}", value)
    Severity: Minor
    Found in lib/jenkins_api_client/client.rb - About 6 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Class Client has 35 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Client
        attr_accessor :timeout, :logger
        # Default port to be used to connect to Jenkins
        DEFAULT_SERVER_PORT = 8080
        # Default timeout in seconds to be used while performing operations
    Severity: Minor
    Found in lib/jenkins_api_client/client.rb - About 4 hrs to fix

      Method make_http_request has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def make_http_request(request, follow_redirect = @follow_redirects)
            request.basic_auth @username, @password if @username
            request['Cookie'] = @cookies if @cookies
      
            if @proxy_ip
      Severity: Minor
      Found in lib/jenkins_api_client/client.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method handle_exception has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def handle_exception(response, to_send = "code", send_json = false)
            msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
            @logger.debug msg
            case response.code.to_i
            # As of Jenkins version 1.519, the job builds return a 201 status code
      Severity: Minor
      Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

        Method initialize has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def initialize(args)
              args = symbolize_keys(args)
              args.each do |key, value|
                if value && VALID_PARAMS.include?(key.to_s)
                  instance_variable_set("@#{key}", value)
        Severity: Minor
        Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

          Method handle_exception has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle_exception(response, to_send = "code", send_json = false)
                msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
                @logger.debug msg
                case response.code.to_i
                # As of Jenkins version 1.519, the job builds return a 201 status code
          Severity: Minor
          Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method refresh_crumbs has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def refresh_crumbs(force_refresh = false)
                # Quick check to see if someone has changed XSS settings and not
                # restarted us
                if force_refresh || @crumbs_enabled.nil?
                  old_crumbs_setting = @crumbs_enabled
          Severity: Minor
          Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method make_http_request has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def make_http_request(request, follow_redirect = @follow_redirects)
                request.basic_auth @username, @password if @username
                request['Cookie'] = @cookies if @cookies
          
                if @proxy_ip
          Severity: Minor
          Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

            Method api_post_request has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def api_post_request(url_prefix, form_data = {}, raw_response = false)
                  retries = @crumb_max_retries
                  begin
                    refresh_crumbs
            
            
            Severity: Minor
            Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method api_post_request has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def api_post_request(url_prefix, form_data = {}, raw_response = false)
                  retries = @crumb_max_retries
                  begin
                    refresh_crumbs
            
            
            Severity: Minor
            Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

              Method post_data has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def post_data(url_prefix, data, content_type)
                    retries = @crumb_max_retries
                    begin
                      refresh_crumbs
              
              
              Severity: Minor
              Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method post_data has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def post_data(url_prefix, data, content_type)
                    retries = @crumb_max_retries
                    begin
                      refresh_crumbs
              
              
              Severity: Minor
              Found in lib/jenkins_api_client/client.rb - About 1 hr to fix

                Method compare_versions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    def compare_versions(version_a, version_b)
                      if version_a == version_b
                        return 0
                      else
                        version_a_d = deconstruct_version_string(version_a)
                Severity: Minor
                Found in lib/jenkins_api_client/client.rb - About 55 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Consider simplifying this complex logical expression.
                Open

                        if version_a_d[0] > version_b_d[0] ||
                          (version_a_d[0] == version_b_d[0] && version_a_d[1] > version_b_d[1]) ||
                          (version_a_d[0] == version_b_d[0] && version_a_d[1] == version_b_d[1] && version_a_d[2] > version_b_d[2])
                          return 1
                        else
                Severity: Major
                Found in lib/jenkins_api_client/client.rb - About 40 mins to fix

                  Method exec_cli has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def exec_cli(command, args = [])
                        base_dir = File.dirname(__FILE__)
                        server_url = "http://#{@server_ip}:#{@server_port}/#{@jenkins_path}"
                        cmd = "java -jar #{base_dir}/../../java_deps/jenkins-cli.jar -s #{server_url}"
                        cmd << " -i #{@identity_file}" if @identity_file && !@identity_file.empty?
                  Severity: Minor
                  Found in lib/jenkins_api_client/client.rb - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method get_artifacts has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_artifacts(job_name, dldir, build_number = nil)
                        @artifacts = job.find_artifacts(job_name,build_number)
                        results = []
                        @artifacts.each do |artifact|
                          uri = URI.parse(artifact)
                  Severity: Minor
                  Found in lib/jenkins_api_client/client.rb - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                        rescue Exceptions::ForbiddenException => e
                          refresh_crumbs(true)
                  
                          if @crumbs_enabled
                            @logger.info "Retrying: #{@crumb_max_retries - retries + 1} out of" +
                  Severity: Minor
                  Found in lib/jenkins_api_client/client.rb and 1 other location - About 50 mins to fix
                  lib/jenkins_api_client/client.rb on lines 522..538

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 43.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                        rescue Exceptions::ForbiddenException => e
                          refresh_crumbs(true)
                  
                          if @crumbs_enabled
                            @logger.info "Retrying: #{@crumb_max_retries - retries + 1} out of" +
                  Severity: Minor
                  Found in lib/jenkins_api_client/client.rb and 1 other location - About 50 mins to fix
                  lib/jenkins_api_client/client.rb on lines 461..477

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 43.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status