-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
94 lines (72 loc) · 2.9 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'json'
require 'yaml'
require 'erb'
require 'logger'
require 'sinatra/activerecord/rake'
require 'puppet_community_data/application'
require "bundler/gem_tasks"
desc "Setup the database connection environment"
task :environment do
ENV['RACK_ENV'] ||= 'production'
rack_env = ENV['RACK_ENV']
# Make sure heroku logging works
STDOUT.sync = true
STDERR.sync = true
logger = Logger.new(STDOUT)
# Configure the ActiveRecord library to use heroku compatible STDERR logging.
ActiveRecord::Base.logger = logger.clone
# Heroku overwrites our database.yml file with an ERB tempalte which
# populates the database connection information automatically. We need to
# make sure to parse the file as ERB and not YAML directly.
dbconfig = YAML.load(ERB.new(File.read('config/database.yml')).result)
logger.debug("config/database.yml is #{JSON.generate(dbconfig)}")
# establish_connection is what actually connects to the database server.
ActiveRecord::Base.establish_connection(dbconfig[rack_env])
end
namespace :db do
# This will use the migration as implemented in ActiveRecordTasks
task :migrate => :environment
task :rollback => :environment
end
namespace :job do
desc "Import pull requests into the DB if it's Sunday"
task :import_if_sunday => :environment do |t|
logger = Logger.new(STDOUT)
if not Date.today.sunday?
logger.debug("Data not imported since today is not Sunday")
Kernel.exit(true)
end
repo_names = ['puppetlabs/puppet-strings','puppetlabs/puppetlabs-stdlib','puppetlabs/puppetlabs-concat','puppetlabs/puppetlabs-apt']
app = PuppetCommunityData::Application.new
app.setup_environment
app.generate_repositories(repo_names)
app.write_pull_requests_to_database
end
desc "Import pull requests into the DB"
task :import => :environment do |t|
repo_names = ['puppetlabs/puppet-strings','puppetlabs/puppetlabs-stdlib','puppetlabs/puppetlabs-concat','puppetlabs/puppetlabs-apt']
app = PuppetCommunityData::Application.new
app.setup_environment
app.generate_repositories(repo_names)
app.write_pull_requests_to_database
end
desc "Import pull requests for a single specified repo into the DB"
task :import_single_repo, [:repo_name] => :environment do |t, args|
app = PuppetCommunityData::Application.new
app.setup_environment
app.generate_repositories([args[:repo_name]])
app.write_pull_requests_to_database
end
desc "Import pull requests for a single specified repo into the DB if it's Sunday"
task :import_single_repo_if_sunday, [:repo_name] => :environment do |t, args|
logger = Logger.new(STDOUT)
if not Date.today.sunday?
logger.debug("Data not imported since today is not Sunday")
Kernel.exit(true)
end
app = PuppetCommunityData::Application.new
app.setup_environment
app.generate_repositories([args[:repo_name]])
app.write_pull_requests_to_database
end
end