forked from DataDog/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Checks
74 lines (66 loc) · 3.01 KB
/
Checks
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
require 'nokogiri'
check :no_api_keys do
self.output_filenames.each do |fn|
if match=File.read(fn).force_encoding("ISO-8859-1").encode("utf-8", replace: nil).match(/\b([0-9a-f]){32}(?<!9775a026f1ca7d1c6c5af9d94d9595a4)(?![0-9a-f])/)
self.add_issue("API Key in here!! - #{match}\nPlease use 9775a026f1ca7d1c6c5af9d94d9595a4 as the API Key", :subject => fn)
end
end
end
check :integration_format do
puts ""
formatoutput=""
overviewimage = Array.new
headings = Array.new
self.output_filenames.each do |fn|
missingfiles =""
if fn.include? "output/integration"
doc = File.open(fn) { |f| Nokogiri::HTML(f)}
integrationlocation = fn.sub('output', 'content').sub('/index.html', '')
pagetitle = doc.xpath("//h1[@id='pagetitle']/text()")
newhlevel = doc.xpath("//div[@id='pagecontent']")
if newhlevel.length > 0
#############
# New hlevel
#############
# Does the document have the right headings?
headings = doc.xpath("//div[@id='pagecontent']/h1").collect {|node| node.text.strip}
if headings.include? 'Overview'
if (headings & ['Configuration', 'Installation']).empty?
missingfiles += "\n - Missing Config or Installation section"
else
overviewimage = doc.xpath("//p[preceding::h1[@id='overview'] and following::h1[(@id='configuration') or (@id='installation')]]/img/@src")
# overviewimage = doc.xpath("//img[preceding::h1[contains(text(), 'Overview')] and following::h1[(contains(text(), 'Configuration')) or (contains(text(), 'Installation'))]]/@src")
if overviewimage.count == 0
missingfiles += "\n - Missing Overview Image"
end
end
else
missingfiles += "\n - Not Updated to New Integration Format"
end
else
#############
# Old hlevel
#############
missingfiles += "\n - Using old hlevel"
headings = doc.xpath("//div[@id='pagecontent']/h3").collect {|node| node.text.strip}
if headings.include? 'Overview'
if (headings & ['Configuration', 'Installation']).empty?
missingfiles += "\n - Missing Config or Installation section"
else
overviewimage = doc.xpath("//img[preceding::h3[contains(text(), 'Overview')] and following::h3[(contains(text(), 'Configuration')) or (contains(text(), 'Installation'))]]/@src")
if overviewimage.count == 0
missingfiles += "\n - Missing Overview Image"
end
end
else
missingfiles += "\n - Not Updated to New Integration Format"
end
end
if missingfiles.length > 0
formatoutput += "Format Issue: #{pagetitle} (#{integrationlocation}) #{missingfiles}\n"
end
end
end
File.open("fileformaterrors", 'w') {|file| file.write(formatoutput)}
puts "\033[31mThere are file format errors. Press \033[1mf\033[22m<enter> or look at \033[1mfileformaterrors\033[22m in your editor to see them."
end