Move all config into yaml file

This commit is contained in:
Brandon Keepers
2017-11-08 08:25:20 -06:00
parent 3a4289218d
commit ed47d7468f
2 changed files with 48 additions and 41 deletions

View File

@@ -1,41 +1,51 @@
# Each piece of content has YAML front matter with these properties:
title:
type: String
required: true
banned_words:
- GitHub App # They're all GitHub Apps
- bot # TODO: link to docs about why bot is not preferred
- automatically # They're all automatic
- probot # Now you're just name dropping
description:
type: String
required: true
exceptions:
bot: ["sentiment-bot"]
slug:
type: String
required: true
fields:
title:
type: String
required: true
screenshots:
type: Array
required: true
description:
type: String
required: true
authors:
type: Array
required: true
slug:
type: String
required: true
repository:
type: String
required: true
screenshots:
type: Array
required: true
host:
type: String
required: true
authors:
type: Array
required: true
# All these fields are generated by `scripts/sync-data`
stars:
type: Numeric
repository:
type: String
required: true
installations:
type: Numeric
host:
type: String
required: true
organizations:
type: Array
# All these fields are generated by `scripts/sync-data`
stars:
type: Numeric
updated:
type: String
installations:
type: Numeric
organizations:
type: Array
updated:
type: String

View File

@@ -4,30 +4,27 @@ require "minitest/autorun"
require "net/http"
describe "lint test" do
BANNED_WORDS = Regexp.new('\b(' + [
"GitHub App", # They're all GitHub Apps
"bot", # TODO: link to docs about why bot is not preferred
"automatically", # They're all automatic
"probot", # Now you're just name dropping
].join('|') + ')\b', Regexp::IGNORECASE | Regexp::MULTILINE)
FRONTMATTER = SafeYAML.load_file("test/frontmatter.yml")
BANNED_WORDS = Regexp.new('\b(' +
FRONTMATTER["banned_words"].join('|') +
')\b', Regexp::IGNORECASE | Regexp::MULTILINE)
EXCEPTIONS = {
"bot" => ["sentiment-bot"]
}
FIELDS = SafeYAML.load_file("test/frontmatter.yml")
Dir.glob("_apps/*.md").each do |path|
describe path do
# Load frontmatter
data = SafeYAML.load_file(path)
it "does not have extraneous fields" do
extra_fields = data.keys - FIELDS.keys
extra_fields = data.keys - FRONTMATTER["fields"].keys
assert extra_fields.empty?, "Unexpected metadata: #{extra_fields.inspect}"
end
FIELDS.each do |name, attrs|
FRONTMATTER["fields"].each do |name, attrs|
if attrs["required"]
it "${name} is required" do
assert data.key?(name), "#{name} is required"
@@ -49,7 +46,7 @@ describe "lint test" do
it "does not use banned words" do
%w(title description slug).each do |field|
match = data[field].match(BANNED_WORDS)
if match && !Array(EXCEPTIONS[match[1].downcase]).include?(data["slug"])
if match && !Array(FRONTMATTER["exceptions"][match[1].downcase]).include?(data["slug"])
assert !match, "`#{match[1]}` should not be used in #{field}"
end
end