Sha256: 8234d21e99ce8d4253b741c527c00119265533c1f4c46ed99006cfda9a6b39ce

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Danger
  # Enforce linear history inside your project.
  #
  # @example Running with warnings
  #
  #          # Enforces linear history, but does not fail the pull request
  #          # linear_history.validate!(soft_fail: true)
  #          linear_history.validate!
  #
  # @example Running with errors
  #
  #          # Enforces linear history, failing the pull request if applicable
  #          linear_history.validate!(soft_fail: false)
  #
  # @see  tootbot/tootbot
  # @tags git
  #
  class LinearHistory < Plugin
    # Validates the pull request commits to ensure linear history.
    #
    # @param  [Bool] soft_fail
    #                Toggles output behavior between warn and fail.
    #                Defaults to true (warn).
    #
    # @return [void]
    #
    def validate!(soft_fail: true)
      return unless git.commits.any? { |commit| commit.parents.length > 1 }

      message = 'Please rebase to get rid of the merge commits in this PR'

      if soft_fail
        warn message
      else
        fail message
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-linear_history-0.0.2 lib/danger_plugin.rb