Merge pull request #722 from warpc/90-error_on_create
[refs #90] Fix error on pull create, create special place for temporary pull request, add cron task for clear temporary pull request, add cron task for clearing activity feed, fix build list pagination error
This commit is contained in:
commit
41ce06b36e
|
@ -26,7 +26,8 @@ class Projects::BuildListsController < Projects::BaseController
|
|||
@action_url = @project ? search_project_build_lists_path(@project) : search_build_lists_path
|
||||
@filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
|
||||
|
||||
@bls = @filter.find.recent.paginate :page => params[:page]
|
||||
page = params[:page].to_i == 0 ? nil : params[:page]
|
||||
@bls = @filter.find.recent.paginate :page => page
|
||||
@build_lists = BuildList.where(:id => @bls.pluck("#{BuildList.table_name}.id")).recent
|
||||
@build_lists = @build_lists.includes [:save_to_platform, :save_to_repository, :arch, :user, :project => [:owner]]
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ class Projects::PullRequestsController < Projects::BaseController
|
|||
|
||||
@pull = to_project.pull_requests.new pull_params
|
||||
@pull.issue.user, @pull.issue.project, @pull.from_project = current_user, to_project, @project
|
||||
@pull.from_project_owner_uname = @pull.from_project.owner.uname
|
||||
@pull.from_project_name = @pull.from_project.name
|
||||
|
||||
if @pull.valid? # FIXME more clean/clever logics
|
||||
@pull.save # set pull id
|
||||
|
|
|
@ -10,6 +10,7 @@ class ActivityFeed < ActiveRecord::Base
|
|||
serialize :data
|
||||
|
||||
default_scope order('created_at DESC')
|
||||
scope :outdated, offset(100)
|
||||
|
||||
self.per_page = 10
|
||||
|
||||
|
|
|
@ -84,8 +84,8 @@ class PullRequest < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def path
|
||||
filename = [id, from_project_owner_uname, from_project_name].compact.join('-')
|
||||
File.join(APP_CONFIG['git_path'], 'pull_requests', to_project.owner.uname, to_project.name, filename)
|
||||
last_part = [id, from_project_owner_uname, from_project_name].compact.join('-')
|
||||
File.join(APP_CONFIG['git_path'], "#{new_record? ? 'temp_' : ''}pull_requests", to_project.owner.uname, to_project.name, last_part)
|
||||
end
|
||||
|
||||
def from_branch
|
||||
|
@ -176,10 +176,11 @@ class PullRequest < ActiveRecord::Base
|
|||
|
||||
def clone
|
||||
git = Grit::Git.new(path)
|
||||
unless git.exist?
|
||||
if new_record? || !git.exist?
|
||||
#~ FileUtils.mkdir_p(path)
|
||||
#~ system("git clone --local --no-hardlinks #{to_project.path} #{path}")
|
||||
options = {:bare => false, :shared => false, :branch => to_ref} # shared?
|
||||
`rm -rf #{path}`
|
||||
git.fs_mkdir('..')
|
||||
git.clone(options, to_project.path, path)
|
||||
if to_project != from_project
|
||||
|
|
|
@ -14,3 +14,11 @@ end
|
|||
every 1.day, :at => '3:50 am' do
|
||||
rake "buildlist:clear:outdated", :output => 'log/build_list_clear.log'
|
||||
end
|
||||
|
||||
every 1.day, :at => '3:30 am' do
|
||||
rake "pull_requests:clear", :output => 'log/pull_requests_clear.log'
|
||||
end
|
||||
|
||||
every 1.day, :at => '3:00 am' do
|
||||
rake "activity_feeds:clear", :output => 'log/activity_feeds.log'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
namespace :activity_feeds do
|
||||
desc 'Remove outdated activity feeds'
|
||||
task :clear => :environment do
|
||||
say "Removing outdated Activity Feed"
|
||||
User.all.each do |user|
|
||||
outdated = ActivityFeed.outdated
|
||||
say "User #{user.uname} has #{outdated.count} outdated ActivityFeed."
|
||||
user.activity_feeds.outdated.destroy_all if outdated.count > 0
|
||||
end
|
||||
say "Outdated activity feeds was successfully removed."
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
namespace :pull_requests do
|
||||
|
||||
desc 'Remove temporary git repos for pull requests'
|
||||
task :clear => :environment do
|
||||
Dir.chdir(File.join(APP_CONFIG['git_path'], 'temp_pull_requests')) do
|
||||
say "Removing repos older one day:"
|
||||
say `find -mindepth 3 -maxdepth 3 -type d -mtime +0`
|
||||
`find -mindepth 3 -maxdepth 3 -type d -mtime +0 | xargs rm -rf`
|
||||
say '-----'
|
||||
say "Removing empty dir:"
|
||||
say `find -maxdepth 2 -type d -empty`
|
||||
`find -maxdepth 2 -type d -empty -delete`
|
||||
say 'done!'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue