Permalink
Browse files

Move bin scripts to rakefile

  • Loading branch information...
1 parent e8c7b9a commit 8edf479842508f5c10e8fa02996e84a3cd12bfc0 @alloy alloy committed Dec 3, 2010
Showing with 24 additions and 60 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 INSTALL
  3. +19 −0 Rakefile
  4. +0 −16 bin/init
  5. +0 −2 bin/macruby_bugmash_bot
  6. +0 −37 bin/update-active-tickets
  7. +2 −3 lib/macruby_bugmash_bot/db.rb
View
1 .gitignore
@@ -1 +1,2 @@
*.swp
+data
View
4 INSTALL
@@ -1,4 +1,4 @@
* git update --init
* sudo gem19 install sequel sqlite3-ruby
-* ruby19 ./bin/init
-* ruby19 ./bin/update-active-tickets
+* rake init
+* rake update_open_tickets
View
19 Rakefile
@@ -0,0 +1,19 @@
+$:.unshift File.expand_path("../lib", __FILE__)
+
+desc "Initialize the db"
+task :init do
+ require "macruby_bugmash_bot/db"
+ mkdir_p(File.dirname(DB.db_path))
+ DB.create!
+end
+
+desc "Update the open tickets"
+task :update_open_tickets do
+ require "macruby_bugmash_bot/db"
+ DB.update_open_tickets!
+end
+
+desc "Run the bot"
+task :run do
+ require "macruby_bugmash_bot"
+end
View
16 bin/init
@@ -1,16 +0,0 @@
-require "fileutils"
-require "rubygems"
-require "sequel"
-
-db = File.expand_path('../../data/db.sqlite3', __FILE__)
-FileUtils.mkdir_p(File.dirname(db))
-DB = Sequel.sqlite(db)
-
-DB.create_table :tickets do
- Integer :id, :primary_key => true
- String :link
- String :summary, :text => true
- String :assigned_to
- FalseClass :marked_for_review
- FalseClass :closed
-end
View
2 bin/macruby_bugmash_bot
@@ -1,2 +0,0 @@
-$:.unshift File.expand_path("../../lib", __FILE__)
-require "macruby_bugmash_bot"
View
37 bin/update-active-tickets
@@ -1,37 +0,0 @@
-require "fileutils"
-require "rubygems"
-require "sequel"
-
-$:.unshift File.expand_path("../../vendor/simple-rss/lib", __FILE__)
-require "simple-rss"
-
-db = File.expand_path('../../data/db.sqlite3', __FILE__)
-FileUtils.mkdir_p(File.dirname(db))
-DB = Sequel.sqlite(db)
-
-class Ticket < Sequel::Model
-end
-
-#fixture = File.expand_path('../../spec/fixtures/trac_active_tickets_rss.xml', __FILE__)
-fixture = File.expand_path('../../spec/fixtures/trac_active_tickets_rss-minus-19-and-81.xml', __FILE__)
-raw_feed = File.read(fixture)
-
-rss = SimpleRSS.parse(raw_feed)
-ids = Ticket.filter(:closed => false).select(:id).all.map(&:id)
-seen = []
-
-rss.entries.each do |entry|
- id = File.basename(entry[:link]).to_i
- seen << id
- unless Ticket.filter(:id => id).first
- puts "does not exist!"
- Ticket.insert(:id => id, :link => entry[:link], :summary => CGI.unescapeHTML(entry[:title]), :marked_for_review => false, :closed => false)
- end
-end
-
-removed = ids - seen
-p removed
-
-removed.each do |id|
- Ticket.filter(:id => id).update(:closed => true)
-end
View
5 lib/macruby_bugmash_bot/db.rb
@@ -10,15 +10,14 @@
class DB
def self.db_path
- db = File.expand_path('../../data/db.sqlite3', __FILE__)
+ db = File.expand_path('../../../data/db.sqlite3', __FILE__)
end
def self.connection
@db ||= Sequel.sqlite(db_path)
end
def self.create!
- puts "CREATE #{db_path}"
connection.create_table :users do
primary_key :id
String :name
@@ -80,7 +79,7 @@ def self.random_open_ticket
OPEN_TICKETS_RSS_FEED = URI.parse("http://www.macruby.org/trac/query?status=new&status=reopened&format=rss&order=priority&col=id&col=summary&col=status&col=time&milestone=%21MacRuby+1.0&milestone=%21MacRuby+Later")
def self.raw_open_tickets_feed
- Net::HTTP.get(ACTIVE_TICKETS_RSS_FEED)
+ Net::HTTP.get(OPEN_TICKETS_RSS_FEED)
rescue Exception => e
# obviously this is a bad thing to do, but I really don't want the bot to break this weekend due to HTTP problems...
puts "[!] FETCHING THE MACRUBY TICKET FEED FAILED DUE TO: #{e.message}\n\t#{e.backtrace.join("\n\t")}"

0 comments on commit 8edf479

Please sign in to comment.