gitlabhq/gitlabhq

View on GitHub
app/models/merge_request.rb

Summary

Maintainability
F
6 days
Test Coverage

Class MergeRequest has 160 methods (exceeds 20 allowed). Consider refactoring.
Open

class MergeRequest < ApplicationRecord
  include AtomicInternalId
  include IidRoutes
  include Issuable
  include Noteable
Severity: Major
Found in app/models/merge_request.rb - About 3 days to fix

    File merge_request.rb has 1031 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class MergeRequest < ApplicationRecord
      include AtomicInternalId
      include IidRoutes
      include Issuable
      include Noteable
    Severity: Major
    Found in app/models/merge_request.rb - About 2 days to fix

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

        def mergeable_state?(skip_ci_check: false, skip_discussions_check: false)
          return false unless open?
          return false if work_in_progress?
          return false if broken?
          return false unless skip_ci_check || mergeable_ci_state?
      Severity: Minor
      Found in app/models/merge_request.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

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

        def mergeable_with_quick_action?(current_user, autocomplete_precheck: false, last_diff_sha: nil)
          return false unless can_be_merged_by?(current_user)
      
          return true if autocomplete_precheck
      
      
      Severity: Minor
      Found in app/models/merge_request.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

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

        def validate_branches
          return unless target_project && source_project
      
          if target_project == source_project && target_branch == source_branch
            errors.add :branch_conflict, "You can't use same project/branch for source and target"
      Severity: Minor
      Found in app/models/merge_request.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

      Method cache_merge_request_closes_issues! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def cache_merge_request_closes_issues!(current_user = self.author)
          return unless project.issues_enabled?
          return if closed? || merged?
      
          transaction do
      Severity: Minor
      Found in app/models/merge_request.rb - About 45 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

      Avoid too many return statements within this method.
      Open

          return false unless skip_discussions_check || mergeable_discussions_state?
      Severity: Major
      Found in app/models/merge_request.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

            return false if last_diff_sha != diff_head_sha
        Severity: Major
        Found in app/models/merge_request.rb - About 30 mins to fix

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

            def validate_fork
              return true unless target_project && source_project
              return true if target_project == source_project
              return true unless source_project_missing?
          
          
          Severity: Minor
          Found in app/models/merge_request.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 predefined_variables has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def predefined_variables
              Gitlab::Ci::Variables::Collection.new.tap do |variables|
                variables.append(key: 'CI_MERGE_REQUEST_ID', value: id.to_s)
                variables.append(key: 'CI_MERGE_REQUEST_IID', value: iid.to_s)
                variables.append(key: 'CI_MERGE_REQUEST_REF_PATH', value: ref_path.to_s)
          Severity: Minor
          Found in app/models/merge_request.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 validate_branch_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def validate_branch_name(attr)
              return unless changes_include?(attr)
          
              branch = read_attribute(attr)
          
          
          Severity: Minor
          Found in app/models/merge_request.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

          There are no issues that match your filters.

          Category
          Status