refactoring according to Alexander's comments
This commit is contained in:
parent
9b39f3779a
commit
518c87994c
|
@ -17,14 +17,18 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
|||
|
||||
def archive
|
||||
format, @treeish = params[:format], params[:treeish]
|
||||
if (@treeish =~ /^#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^(zip|tar\.gz)$/)
|
||||
@treeish = @treeish.gsub(/^#{@project.name}-/, '')
|
||||
raise Grit::NoSuchPathError unless @treeish =~ /^#{@project.name}-/ &&
|
||||
@treeish !~ /[\s]+/ &&
|
||||
format =~ /^(zip|tar\.gz)$/
|
||||
@treeish.gsub!(/^#{@project.name}-/, '')
|
||||
sha1 = @project.build_scripts.by_active.by_treeish(@treeish).first.try(:sha1)
|
||||
unless sha1
|
||||
@commit = @project.repo.commits(@treeish, 1).first
|
||||
raise Grit::NoSuchPathError unless @commit
|
||||
tag = @project.repo.tags.find{ |t| t.name == @treeish }
|
||||
sha1 = @project.get_project_tag_sha1(tag, format) if tag
|
||||
end
|
||||
raise Grit::NoSuchPathError unless @commit
|
||||
tag = @project.repo.tags.find{ |t| t.name == @treeish }
|
||||
sha1 = @project.get_project_tag_sha1(tag, format) if tag
|
||||
sha1 ||= @project.build_scripts.by_active.by_treeish(@treeish).first.try(:sha1)
|
||||
|
||||
if sha1.present?
|
||||
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
|
||||
else
|
||||
|
|
|
@ -2,8 +2,8 @@ class BuildScript < ActiveRecord::Base
|
|||
include FileStoreClean
|
||||
|
||||
STATUSES = [
|
||||
active = 'active',
|
||||
blocked = 'blocked'
|
||||
ACTIVE = 'active',
|
||||
BLOCKED = 'blocked'
|
||||
]
|
||||
FORMAT = 'tar.gz'
|
||||
|
||||
|
@ -12,7 +12,7 @@ class BuildScript < ActiveRecord::Base
|
|||
validates :treeish, presence: true
|
||||
validates :project_id, presence: true, uniqueness: { scope: :treeish }
|
||||
|
||||
scope :by_active, -> { where(status: 'active') }
|
||||
scope :by_active, -> { where(status: ACTIVE) }
|
||||
scope :by_treeish, -> treeish { where(treeish: treeish) }
|
||||
|
||||
before_validation :attach_project
|
||||
|
|
Loading…
Reference in New Issue