<commit_before>require 'json'
require 'state_machine'
require 'dm-migrations'
require 'git'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, "postgres://stompbox:stompbox@localhost/stompbox")

class Push
  include DataMapper::Resource

  property :id,         Serial
  property :status,     String
  property :payload,    Text, :required => true, :lazy => false
  property :created_at, DateTime

  state_machine :status, :initial => :received do

    event :deploy do
      # If any pushes are already deployed, undeploy them
      # Git the push
      # torquebox:archive & deploy
      # Write deployment date
      transition all - :deployed => :deploying
    end

    event :deployed do
      transition :deploying => :deployed
    end

    event :failed do
      transition :deploying => :failed
    end

    event :undeploy do
      # Write undeployment date
      transition :deployed => :undeploying
    end

    event :undeployed do
      transition :undeploying => :undeployed
    end

  end

  attr_accessor :parsed_payload

  def [](property)
    parse[property]
  end

  # Use tcrawley's background stuff
  def background_deploy
    self.deploy
    # Hack to avoid problems with github responses using git gem over https
    repo = self['repository']['url'].sub('https', 'git')
    git = Git.clone(repo, self['repository']['name'], :path=>config['deployments'])
    self.deployed
  end

  # Use tcrawley's background stuff
  def background_undeploy
    self.undeploy!
    self.undeployed!
  end

  protected
  def parse
    @parsed_payload ||= JSON.parse(self.payload)
  end

  def config
    YAML::load(File.open("config/stompbox.yml"))
  end

end

DataMapper.auto_upgrade!

<commit_msg>Reset git repo to the commit hash on deployment<commit_after>require 'json'
require 'state_machine'
require 'dm-migrations'
require 'git'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, "postgres://stompbox:stompbox@localhost/stompbox")

class Push
  include DataMapper::Resource

  property :id,         Serial
  property :status,     String
  property :payload,    Text, :required => true, :lazy => false
  property :created_at, DateTime

  state_machine :status, :initial => :received do

    event :deploy do
      # If any pushes are already deployed, undeploy them
      # Git the push
      # torquebox:archive & deploy
      # Write deployment date
      transition all - :deployed => :deploying
    end

    event :deployed do
      transition :deploying => :deployed
    end

    event :failed do
      transition :deploying => :failed
    end

    event :undeploy do
      # Write undeployment date
      transition :deployed => :undeploying
    end

    event :undeployed do
      transition :undeploying => :undeployed
    end

  end

  attr_accessor :parsed_payload

  def [](property)
    parse[property]
  end

  # Use tcrawley's background stuff
  def background_deploy
    self.deploy
    # Hack to avoid problems with github responses using git gem over https
    repo = self['repository']['url'].sub('https', 'git')
    git = Git.clone(repo, self['repository']['name'], :path=>config['deployments'])
    git.reset_hard(self['after'])
    self.deployed
  end

  # Use tcrawley's background stuff
  def background_undeploy
    self.undeploy!
    self.undeployed!
  end

  protected
  def parse
    @parsed_payload ||= JSON.parse(self.payload)
  end

  def config
    YAML::load(File.open("config/stompbox.yml"))
  end

end

DataMapper.auto_upgrade!


{'fraction_non_alphanumeric': 0.09777651083238312, 'fraction_numerical': 0.0, 'mean_word_length': 3.2636695018226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '7269635', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1031, 'n_words': 305}