forked from github/developer.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
137 lines (112 loc) · 3.66 KB
/
Rakefile
File metadata and controls
137 lines (112 loc) · 3.66 KB
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
require 'nanoc3/tasks'
require './lib/resources'
require 'curb'
require 'yajl'
require 'json-compare'
require 'hashdiff'
desc "Compile the site"
task :compile do
`nanoc compile`
end
# prompt user for a commit message; default: HEAD commit 1-liner
def commit_message
last_commit = `git log -1 --pretty=format:"%s"`.chomp.strip
last_commit = 'Publishing developer content to GitHub pages.' if last_commit == ''
print "Enter a commit message (default: '#{last_commit}'): "
STDOUT.flush
mesg = STDIN.gets.chomp.strip
mesg = last_commit if mesg == ''
mesg.gsub(/'/, '') # to allow this to be handed off via -m '#{message}'
end
desc "Publish to http://developer.github.com"
task :publish => [:clean] do
mesg = commit_message
FileUtils.rm_r('output') if File.exist?('output')
sh "nanoc compile"
ENV['GIT_DIR'] = File.expand_path(`git rev-parse --git-dir`.chomp)
old_sha = `git rev-parse refs/remotes/origin/gh-pages`.chomp
Dir.chdir('output') do
ENV['GIT_INDEX_FILE'] = gif = '/tmp/dev.gh.i'
ENV['GIT_WORK_TREE'] = Dir.pwd
File.unlink(gif) if File.file?(gif)
`git add -A`
tsha = `git write-tree`.strip
puts "Created tree #{tsha}"
if old_sha.size == 40
csha = `git commit-tree #{tsha} -p #{old_sha} -m '#{mesg}'`.strip
else
csha = `git commit-tree #{tsha} -m '#{mesg}'`.strip
end
puts "Created commit #{csha}"
puts `git show #{csha} --stat`
puts "Updating gh-pages from #{old_sha}"
`git update-ref refs/heads/gh-pages #{csha}`
`git push origin gh-pages`
end
end
task :api_test do
API_URL = "https://api.github.com"
# missing tag, team ?
public_api = {
"FULL_USER" => "/users/octocat"
#{}"GIST" => "/users/octocat/gists",
# "TEMPLATES" => "/gitignore/template", implied correct, it's just an array
#{}"TEMPLATE" => "/gitignore/templates/C",
#{}"ORG" => "/users/gjtorikian/orgs",
#{}"FULL_ORG" => "/orgs/github",
#{}"PULL" => "/repos/octocat/Hello-World/pulls/1",
#{}"COMMIT" => "/repos/octocat/Hello-World/pulls/1/commits",
#{}"FILE" => "/repos/octocat/Hello-World/pulls/1/files",
#{}"FULL_REPO" => "/users/octocat/repos",
#{}"CONTRIBUTOR" => "/repos/octocat/Hello-World/contributors",
#{}"BRANCHES" => "/repos/octocat/Hello-World/branches",
#{}"BRANCH" => "/repos/octocat/Hello-World/branches/master"
}
auth_api = {
"ISSUE" => "",
"OAUTH_ACCESS" => ""
}
# adapted from https://gist.github.com/146844
class Hash
def deep_diff(b)
a = self
(a.keys | b.keys).inject({}) do |diff, k|
if a[k] != b[k]
if k == k
# no op
elsif a[k].respond_to?(:deep_diff) && b[k].respond_to?(:deep_diff)
diff[k] = a[k].deep_diff(b[k])
else
diff[k] = [a[k], b[k]]
end
end
diff
end
end
end
curler = Curl::Easy.new
curler.http_auth_types = :basic
password = File.read('.ghpassword').split(":")
curler.username = password[0]
curler.password = password[1]
public_api.each do |type, url|
curler.url = API_URL + url
curler.perform
doc_hash = JSON.parse(GitHub::Resources::json(type, true))
api_hash = Yajl::Parser.parse(curler.body_str)
puts "\n#{type}\n"
if api_hash.kind_of?(Array)
api_hash = api_hash[0]
end
if doc_hash.kind_of?(Array)
doc_hash = doc_hash[0]
end
diff = api_hash.deep_diff(doc_hash)
if diff.length > 0
puts "DANGER, DANGER, WILL ROBINSON! The following #{type} values are NOT documented: \n\n"
diff.each do |id|
puts "#{id} is new!"
end
end
end
end