repositories_controller.rb revision 03dee28977299b4b40210d9b7842bf85c136ab7d
7384b4e78eaab44693c985192276e31322155e32Stephan Boschclass RepositoriesController < ApplicationController
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch inherit_resources
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch defaults finder: :find_by_path!
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch load_and_authorize_resource :except => [:index, :show]
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch def files
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch @path = params[:path]
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch commit_id = @repository.commit_id(params[:oid])
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch @oid = commit_id[:oid]
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch @branch_name = commit_id[:branch_name]
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch @is_head = @repository.is_head?(@oid)
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch
9e7bf91667639a2390207ab4d90bf88e2afcec2aStephan Bosch @info = @repository.path_info(params[:path], @oid)
50a6d26bd9041f44b4cad0c0357c0c604c132cc8Stephan Bosch
50a6d26bd9041f44b4cad0c0357c0c604c132cc8Stephan Bosch raise Repository::FileNotFoundError, @path if @info.nil?
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
1175415b88ff168e367c77df23901eada13225b9Stephan Bosch case @info[:type]
50a6d26bd9041f44b4cad0c0357c0c604c132cc8Stephan Bosch when :raw
50a6d26bd9041f44b4cad0c0357c0c604c132cc8Stephan Bosch render text: @repository.read_file(@path, @oid)[:content],
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch content_type: Mime::Type.lookup('application/force-download')
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch when :file_base
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch @file = @repository.read_file(@info[:entry][:path], params[:oid])
end
end
def entries_info
render json: @repository.entries_info(@oid, params[:path])
end
def diff
@oid = @repository.commit_id(params[:oid])[:oid]
@changed_files = @repository.changed_files(@oid)
end
def history
@path = params[:path]
@oid = @repository.commit_id(params[:oid])[:oid]
@current_file = @repository.read_file(@path, @oid) if @path
@commits = @repository.commits(@oid, @path)
end
end