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
|
def archive
|
||||||
format, @treeish = params[:format], params[:treeish]
|
format, @treeish = params[:format], params[:treeish]
|
||||||
if (@treeish =~ /^#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^(zip|tar\.gz)$/)
|
raise Grit::NoSuchPathError unless @treeish =~ /^#{@project.name}-/ &&
|
||||||
@treeish = @treeish.gsub(/^#{@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
|
@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
|
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?
|
if sha1.present?
|
||||||
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
|
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
|
||||||
else
|
else
|
||||||
|
|
|
@ -2,8 +2,8 @@ class BuildScript < ActiveRecord::Base
|
||||||
include FileStoreClean
|
include FileStoreClean
|
||||||
|
|
||||||
STATUSES = [
|
STATUSES = [
|
||||||
active = 'active',
|
ACTIVE = 'active',
|
||||||
blocked = 'blocked'
|
BLOCKED = 'blocked'
|
||||||
]
|
]
|
||||||
FORMAT = 'tar.gz'
|
FORMAT = 'tar.gz'
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ class BuildScript < ActiveRecord::Base
|
||||||
validates :treeish, presence: true
|
validates :treeish, presence: true
|
||||||
validates :project_id, presence: true, uniqueness: { scope: :treeish }
|
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) }
|
scope :by_treeish, -> treeish { where(treeish: treeish) }
|
||||||
|
|
||||||
before_validation :attach_project
|
before_validation :attach_project
|
||||||
|
|
Loading…
Reference in New Issue