forked from github/github-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
67 lines (59 loc) · 1.89 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
require 'rubygems'
require 'bundler/setup'
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
namespace :services do
task :load do
require File.expand_path("../config/load", __FILE__)
end
desc "Writes JSON config to FILE || config/services.json, Docs to DOCS"
task :build => [:config, :docs]
desc "Writes a JSON config to FILE || config/services.json"
task :config => :load do
file = ENV["FILE"] || default_services_config
services = []
Service.load_services
Service.services.each do |svc|
services << {:name => svc.hook_name, :events => svc.default_events, :supported_events => svc.supported_events,
:title => svc.title, :schema => svc.schema}
end
services.sort! { |x, y| x[:name] <=> y[:name] }
data = {
:metadata => { :generated_at => Time.now.utc },
:services => services
}
puts "Writing config to #{file}"
File.open file, 'w' do |io|
io << Yajl.dump(data, :pretty => true)
end
end
desc "Writes Docs to DOCS"
task :docs => :load do
dir = ENV['DOCS'] || default_docs_dir
docs = Dir[File.expand_path("../docs/*", __FILE__)]
docs.each do |path|
name = File.basename(path)
next if GitHubDocs.include?(name)
new_name = dir.include?('{name}') ? dir.sub('{name}', name) : File.join(dir, name)
new_dir = File.dirname(new_name)
FileUtils.mkdir_p(new_dir)
puts "COPY #{path} => #{new_name}"
FileUtils.cp(path, new_name)
end
end
require 'set'
GitHubDocs = Set.new(%w(github_payload payload_data))
def base_github_path
ENV['GH_PATH'] || "#{ENV['HOME']}/github/github"
end
def default_services_config
"#{base_github_path}/config/services.json"
end
def default_docs_dir
"#{base_github_path}/app/views/edit_repositories/hooks/_{name}.erb"
end
end