This repository was archived by the owner on Jun 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.rake
95 lines (87 loc) · 3.18 KB
/
test.rake
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
# coding: utf-8
desc "Test weekly"
task "test-weekly", [:date] do |t, args|
args.with_defaults(:date => "all")
weekly_date = args[:date]
weekly_date = find_latest_weekly.split("-weekly.md").at(0) if weekly_date == "latest"
Dir.foreach("_weekly") do |weekly_file|
if weekly_file == "." || weekly_file == ".."
next
end
if weekly_date != "all" && weekly_file != "#{weekly_date}-weekly.md"
next
end
puts "[INFO] Checking #{weekly_file}...".green
content = YAML.load(open("_weekly/#{weekly_file}").read)
title_record = Hash.new
comment_record = Hash.new
link_record = Hash.new
content["articles"].each_with_index do |article, index|
article["title"] = "" if !article.has_key?("title")
article["link"] = "" if !article.has_key?("link")
article["referrer"] = "" if !article.has_key?("referrer")
article["comment"] = "" if !article.has_key?("comment")
article["tags"] = "" if !article.has_key?("tags")
article_info = {
:file_name => weekly_file,
:index => index,
:title => article["title"],
:link => article["link"],
:referrer => article["referrer"],
:comment => article["comment"],
:tags => article["tags"]
}
# check empty
if article["title"].empty?
show_message_on_article("ERROR", "Empty title of an article", article_info, :title)
exit 1
end
if article["link"].empty?
puts "[ERROR] Empty link within a weekly found:"
show_message_on_article("ERROR", "Empty link of an article", article_info, :link)
exit 1
end
if article["comment"].empty?
show_message_on_article("WARNING", "Empty comment of an article", article_info, :comment)
end
if article["referrer"].empty?
show_message_on_article("WARNING", "Empty referrer of an article", article_info, :referrer)
end
if article["tags"].empty?
show_message_on_article("WARNING", "Empty tags of an article", article_info, :tags)
end
# check title duplicate
if title_record.has_key? article["title"]
show_message_on_article("ERROR", "Duplicated title within a weekly", article_info, :title)
exit 1
end
title_record[article["title"]] = 1
# check link duplicate
if link_record.has_key? article["link"]
show_message_on_article("ERROR", "Duplicated link within a weekly", article_info, :link)
exit 1
end
link_record[article["link"]] = 1
# check comment duplicate
if comment_record.has_key? article["comment"]
show_message_on_article("ERROR", "Duplicated comment within a weekly", article_info, :comment)
exit 1
end
comment_record[article["comment"]] = 1
# check tags duplicate
tags_record = Hash.new
article["tags"].each do |tag|
if tags_record.has_key? tag
show_message_on_article("ERROR", "Duplicated tags found", article_info, :tags)
exit 1
end
if tag.empty?
show_message_on_article("WARNING", "Empty tags found", article_info, :tags)
else
tags_record[tag] = 1
end
end
end
end
puts "Success."
end