Merge pull request #126 from warpc/112-sync_projects

Add feature #126: import SRPM package in web
This commit is contained in:
Vladimir Sharshov 2012-01-24 13:39:46 -08:00
commit 11f5305bec
12 changed files with 78 additions and 12 deletions

View File

@ -18,7 +18,7 @@ gem "yui-compressor", "0.9.5" # Higher versions depends on Platform gem which co
gem 'rails3-jquery-autocomplete'
gem 'ancestry', '~> 1.2.4'
gem 'paperclip', "~> 2.3"
gem 'paperclip', "~> 2.5"
gem "will_paginate", "~> 3.0.2"
gem 'meta-tags', '~> 1.2.4', :require => 'meta_tags'
gem "russian"

View File

@ -59,7 +59,7 @@ GEM
capistrano (>= 1.0.0)
capistrano_colors (0.5.5)
chronic (0.6.6)
cocaine (0.2.0)
cocaine (0.2.1)
columnize (0.3.5)
daemons (1.1.4)
delayed_job (2.1.4)
@ -120,7 +120,7 @@ GEM
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.0.5)
paperclip (2.4.5)
paperclip (2.5.0)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
@ -230,7 +230,7 @@ DEPENDENCIES
mysql2 (<= 0.2.9)
omniauth (~> 1.0.1)
omniauth-openid (~> 1.0.1)
paperclip (~> 2.3)
paperclip (~> 2.5)
pg (~> 0.11.0)
rails (= 3.0.11)
rails-xmlrpc (~> 0.3.6)

View File

@ -9,7 +9,7 @@ class Product < ActiveRecord::Base
has_attached_file :tar
validates_attachment_content_type :tar, :content_type => ["application/gnutar", "application/x-compressed", "application/x-gzip", "application/x-bzip2", "application/x-tar"], :message => I18n.t('layout.products.invalid_content_type')
validates_attachment_content_type :tar, :content_type => ["application/gnutar", "application/x-compressed", "application/x-gzip", "application/x-bzip2", "application/x-tar"], :message => I18n.t('layout.invalid_content_type')
validates :name, :presence => true, :uniqueness => {:scope => :platform_id}
scope :recent, order("name ASC")

View File

@ -8,6 +8,7 @@ class Project < ActiveRecord::Base
has_many :build_lists, :dependent => :destroy
has_many :auto_build_lists, :dependent => :destroy
# has_many :project_imports, :dependent => :destroy
has_many :project_to_repositories, :dependent => :destroy
has_many :repositories, :through => :project_to_repositories
@ -18,6 +19,8 @@ class Project < ActiveRecord::Base
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ }
validates :owner, :presence => true
# validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?}
validates_attachment_size :srpm, :less_than => 500.megabytes
validates_attachment_content_type :srpm, :content_type => ['application/octet-stream'], :message => I18n.t('layout.invalid_content_type') # "application/x-rpm", "application/x-redhat-package-manager" ?
#attr_accessible :category_id, :name, :description, :visibility
attr_readonly :name
@ -31,10 +34,13 @@ class Project < ActiveRecord::Base
after_create :attach_to_personal_repository
after_create :create_git_repo
after_destroy :destroy_git_repo
after_save {|p| p.delay.import_srpm if p.srpm?} # should be after create_git_repo
# after_rollback lambda { destroy_git_repo rescue true if new_record? }
has_ancestry
has_attached_file :srpm
include Modules::Models::Owner
def auto_build
@ -137,6 +143,13 @@ class Project < ActiveRecord::Base
@platforms ||= repositories.map(&:platform).uniq
end
def import_srpm(branch_name = 'import')
if srpm?
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm.path} #{path} #{branch_name} >> /dev/null 2>&1")
self.srpm = nil; save # clear srpm
end
end
class << self
def commit_comments(commit, project)
comments = Comment.where(:commentable_id => commit.id, :commentable_type => 'Grit::Commit').order(:created_at)

View File

@ -13,6 +13,9 @@
.group
= f.label :has_issues, t("activerecord.attributes.project.has_issues"), :class => :label
= f.check_box :has_issues
.group
= f.label :srpm, t("activerecord.attributes.project.srpm"), :class => :label
= f.file_field :srpm, :class => 'file_field'
.group.navform.wat-cf
%button.button{:type => "submit"}

View File

@ -8,7 +8,7 @@
.content
%h2.title= t("layout.projects.edit_header")
.inner
= form_for @project, :html => { :class => :form } do |f|
= form_for @project, :html => { :class => :form, :multipart => true } do |f|
= render :partial => "form", :locals => {:f => f}
- content_for :sidebar, render('sidebar')

View File

@ -9,7 +9,7 @@
.content
%h2.title= t("layout.projects.new_header")
.inner
= form_for [get_owner, @project], :html => { :class => :form } do |f|
= form_for [get_owner, @project], :html => { :class => :form, :multipart => true } do |f|
= render :partial => "form", :locals => {:f => f}
-# content_for :sidebar, render('sidebar')

39
bin/import_srpm.sh Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# import_srpm.sh: Import SRPM packages to git repo
# Input data
srpm_path=$1
git_path=$2
git_branch=$3
name=$(rpm -q --qf '[%{Name}]' -p $srpm_path)
version=$(rpm -q --qf '[%{Version}]' -p $srpm_path)
tmp_dir=/tmp/$name-$version-$RANDOM
# Clone destination repo
mkdir -p $tmp_dir
git clone $git_path $tmp_dir
# Switch to import branch
cd $tmp_dir
git branch --track $git_branch origin/$git_branch # Try track remote
git branch $git_branch # Try create local
git checkout $git_branch
# Remove all files except .git
rm -rf $tmp_dir/*
mv $tmp_dir/.git $tmp_dir/git
rm -rf $tmp_dir/.*
mv $tmp_dir/git $tmp_dir/.git
# Unpack srpm
rpm2cpio $srpm_path > srpm.cpio
cpio -idv < srpm.cpio
rm -f srpm.cpio
# Commit and push changes
git add -A .
git commit -m "Automatic import for version $version"
git push origin HEAD
# Cleanup
rm -rf $tmp_dir

View File

@ -46,6 +46,7 @@ en:
notifiers:
edit_header: Notifier setting
processing: working ...
invalid_content_type: incorrect type
downloads:
title: Downloads statistic
@ -201,7 +202,6 @@ en:
new_header: New product
edit_header: Product editing
confirm_delete: Are you sure to delete this product?
invalid_content_type: incorrect type
cron_tab_generator:
show: Show cron tab the generator
@ -605,6 +605,7 @@ en:
created_at: Created
updated_at: Updated
has_issues: Tracker on
srpm: Import code from src.rpm
rpm:
name: Name

View File

@ -46,6 +46,7 @@ ru:
notifiers:
edit_header: Настройки оповещений
processing: Обрабатывается...
invalid_content_type: имеет неверный тип
downloads:
title: Статистика закачек пакетов
@ -201,7 +202,6 @@ ru:
new_header: Новый продукт
edit_header: Редактирование продукта
confirm_delete: Вы уверены, что хотите удалить этот продукт?
invalid_content_type: имеет неверный тип
cron_tab_generator:
show: Показать cron tab генератор
@ -605,6 +605,7 @@ ru:
created_at: Создан
updated_at: Обновлен
has_issues: Включить трэкер
srpm: Импортировать код из src.rpm
rpm:
name: Название
@ -679,14 +680,12 @@ ru:
status: Статус
version: Версия
build_list: Сборочный лист
download:
name: Название
version: Версия
distro: Дистрибутив
platform: Архитектура
counter: Закачки
notifications:
subjects:
new_comment_notification: Новый комментарий к Вашей задаче

View File

@ -0,0 +1,11 @@
class AddSrpmColumnsToProjects < ActiveRecord::Migration
def self.up
change_table :projects do |t|
t.has_attached_file :srpm
end
end
def self.down
drop_attached_file :projects, :srpm
end
end

View File

@ -91,7 +91,7 @@ describe CanCan do
@ability.should be_able_to(:read, @admin)
end
it "shoud be able to read index AutoBuildList" do
pending "shoud be able to read index AutoBuildList" do
@ability.should be_able_to(:index, AutoBuildList)
end