<commit_before>class CommitController < ApplicationController
  helper :diff
  helper :chunk

  before_filter :get_commit

  def get_commit
    @project = Project.find(:first, :conditions => [ 'name = ?', params[:project] ])
    puts "Project is #{@project.inspect}"
    @commit = Commit.by_sha1(:sha1 => params[:sha1],
                             :project => @project)
  end

  def diff
    @diff = @commit.diff
  end

  def show
  end

  def json
    render :json => @commit
  end

  def approved
    render :json => @commit.approved?
  end

  def changed
    render :json => @commit.changed_files
  end

end<commit_msg>Add commit/approve action<commit_after>class CommitController < ApplicationController
  helper :diff
  helper :chunk

  before_filter :authenticate, :only => [:approve]

  before_filter :get_commit

  def get_commit
    @project = Project.find(:first, :conditions => [ 'name = ?', params[:project] ])
    puts "Project is #{@project.inspect}"
    @commit = Commit.by_sha1(:sha1 => params[:sha1],
                             :project => @project)
  end

  def diff
    @diff = @commit.diff
  end

  def show
  end

  def json
    render :json => @commit
  end

  def approved
    render :json => @commit.approved?
  end

  def changed
    render :json => @commit.changed_files
  end

  def approve
    raise "no commit" if @commit.nil?
    @approval = Approval.new(
                            :commit => @commit,
                            :approved_by => session[:username],
                            :approved_on => Time.new()
                               )

    begin
      @approval.save
    rescue ActiveRecord::StatementInvalid
      # Probably trying to approve something already approved
      render :text => 'Cannot approve same commit twice' and return
    end
    render :text => 'Commit approved'
  end

end
{'fraction_non_alphanumeric': 0.10275824770146025, 'fraction_numerical': 0.003244997295835587, 'mean_word_length': 2.2918149466192173, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3501359', 'n_tokens_mistral': 548, 'n_tokens_neox': 526, 'n_words': 153}