This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Rakefile
143 lines (121 loc) · 4.25 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
require 'rake'
require 'gepetto_hooks'
require 'benchmark'
require 'erb'
require 'sinatra/activerecord/rake'
require 'puppet_labs/pull_request_app'
require 'delayed/tasks'
require 'puppet_labs/webhook'
require 'rest_client'
task :default => :help
desc 'List tasks (rake -T)'
task :help do
sh 'rake -T'
end
# Setup the environment for the application
task :environment do
PuppetLabs::Webhook.setup_environment(ENV['RACK_ENV'])
end
desc "IRB REPL Shell"
task :shell => :environment do
require 'irb'
ARGV.clear
IRB.start
end
task :pry => :environment do
require 'pry'
binding.pry
end
namespace :db do
namespace :pg do
desc "Create the database"
task :create => :environment do
ar_dbconfig = PuppetLabs::Webhook.dbconfig(ENV['RACK_ENV'])
# drop the old database if it exists
ActiveRecord::Base.connection.drop_database ar_dbconfig['database']
ActiveRecord::Base.connection.create_database ar_dbconfig['database']
puts "Created empty database #{ar_dbconfig['database']}"
end
end
desc "Migrate the database"
task :migrate => :environment do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate("db/migrate")
end
end
namespace :api do
desc "Run the server using foreman form the Heroku toolbelt"
task :run do
sh 'foreman start'
end
desc "Submit a fake pull request"
task(:pull_request) do
sh 'curl -i -H "Content-Type: application/json" --data "$(cat spec/unit/fixtures/example_pull_request.json)" http://localhost:5000/event/github/'
end
desc "Submit a fake issue"
task(:issue) do
sh 'curl -i -H "Content-Type: application/json" --data "$(cat spec/unit/fixtures/example_issue.json)" http://localhost:5000/event/github/'
end
end
desc "Use watchr to auto test"
task :watchr do
sh 'bundle exec watchr spec/watchr.rb'
end
desc "Run a web server with documentation"
task :apidoc do
sh 'bundle exec yard server --reload'
end
namespace :jobs do
desc "Run a delayed job worker quietly"
task :worksilent => :environment do
Delayed::Worker.new(:min_priority => ENV['MIN_PRIORITY'],
:max_priority => ENV['MAX_PRIORITY'],
:queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','),
:quiet => true).start
end
desc "Update the finished card summary (uses GITHUB_SUMMARY_GIST_ID,TRELLO_FINISHED_LIST_ID,SUMMARY_TEMPLATE_URL)"
task :summary => :environment do
puts "Summarizing completed cards..."
job = PuppetLabs::Trello::TrelloSummaryJob.new(:template_url => ENV['SUMMARY_TEMPLATE_URL'])
summary_time = Benchmark.measure do
job.perform
end
puts "summary_time_seconds=#{summary_time.real}"
puts "gist_url=#{job.gist_url}"
end
end
namespace :import do
desc "Import existing PRs from a GitHub repo (use REPO=puppetlabs/puppet, optionally PR=123)"
task :prs => :environment do
url = "https://api.github.com/repos/#{ENV['REPO']}/pulls"
url << '/' << ENV['PR'] if ENV['PR']
resource = RestClient::Resource.new(url, :user => ENV['GITHUB_ACCOUNT'], :password => ENV['GITHUB_TOKEN'])
response = JSON.parse(resource.get)
response = [response] if ENV['PR']
response.reverse.each do |pr|
queued = PuppetLabs::Github::PullRequestController.new(:pull_request => PuppetLabs::Github::PullRequest.from_data(pr)).run
raise StandardError, "Failed to queue PR##{pr.number}: #{queued.inspect}" unless queued[0].to_s[0] == '2'
end
end
desc "Import existing pull requests in the foreground"
task :foreground => :environment do
url = "https://api.github.com/repos/#{ENV['REPO']}/pulls"
url << '/' << ENV['PR'] if ENV['PR']
resource = RestClient::Resource.new(url, :user => ENV['GITHUB_ACCOUNT'], :password => ENV['GITHUB_TOKEN'])
response = JSON.parse(resource.get)
response = [response] if ENV['PR']
response.reverse.each do |data|
pull_request = PuppetLabs::Github::PullRequest.from_data(data)
jira = PuppetLabs::Jira::PullRequestHandler.new
jira.pull_request = pull_request
jira.perform
end
end
end
desc "Run the examples in spec/"
task :spec do
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
end