<commit_before>require 'fileutils'

class Deploy < Task
  state_machine :status do
    after_transition to: :success, do: :schedule_continuous_delivery
    after_transition to: :success, do: :update_undeployed_commits_count
  end

  before_create :denormalize_commit_stats
  after_commit :broadcast_update

  delegate :broadcast_update, to: :stack

  def build_rollback(user = nil)
    Rollback.new(
      user_id: user.try!(:id),
      stack_id: stack_id,
      parent_id: id,
      since_commit: stack.last_deployed_commit,
      until_commit: until_commit,
    )
  end

  def trigger_rollback(user)
    rollback = build_rollback(user)
    rollback.save!
    rollback.enqueue

    lock_reason = "A rollback for #{rollback.since_commit.sha} has been triggered. " \
      "Please make sure the reason for the rollback has been addressed before deploying again."
    stack.update!(lock_reason: lock_reason, lock_author_id: user.id)

    rollback
  end

  def rollback?
    false
  end

  def commit_range
    [since_commit, until_commit]
  end

  def rollbackable?
    stack.supports_rollback? && success? && self != stack.last_deploy
  end
<commit_msg>Fix Deploy#rollbackable? to consider currently deployed commit not last successful deploy<commit_after>require 'fileutils'

class Deploy < Task
  state_machine :status do
    after_transition to: :success, do: :schedule_continuous_delivery
    after_transition to: :success, do: :update_undeployed_commits_count
  end

  before_create :denormalize_commit_stats
  after_commit :broadcast_update

  delegate :broadcast_update, to: :stack

  def build_rollback(user = nil)
    Rollback.new(
      user_id: user.try!(:id),
      stack_id: stack_id,
      parent_id: id,
      since_commit: stack.last_deployed_commit,
      until_commit: until_commit,
    )
  end

  def trigger_rollback(user)
    rollback = build_rollback(user)
    rollback.save!
    rollback.enqueue

    lock_reason = "A rollback for #{rollback.since_commit.sha} has been triggered. " \
      "Please make sure the reason for the rollback has been addressed before deploying again."
    stack.update!(lock_reason: lock_reason, lock_author_id: user.id)

    rollback
  end

  def rollback?
    false
  end

  def commit_range
    [since_commit, until_commit]
  end

  def rollbackable?
    stack.supports_rollback? && success? && until_commit_id != stack.last_deployed_commit.try!(:id)
  end

{'fraction_non_alphanumeric': 0.07676348547717843, 'fraction_numerical': 0.0, 'mean_word_length': 3.822, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6232642', 'n_tokens_mistral': 785, 'n_tokens_neox': 763, 'n_words': 194}