aboutsummaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-23 18:18:57 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-29 18:49:34 +0200
commitd1a1409a0f5d6e9ecea2e942de2e87628ee15a67 (patch)
tree9c7ac878094a52e7eeb588af1754ae0c995a698d /lib/tasks
parentImproved way admins create questions (diff)
downloadrecruiting-webapp-d1a1409a0f5d6e9ecea2e942de2e87628ee15a67.tar.gz
recruiting-webapp-d1a1409a0f5d6e9ecea2e942de2e87628ee15a67.tar.bz2
recruiting-webapp-d1a1409a0f5d6e9ecea2e942de2e87628ee15a67.zip
Rake task prepare:lead_data
The task fetches Gentoo project leads data from gentoo.org and stores it in tmp/lead_data.yml
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/prepare.rake51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/tasks/prepare.rake b/lib/tasks/prepare.rake
index 4c05b07..f28826e 100644
--- a/lib/tasks/prepare.rake
+++ b/lib/tasks/prepare.rake
@@ -1,4 +1,5 @@
require "ftools"
+require "rexml/document"
desc "Prepare database and configuration files to run tests (accepts options used by prepare:config and seed option)"
opt = ENV.include?('seed') ? ['db:seed'] : []
@@ -26,4 +27,54 @@ namespace :prepare do
File.copy('doc/config/config.yml', 'config/config.yml')
end
+
+ desc "Prepare project Lead data"
+ task :lead_data => :environment do
+
+ # Fetch xml document from uri. Collect all elements with name equal to
+ # name parameter and array containing them (and only them).
+ def get_all_tags_with_name(uri, name)
+ raw_data = Net::HTTP.get_response(URI.parse(uri)).body
+ project_data = REXML::Document.new(raw_data)
+ projects_el = project_data.children
+
+ removed_sth = true # So it'll enter loop first time
+ while removed_sth # Repeat until there is nothing left to remove
+ removed_sth = false
+ projects_el = projects_el.collect do |x| # Check all elements
+ if x.respond_to?(:name) && x.name == name # If element has name and
+ # it's what we're looking
+ # for let it stay.
+ x
+ else
+ removed_sth = true # otherwise remove it
+ x.respond_to?(:children) ? x.children : nil
+ end
+ end
+
+ # Remove nils & flatten array
+ if removed_sth
+ projects_el.flatten!
+ projects_el.compact!
+ end
+ end
+ projects_el
+ end
+
+ devs = []
+ projects = get_all_tags_with_name('http://www.gentoo.org/proj/en/metastructure/gentoo.xml?passthru=1', 'subproject')
+
+ for proj in projects
+ devs += get_all_tags_with_name("http://www.gentoo.org#{proj.attribute('ref').to_s}?passthru=1", 'dev')
+ end
+
+ leads = devs.collect{ |x| x if /lead/i.match(x.attribute('role').to_s) }.compact
+ lead_nicks = leads.collect{ |x| x.text }
+
+ User.transaction do
+ for user in User.all
+ user.update_attribute(:project_lead, lead_nicks.include?(user.nick))
+ end
+ end
+ end
end