Sha256: e7cbe9623231933533ccc7adbff3c945b6b388fe33e6982b6c626dd11b501ed0

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 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.1 lib/danger_plugin.rb