polisher 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +8 -0
- data/LICENSE +661 -0
- data/README.rdoc +25 -0
- data/Rakefile +92 -0
- data/TODO +6 -0
- data/bin/server +3 -0
- data/config/database.yml +8 -43
- data/config/polisher.yml +15 -5
- data/config.ru +25 -0
- data/db/connection.rb +49 -0
- data/db/migrations/001_create_sources.rb +27 -0
- data/db/migrations/002_create_managed_gems.rb +24 -0
- data/db/migrations/003_create_events.rb +27 -0
- data/db/models/event.rb +61 -0
- data/db/models/managed_gem.rb +111 -0
- data/db/models/source.rb +35 -0
- data/lib/common.rb +39 -0
- data/lib/event_handlers.rb +100 -0
- data/lib/sinatra/url_for.rb +40 -0
- data/polisher.rb +120 -0
- data/public/javascripts/polisher.js +15 -0
- data/public/stylesheets/style.css +18 -3
- data/spec/event_handlers_spec.rb +164 -0
- data/spec/models_spec.rb +193 -0
- data/spec/polisher_spec.rb +133 -0
- data/spec/spec_helper.rb +44 -0
- data/views/gems/index.haml +106 -0
- data/views/layout.haml +24 -0
- data/views/sources/index.haml +41 -0
- metadata +36 -93
- data/README +0 -243
- data/app/controllers/application_controller.rb +0 -12
- data/app/controllers/callback_controller.rb +0 -47
- data/app/controllers/manage_controller.rb +0 -112
- data/app/helpers/application_helper.rb +0 -3
- data/app/models/artifact.rb +0 -21
- data/app/models/event_handler.rb +0 -61
- data/app/models/gem_search_criteria.rb +0 -24
- data/app/models/gem_source.rb +0 -43
- data/app/models/managed_gem.rb +0 -47
- data/app/views/callback/gem_updated.rhtml +0 -0
- data/app/views/layouts/_header.rhtml +0 -8
- data/app/views/layouts/index.rhtml +0 -27
- data/app/views/manage/create_event_handler.rhtml +0 -15
- data/app/views/manage/create_gem.rhtml +0 -15
- data/app/views/manage/create_gem_source.rhtml +0 -15
- data/app/views/manage/delete_event_handler.rhtml +0 -15
- data/app/views/manage/delete_gem.rhtml +0 -15
- data/app/views/manage/delete_gem_source.rhtml +0 -15
- data/app/views/manage/list.rhtml +0 -66
- data/app/views/manage/new_event_handler.rhtml +0 -38
- data/app/views/manage/new_gem.rhtml +0 -21
- data/app/views/manage/new_gem_search_criteria.rhtml +0 -3
- data/app/views/manage/new_gem_source.rhtml +0 -10
- data/config/boot.rb +0 -110
- data/config/environment.rb +0 -44
- data/config/environments/development.rb +0 -17
- data/config/environments/production.rb +0 -28
- data/config/environments/test.rb +0 -28
- data/config/initializers/backtrace_silencers.rb +0 -7
- data/config/initializers/inflections.rb +0 -10
- data/config/initializers/mime_types.rb +0 -5
- data/config/initializers/new_rails_defaults.rb +0 -21
- data/config/initializers/session_store.rb +0 -15
- data/config/locales/en.yml +0 -5
- data/config/routes.rb +0 -44
- data/db/migrate/001_create_gem_sources.rb +0 -34
- data/db/migrate/002_create_managed_gems.rb +0 -32
- data/db/migrate/003_create_gem_search_criterias.rb +0 -33
- data/db/migrate/004_create_event_handlers.rb +0 -32
- data/db/migrate/005_create_artifacts.rb +0 -32
- data/db/schema.rb +0 -42
- data/db/seeds.rb +0 -7
- data/lib/email_adapter.rb +0 -46
- data/lib/gem2rpm.rb +0 -189
- data/lib/gem_api_adapter.rb +0 -87
- data/lib/rpm_adapter.rb +0 -39
- data/public/404.html +0 -30
- data/public/422.html +0 -30
- data/public/500.html +0 -30
- data/public/dispatch.cgi +0 -10
- data/public/dispatch.fcgi +0 -24
- data/public/dispatch.rb +0 -29
- data/public/favicon.ico +0 -0
- data/public/images/rails.png +0 -0
- data/public/javascripts/application.js +0 -2
- data/public/javascripts/controls.js +0 -963
- data/public/javascripts/dragdrop.js +0 -973
- data/public/javascripts/effects.js +0 -1128
- data/public/javascripts/prototype.js +0 -4320
- data/public/robots.txt +0 -5
- data/script/about +0 -4
- data/script/console +0 -3
- data/script/dbconsole +0 -3
- data/script/destroy +0 -3
- data/script/generate +0 -3
- data/script/performance/benchmarker +0 -3
- data/script/performance/profiler +0 -3
- data/script/plugin +0 -3
- data/script/runner +0 -3
- data/script/server +0 -3
- data/tmp/gems/README +0 -1
- data/tmp/rpms/README +0 -1
@@ -0,0 +1,100 @@
|
|
1
|
+
# Gem event handler callbacks,
|
2
|
+
# A method should exist here for every process supported by the system.
|
3
|
+
# The method should share the same name w/ the corresponding process
|
4
|
+
#
|
5
|
+
# Copyright (C) 2010 Red Hat, Inc.
|
6
|
+
# Written by Mohammed Morsi <mmorsi@redhat.com>
|
7
|
+
#
|
8
|
+
# This program is free software, you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU Affero General Public License
|
10
|
+
# as published by the Free Software Foundation, either version 3
|
11
|
+
# of the License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the the GNU Affero
|
14
|
+
# General Public License, along with Polisher. If not, see
|
15
|
+
# <http://www.gnu.org/licenses/>
|
16
|
+
|
17
|
+
require 'gem2rpm'
|
18
|
+
require 'net/smtp'
|
19
|
+
|
20
|
+
# Convert gem into another package format.
|
21
|
+
# Right now uses gem2rpm to create rpm spec, taking optional template file name
|
22
|
+
# TODO extend/modify to support any other package format
|
23
|
+
def create_package(gem, template_file = '')
|
24
|
+
# d/l gem into artifacts/gems dir, link it into the artifacts/SOURCES dir
|
25
|
+
gem_file_path = gem.download_to :dir => ARTIFACTS_DIR + "/gems"
|
26
|
+
gem_file = gem_file_path.split('/').last
|
27
|
+
File.symlink gem_file_path, ARTIFACTS_DIR + "/SOURCES/" + gem_file
|
28
|
+
|
29
|
+
# spec we are writing
|
30
|
+
spec_file = ARTIFACTS_DIR + "/SPECS/rubygem-#{gem.name}.spec"
|
31
|
+
sfh = File.open(spec_file, "wb")
|
32
|
+
|
33
|
+
# coversion template to use, if not specified use gem2rpm default
|
34
|
+
template = Gem2Rpm::TEMPLATE
|
35
|
+
File.open(ARTIFACTS_DIR + "/templates/#{template_file}", "rb") { |file|
|
36
|
+
template = file.read
|
37
|
+
} unless template_file == '' || template_file.nil?
|
38
|
+
|
39
|
+
# create rpm spec w/ gem2rpm
|
40
|
+
Gem2Rpm::convert gem_file_path, template, sfh
|
41
|
+
sfh.close
|
42
|
+
|
43
|
+
# run rpmbuild on spec
|
44
|
+
system("rpmbuild --define '_topdir #{ARTIFACTS_DIR}' -ba #{spec_file}")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Update specified repository w/ latest gem artifact.
|
48
|
+
# Right now updates specified yum repo w/ newly created gem rpm
|
49
|
+
# TODO extend/modify to support other repository formats
|
50
|
+
def update_repo(gem, repository)
|
51
|
+
# create the repository dir if it doesn't exist
|
52
|
+
repo_dir = ARTIFACTS_DIR + "/repos/#{repository}"
|
53
|
+
Dir.mkdir repo_dir unless File.directory? repo_dir
|
54
|
+
|
55
|
+
# get the latest built rpm that matches gem name
|
56
|
+
# FIXME need to incorporate version
|
57
|
+
gem_file = Dir[ARTIFACTS_DIR + "/RPMS/*/rubygem-#{gem.name}-*.rpm"].
|
58
|
+
collect { |fn| File.new(fn) }.
|
59
|
+
sort { |f1,f2| file1.mtime <=> file2.mtime }.last
|
60
|
+
|
61
|
+
# grab the architecture from the directory the file resides in
|
62
|
+
arch = gem_file.path.split('.')
|
63
|
+
arch = arch[arch.size-2]
|
64
|
+
|
65
|
+
# copy gem into repo/arch dir, creating it if it doesn't exist
|
66
|
+
arch_dir = repo_dir + "/#{arch}"
|
67
|
+
Dir.mkdir arch_dir unless File.directory? arch_dir
|
68
|
+
File.open(arch_dir + "/rubygem-#{gem.name}.rpm", 'wb') { |ofile| ofile.write gem_file.read }
|
69
|
+
|
70
|
+
# run createrepo to finalize the repository
|
71
|
+
system("createrepo #{repo_dir}")
|
72
|
+
end
|
73
|
+
|
74
|
+
# run gem's test suite against specified repository
|
75
|
+
def run_test_suite(gem, repository)
|
76
|
+
end
|
77
|
+
|
78
|
+
# notify a list of recipients of gem update
|
79
|
+
def notify_subscribers(gem, recipients = [])
|
80
|
+
from = POLISHER_CONFIG['email_from']
|
81
|
+
subject = POLISHER_CONFIG['email_subject']
|
82
|
+
body = POLISHER_CONFIG['email_body']
|
83
|
+
server = POLISHER_CONFIG['email_server']
|
84
|
+
|
85
|
+
# substitute variables into subject / body where appropriate
|
86
|
+
subject.gsub('#{gem_name}', gem.name)
|
87
|
+
body.gsub('#{gem_name}', gem.name)
|
88
|
+
|
89
|
+
msg = <<END_OF_MESSAGE
|
90
|
+
From: #{from}
|
91
|
+
To: #{recipients.join(',')}
|
92
|
+
Subject: #{subject}
|
93
|
+
|
94
|
+
#{body}
|
95
|
+
END_OF_MESSAGE
|
96
|
+
|
97
|
+
Net::SMTP.start(server) do |smtp|
|
98
|
+
smtp.send_message msg, from, to
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# copied from http://git.fedoraproject.org/git/?p=deltacloud/core.git;a=blob;f=server/libexec/lib/sinatra/url_for.rb
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module UrlForHelper
|
5
|
+
# Construct a link to +url_fragment+, which should be given relative to
|
6
|
+
# the base of this Sinatra app. The mode should be either
|
7
|
+
# <code>:path_only</code>, which will generate an absolute path within
|
8
|
+
# the current domain (the default), or <code>:full</code>, which will
|
9
|
+
# include the site name and port number. (The latter is typically
|
10
|
+
# necessary for links in RSS feeds.) Example usage:
|
11
|
+
#
|
12
|
+
# url_for "/" # Returns "/myapp/"
|
13
|
+
# url_for "/foo" # Returns "/myapp/foo"
|
14
|
+
# url_for "/foo", :full # Returns "http://example.com/myapp/foo"
|
15
|
+
#--
|
16
|
+
# See README.rdoc for a list of some of the people who helped me clean
|
17
|
+
# up earlier versions of this code.
|
18
|
+
def url_for url_fragment, mode=:path_only
|
19
|
+
case mode
|
20
|
+
when :path_only
|
21
|
+
base = request.script_name
|
22
|
+
when :full
|
23
|
+
scheme = request.scheme
|
24
|
+
if (scheme == 'http' && request.port == 80 ||
|
25
|
+
scheme == 'https' && request.port == 443)
|
26
|
+
port = ""
|
27
|
+
else
|
28
|
+
port = ":#{request.port}"
|
29
|
+
end
|
30
|
+
request_host = HOSTNAME ? HOSTNAME : request.host
|
31
|
+
base = "#{scheme}://#{request_host}#{port}#{request.script_name}"
|
32
|
+
else
|
33
|
+
raise TypeError, "Unknown url_for mode #{mode}"
|
34
|
+
end
|
35
|
+
"#{base}#{url_fragment}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
helpers UrlForHelper
|
40
|
+
end
|
data/polisher.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# ruby gem polisher REST interface
|
2
|
+
#
|
3
|
+
# Copyright (C) 2010 Red Hat, Inc.
|
4
|
+
# Written by Mohammed Morsi <mmorsi@redhat.com>
|
5
|
+
#
|
6
|
+
# This program is free software, you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License
|
8
|
+
# as published by the Free Software Foundation, either version 3
|
9
|
+
# of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# You should have received a copy of the the GNU Affero
|
12
|
+
# General Public License, along with Polisher. If not, see
|
13
|
+
# <http://www.gnu.org/licenses/>
|
14
|
+
|
15
|
+
# ruby gems
|
16
|
+
require 'rubygems'
|
17
|
+
require 'haml'
|
18
|
+
require 'sinatra'
|
19
|
+
require 'fileutils'
|
20
|
+
|
21
|
+
# lib/ modules
|
22
|
+
require 'common'
|
23
|
+
require 'event_handlers'
|
24
|
+
require 'sinatra/url_for'
|
25
|
+
|
26
|
+
# db modules
|
27
|
+
require 'db/connection'
|
28
|
+
|
29
|
+
##################################################################### Config
|
30
|
+
|
31
|
+
# dir which generated artifacts reside
|
32
|
+
ARTIFACTS_DIR = Sinatra::Application.artifacts_dir
|
33
|
+
|
34
|
+
create_missing_polisher_dirs(:artifacts_dir => ARTIFACTS_DIR, :db_data_dir => Sinatra::Application.db_data_dir, :log_dir => Sinatra::Application.log_dir)
|
35
|
+
|
36
|
+
# startup logger
|
37
|
+
LOGGER = Logger.new(Sinatra::Application.log_dir + '/polisher.log')
|
38
|
+
|
39
|
+
# connect to db
|
40
|
+
module Polisher::DB
|
41
|
+
connect load_config(Sinatra::Application.db_config, Sinatra::Application.environment), LOGGER
|
42
|
+
end
|
43
|
+
|
44
|
+
# get polisher config
|
45
|
+
POLISHER_CONFIG = YAML::load(File.open(Sinatra::Application.polisher_config))[Sinatra::Application.environment.to_s]
|
46
|
+
|
47
|
+
##################################################################### Gems
|
48
|
+
|
49
|
+
# Redirect to /gems
|
50
|
+
get '/' do redirect '/gems'; end
|
51
|
+
|
52
|
+
get '/gems' do
|
53
|
+
@sources = Source.find :all
|
54
|
+
@gems = ManagedGem.find :all
|
55
|
+
@processes = Event.processes
|
56
|
+
@version_qualifiers = Event::VERSION_QUALIFIERS
|
57
|
+
|
58
|
+
haml :"gems/index"
|
59
|
+
end
|
60
|
+
|
61
|
+
post '/gems/create' do
|
62
|
+
@gem = ManagedGem.new :name => params[:name], :source_id => params[:source_id]
|
63
|
+
@gem.save!
|
64
|
+
@gem.subscribe
|
65
|
+
redirect '/gems'
|
66
|
+
end
|
67
|
+
|
68
|
+
delete '/gems/destroy/:id' do
|
69
|
+
ManagedGem.delete params[:id]
|
70
|
+
redirect '/gems'
|
71
|
+
end
|
72
|
+
|
73
|
+
post '/gems/updated' do
|
74
|
+
name = params[:name]
|
75
|
+
version = params[:version]
|
76
|
+
source_uri = ManagedGem.uri_to_source_uri(params[:gem_uri])
|
77
|
+
|
78
|
+
source = Source.find(:first, :conditions => ["uri = ?", source_uri])
|
79
|
+
gem = source.gems.all.find { |gem| gem.name == name }
|
80
|
+
events = gem.events.all.find_all { |event| event.applies_to_version?(version) }
|
81
|
+
events.each { |event| event.run }
|
82
|
+
|
83
|
+
redirect '/gems'
|
84
|
+
end
|
85
|
+
|
86
|
+
##################################################################### Sources
|
87
|
+
|
88
|
+
get '/sources' do
|
89
|
+
@sources = Source.find :all
|
90
|
+
haml :"sources/index"
|
91
|
+
end
|
92
|
+
|
93
|
+
post '/sources/create' do
|
94
|
+
@source = Source.new :name => params[:name], :uri => params[:uri]
|
95
|
+
@source.save!
|
96
|
+
redirect '/sources'
|
97
|
+
end
|
98
|
+
|
99
|
+
delete '/sources/destroy/:id' do
|
100
|
+
Source.delete params[:id]
|
101
|
+
redirect '/sources'
|
102
|
+
end
|
103
|
+
|
104
|
+
##################################################################### Events
|
105
|
+
|
106
|
+
post '/events/create' do
|
107
|
+
version = (params[:gem_version] != '*' ? params[:gem_version] : '')
|
108
|
+
@event = Event.new :managed_gem_id => ManagedGem.find(params[:managed_gem_id]),
|
109
|
+
:process => params[:process],
|
110
|
+
:gem_version => version,
|
111
|
+
:version_qualifier => params[:version_qualifier],
|
112
|
+
:process_options => params[:process_options]
|
113
|
+
@event.save!
|
114
|
+
redirect '/gems'
|
115
|
+
end
|
116
|
+
|
117
|
+
delete '/events/destroy/:id' do
|
118
|
+
Event.delete params[:id]
|
119
|
+
redirect '/gems'
|
120
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// polisher javascript methods
|
2
|
+
|
3
|
+
// send a http delete request
|
4
|
+
function delete_request(uri, callback){
|
5
|
+
$.ajax({
|
6
|
+
url: uri,
|
7
|
+
type: 'DELETE',
|
8
|
+
success: callback
|
9
|
+
});
|
10
|
+
}
|
11
|
+
|
12
|
+
// reload page
|
13
|
+
function reload(){
|
14
|
+
location.reload(true);
|
15
|
+
}
|
@@ -6,9 +6,11 @@ a{
|
|
6
6
|
|
7
7
|
form{
|
8
8
|
padding-top: 5px;
|
9
|
+
padding-left: 15px;
|
9
10
|
}
|
10
11
|
|
11
|
-
form
|
12
|
+
/* set fixed width of first column in form tables */
|
13
|
+
form tr > td:first-child{
|
12
14
|
width: 150px;;
|
13
15
|
}
|
14
16
|
|
@@ -44,19 +46,28 @@ form td{
|
|
44
46
|
padding-left: 10px;
|
45
47
|
}
|
46
48
|
|
47
|
-
#main h4,
|
48
49
|
#main h5,
|
49
50
|
#main h6{
|
50
51
|
display: inline;
|
51
52
|
}
|
52
53
|
|
54
|
+
#main h4{
|
55
|
+
margin-top: 25px;
|
56
|
+
margin-bottom: 0;
|
57
|
+
}
|
58
|
+
|
53
59
|
#main h6{
|
54
60
|
padding-left: 15px;
|
55
61
|
}
|
56
62
|
|
63
|
+
#main ul{
|
64
|
+
margin-top: 3px;
|
65
|
+
margin-bottom: 3px;
|
66
|
+
padding-left: 20px;
|
67
|
+
}
|
68
|
+
|
57
69
|
#main ul li{
|
58
70
|
list-style: none;
|
59
|
-
padding-top: 15px;
|
60
71
|
}
|
61
72
|
|
62
73
|
#main ul li:before {
|
@@ -66,3 +77,7 @@ form td{
|
|
66
77
|
#main ul li ul li{
|
67
78
|
padding-top: 5px;
|
68
79
|
}
|
80
|
+
|
81
|
+
#main input#gem_version {
|
82
|
+
width: 125px;
|
83
|
+
}
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# ruby gem polisher event handlers spec
|
2
|
+
#
|
3
|
+
# Copyright (C) 2010 Red Hat, Inc.
|
4
|
+
# Written by Mohammed Morsi <mmorsi@redhat.com>
|
5
|
+
#
|
6
|
+
# This program is free software, you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License
|
8
|
+
# as published by the Free Software Foundation, either version 3
|
9
|
+
# of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# You should have received a copy of the the GNU Affero
|
12
|
+
# General Public License, along with Motel. If not, see
|
13
|
+
# <http://www.gnu.org/licenses/>
|
14
|
+
|
15
|
+
require 'fileutils'
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
18
|
+
|
19
|
+
BUILD_VERSION='fc11'
|
20
|
+
|
21
|
+
describe "Polisher::EventHandlers" do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
FileUtils.rm_rf(ARTIFACTS_DIR)
|
25
|
+
FileUtils.mkdir_p(ARTIFACTS_DIR + '/gems')
|
26
|
+
FileUtils.mkdir_p(ARTIFACTS_DIR + '/repos')
|
27
|
+
FileUtils.mkdir_p(ARTIFACTS_DIR + '/SOURCES')
|
28
|
+
FileUtils.mkdir_p(ARTIFACTS_DIR + '/SPECS')
|
29
|
+
FileUtils.mkdir_p(ARTIFACTS_DIR + '/templates')
|
30
|
+
|
31
|
+
unless defined? @gem
|
32
|
+
@gem = ManagedGem.create :name => 'polisher', :source_id => 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should correctly create package" do
|
37
|
+
create_package(@gem)
|
38
|
+
File.exists?(ARTIFACTS_DIR + '/gems/polisher-0.1.gem').should == true
|
39
|
+
File.exists?(ARTIFACTS_DIR + '/SOURCES/polisher-0.1.gem').should == true
|
40
|
+
File.exists?(ARTIFACTS_DIR + '/SPECS/rubygem-polisher.spec').should == true
|
41
|
+
File.exists?(ARTIFACTS_DIR + "/SRPMS/rubygem-polisher-0.1-1.#{BUILD_VERSION}.src.rpm").should == true
|
42
|
+
File.exists?(ARTIFACTS_DIR + "/RPMS/noarch/rubygem-polisher-0.1-1.#{BUILD_VERSION}.noarch.rpm").should == true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should correctly create package using template" do
|
46
|
+
File.write(ARTIFACTS_DIR + '/templates/polisher.spec.tpl', POLISHER_TEST_TEMPLATE)
|
47
|
+
create_package(@gem, '/polisher.spec.tpl')
|
48
|
+
File.exists?(ARTIFACTS_DIR + '/SPECS/rubygem-polisher.spec').should == true
|
49
|
+
File.read_all(ARTIFACTS_DIR + '/SPECS/rubygem-polisher.spec').should =~ /.*by polisher.*/
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should correctly update repository" do
|
53
|
+
create_package(@gem)
|
54
|
+
update_repo(@gem, 'fedora-ruby')
|
55
|
+
File.directory?(ARTIFACTS_DIR + '/repos/fedora-ruby/noarch').should == true
|
56
|
+
File.directory?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata').should == true
|
57
|
+
File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/noarch/rubygem-polisher.rpm').should == true
|
58
|
+
File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/repomd.xml').should == true
|
59
|
+
File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/primary.xml.gz').should == true
|
60
|
+
File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/other.xml.gz').should == true
|
61
|
+
File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/filelists.xml.gz').should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should correctly notify email recipients" do
|
65
|
+
# TODO test notify subscribers
|
66
|
+
#notify_subscribers(@gem, [...])
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
POLISHER_TEST_TEMPLATE =
|
72
|
+
%q{# Generated from <%= File::basename(format.gem_path) %> by polisher -*- rpm-spec -*-
|
73
|
+
%define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
|
74
|
+
%define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
|
75
|
+
%define gemname <%= spec.name %>
|
76
|
+
%define geminstdir %{gemdir}/gems/%{gemname}-%{version}
|
77
|
+
|
78
|
+
Summary: <%= spec.summary.gsub(/\.$/, "") %>
|
79
|
+
Name: rubygem-%{gemname}
|
80
|
+
Version: <%= spec.version %>
|
81
|
+
Release: 1%{?dist}
|
82
|
+
Group: Development/Languages
|
83
|
+
License: GPLv2+ or Ruby
|
84
|
+
URL: <%= spec.homepage %>
|
85
|
+
Source0: <%= download_path %>%{gemname}-%{version}.gem
|
86
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
87
|
+
Requires: rubygems
|
88
|
+
<% for d in spec.dependencies %>
|
89
|
+
<% for req in d.version_requirements.to_rpm %>
|
90
|
+
Requires: rubygem(<%= d.name %>) <%= req %>
|
91
|
+
<% end %>
|
92
|
+
<% end %>
|
93
|
+
BuildRequires: rubygems
|
94
|
+
<% if spec.extensions.empty? %>
|
95
|
+
BuildArch: noarch
|
96
|
+
<% end %>
|
97
|
+
Provides: rubygem(%{gemname}) = %{version}
|
98
|
+
|
99
|
+
%description
|
100
|
+
<%= spec.description.to_s.chomp.word_wrap(78) + "\n" %>
|
101
|
+
|
102
|
+
<% if nongem %>
|
103
|
+
%package -n ruby-%{gemname}
|
104
|
+
Summary: <%= spec.summary.gsub(/\.$/, "") %>
|
105
|
+
Group: Development/Languages
|
106
|
+
Requires: rubygem(%{gemname}) = %{version}
|
107
|
+
<% spec.files.select{ |f| spec.require_paths.include?(File::dirname(f)) }.reject { |f| f =~ /\.rb$/ }.collect { |f| File::basename(f) }.each do |p| %>
|
108
|
+
Provides: ruby(<%= p %>) = %{version}
|
109
|
+
<% end %>
|
110
|
+
%description -n ruby-%{gemname}
|
111
|
+
<%= spec.description.to_s.chomp.word_wrap(78) + "\n" %>
|
112
|
+
<% end # if nongem %>
|
113
|
+
|
114
|
+
%prep
|
115
|
+
|
116
|
+
%build
|
117
|
+
|
118
|
+
%install
|
119
|
+
rm -rf %{buildroot}
|
120
|
+
mkdir -p %{buildroot}%{gemdir}
|
121
|
+
<% rdoc_opt = spec.has_rdoc ? "--rdoc " : "" %>
|
122
|
+
gem install --local --install-dir %{buildroot}%{gemdir} \
|
123
|
+
--force <%= rdoc_opt %>%{SOURCE0}
|
124
|
+
<% unless spec.executables.empty? %>
|
125
|
+
mkdir -p %{buildroot}/%{_bindir}
|
126
|
+
mv %{buildroot}%{gemdir}/bin/* %{buildroot}/%{_bindir}
|
127
|
+
rmdir %{buildroot}%{gemdir}/bin
|
128
|
+
find %{buildroot}%{geminstdir}/bin -type f | xargs chmod a+x
|
129
|
+
<% end %>
|
130
|
+
<% if nongem %>
|
131
|
+
mkdir -p %{buildroot}%{ruby_sitelib}
|
132
|
+
<% spec.files.select{ |f| spec.require_paths.include?(File::dirname(f)) }.each do |p| %>
|
133
|
+
ln -s %{gemdir}/gems/%{gemname}-%{version}/<%= p %> %{buildroot}%{ruby_sitelib}
|
134
|
+
<% end %>
|
135
|
+
<% end # if nongem %>
|
136
|
+
|
137
|
+
%clean
|
138
|
+
rm -rf %{buildroot}
|
139
|
+
|
140
|
+
%files
|
141
|
+
%defattr(-, root, root, -)
|
142
|
+
<% for f in spec.executables %>
|
143
|
+
%{_bindir}/<%= f %>
|
144
|
+
<% end %>
|
145
|
+
%{gemdir}/gems/%{gemname}-%{version}/
|
146
|
+
<% if spec.has_rdoc %>
|
147
|
+
%doc %{gemdir}/doc/%{gemname}-%{version}
|
148
|
+
<% end %>
|
149
|
+
<% for f in spec.extra_rdoc_files %>
|
150
|
+
%doc %{geminstdir}/<%= f %>
|
151
|
+
<% end %>
|
152
|
+
%{gemdir}/cache/%{gemname}-%{version}.gem
|
153
|
+
%{gemdir}/specifications/%{gemname}-%{version}.gemspec
|
154
|
+
|
155
|
+
<% if nongem %>
|
156
|
+
%files -n ruby-%{gemname}
|
157
|
+
%defattr(-, root, root, -)
|
158
|
+
%{ruby_sitelib}/*
|
159
|
+
<% end # if nongem %>
|
160
|
+
|
161
|
+
%changelog
|
162
|
+
* <%= Time.now.strftime("%a %b %d %Y") %> <%= packager %> - <%= spec.version %>-1
|
163
|
+
- Initial package
|
164
|
+
}
|
data/spec/models_spec.rb
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
# ruby gem polisher models spec
|
2
|
+
#
|
3
|
+
# Copyright (C) 2010 Red Hat, Inc.
|
4
|
+
# Written by Mohammed Morsi <mmorsi@redhat.com>
|
5
|
+
#
|
6
|
+
# This program is free software, you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License
|
8
|
+
# as published by the Free Software Foundation, either version 3
|
9
|
+
# of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# You should have received a copy of the the GNU Affero
|
12
|
+
# General Public License, along with Polisher. If not, see
|
13
|
+
# <http://www.gnu.org/licenses/>
|
14
|
+
|
15
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
16
|
+
|
17
|
+
|
18
|
+
describe "Polisher::Source" do
|
19
|
+
it "should not be valid if name or uri is missing" do
|
20
|
+
src = Source.new :name => 'foo', :uri => 'bar'
|
21
|
+
src.valid?.should be(true)
|
22
|
+
|
23
|
+
src.name = nil
|
24
|
+
src.valid?.should be(false)
|
25
|
+
src.name = 'foo'
|
26
|
+
|
27
|
+
src.uri = nil
|
28
|
+
src.valid?.should be(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should clean uri properly" do
|
32
|
+
src = Source.new :uri => 'http://example.com/'
|
33
|
+
src.clean_uri!
|
34
|
+
src.uri.should == 'http://example.com'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
describe "Polisher::ManagedGem" do
|
41
|
+
it "should not be valid if name or source is missing" do
|
42
|
+
gem = ManagedGem.new :name => 'foo', :source_id => 1
|
43
|
+
gem.valid?.should be(true)
|
44
|
+
|
45
|
+
gem.name = nil
|
46
|
+
gem.valid?.should be(false)
|
47
|
+
gem.name = 'foo'
|
48
|
+
|
49
|
+
gem.source_id = nil
|
50
|
+
gem.valid?.should be(false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not be valid if name is not unique within source scope" do
|
54
|
+
gem1 = ManagedGem.create :name => 'foo', :source_id => 1
|
55
|
+
gem2 = ManagedGem.new :name => 'foo', :source_id => 1
|
56
|
+
gem2.valid?.should be(false)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should generate correct source uri from gem uri" do
|
60
|
+
ManagedGem.uri_to_source_uri('http://rubygems.org/downloads/polisher-0.1.gem').
|
61
|
+
should == 'http://rubygems.org'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should successfully subscribe/unsubscribe to updates" do
|
65
|
+
gem = ManagedGem.new :name => "polisher", :source_id => 1
|
66
|
+
gem.subscribe :callback_url => "http://projects.morsi.org/polisher/demo/gems/updated/1"
|
67
|
+
gem.subscribed?.should == true
|
68
|
+
gem.unsubscribe :callback_url => "http://projects.morsi.org/polisher/demo/gems/updated/1"
|
69
|
+
gem.subscribed?.should == false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should successfully get remote gem info" do
|
73
|
+
gem = ManagedGem.new :name => "polisher", :source_id => 1
|
74
|
+
info = gem.get_info
|
75
|
+
info["name"].should == "polisher"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should successfully download gem" do
|
79
|
+
FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
|
80
|
+
FileUtils.mkdir_p(ARTIFACTS_DIR)
|
81
|
+
|
82
|
+
gem = ManagedGem.new :name => "polisher", :source_id => 1
|
83
|
+
path = gem.download_to(:dir => ARTIFACTS_DIR, :version => 0.1)
|
84
|
+
File.size?(ARTIFACTS_DIR + '/polisher-0.1.gem').should_not be_nil
|
85
|
+
FileUtils.rm(ARTIFACTS_DIR + '/polisher-0.1.gem')
|
86
|
+
path.should == ARTIFACTS_DIR + '/polisher-0.1.gem'
|
87
|
+
|
88
|
+
|
89
|
+
gem.download_to(:path => ARTIFACTS_DIR + '/my.gem', :version => 0.1)
|
90
|
+
File.size?(ARTIFACTS_DIR + '/my.gem').should_not be_nil
|
91
|
+
|
92
|
+
gem.download_to(:dir => ARTIFACTS_DIR)
|
93
|
+
File.size?(ARTIFACTS_DIR + '/polisher-0.1.gem').should_not be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "Polisher::Event" do
|
99
|
+
|
100
|
+
it "should not be valid if managed_gem or process is missing" do
|
101
|
+
gem = ManagedGem.create :name => 'valid-event-test-gem1', :source_id => 1
|
102
|
+
|
103
|
+
event = Event.new :managed_gem_id => gem.id, :process => 'create_repo'
|
104
|
+
event.valid?.should be(true)
|
105
|
+
|
106
|
+
event.managed_gem = nil
|
107
|
+
event.valid?.should be(false)
|
108
|
+
event.managed_gem = gem
|
109
|
+
|
110
|
+
event.process = nil
|
111
|
+
event.valid?.should be(false)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not be valid with invalid version qualifier" do
|
115
|
+
gem = ManagedGem.create :name => 'valid-event-test-gem2', :source_id => 1
|
116
|
+
|
117
|
+
event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :version_qualifier => ">", :gem_version => 5
|
118
|
+
event.valid?.should be(true)
|
119
|
+
|
120
|
+
event.version_qualifier = '=='
|
121
|
+
event.valid?.should be(false)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not be valid if version/qualifier are not both present or nil" do
|
125
|
+
gem = ManagedGem.create :name => 'valid-event-test-gem3', :source_id => 1
|
126
|
+
|
127
|
+
event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :version_qualifier => ">"
|
128
|
+
event.valid?.should be(false)
|
129
|
+
|
130
|
+
event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :gem_version => 5
|
131
|
+
event.valid?.should be(false)
|
132
|
+
|
133
|
+
event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :gem_version => 5, :version_qualifier => '<='
|
134
|
+
event.valid?.should be(true)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should correctly resolve version qualifiers" do
|
138
|
+
event = Event.new :version_qualifier => nil
|
139
|
+
event.applies_to_version?('1.1').should be(true)
|
140
|
+
|
141
|
+
event = Event.new :version_qualifier => "=", :gem_version => "5.3"
|
142
|
+
event.applies_to_version?('1.2').should be(false)
|
143
|
+
event.applies_to_version?('5.3').should be(true)
|
144
|
+
event.applies_to_version?('7.9').should be(false)
|
145
|
+
|
146
|
+
event = Event.new :version_qualifier => ">", :gem_version => "1.9"
|
147
|
+
event.applies_to_version?('1.8').should be(false)
|
148
|
+
event.applies_to_version?('1.9').should be(false)
|
149
|
+
event.applies_to_version?('2.0').should be(true)
|
150
|
+
|
151
|
+
event = Event.new :version_qualifier => "<", :gem_version => "0.6"
|
152
|
+
event.applies_to_version?('0.5').should be(true)
|
153
|
+
event.applies_to_version?('0.6').should be(false)
|
154
|
+
event.applies_to_version?('0.7').should be(false)
|
155
|
+
|
156
|
+
event = Event.new :version_qualifier => ">=", :gem_version => "1.9"
|
157
|
+
event.applies_to_version?('1.8').should be(false)
|
158
|
+
event.applies_to_version?('1.9').should be(true)
|
159
|
+
event.applies_to_version?('2.0').should be(true)
|
160
|
+
|
161
|
+
event = Event.new :version_qualifier => "<=", :gem_version => "0.6"
|
162
|
+
event.applies_to_version?('0.5').should be(true)
|
163
|
+
event.applies_to_version?('0.6').should be(true)
|
164
|
+
event.applies_to_version?('0.7').should be(false)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should successfully run event process" do
|
168
|
+
gem = ManagedGem.new :name => "foobar"
|
169
|
+
event = Event.new :managed_gem => gem, :process => "test_event_run_method", :process_options => "a;b;c"
|
170
|
+
event.run
|
171
|
+
|
172
|
+
$test_event_run_hash[:gem].should_not be_nil
|
173
|
+
$test_event_run_hash[:first].should_not be_nil
|
174
|
+
$test_event_run_hash[:second].should_not be_nil
|
175
|
+
$test_event_run_hash[:third].should_not be_nil
|
176
|
+
|
177
|
+
$test_event_run_hash[:gem].name.should == "foobar"
|
178
|
+
$test_event_run_hash[:first].should == "a"
|
179
|
+
$test_event_run_hash[:second].should == "b"
|
180
|
+
$test_event_run_hash[:third].should == "c"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# prolly should fixure out a better way todo this
|
185
|
+
$test_event_run_hash = {}
|
186
|
+
|
187
|
+
# helper method, invoked in Event::run spec
|
188
|
+
def test_event_run_method(gem, first, second, third)
|
189
|
+
$test_event_run_hash[:gem] = gem
|
190
|
+
$test_event_run_hash[:first] = first
|
191
|
+
$test_event_run_hash[:second] = second
|
192
|
+
$test_event_run_hash[:third] = third
|
193
|
+
end
|