1+ module Shift
2+ module BuiltIn
3+ class GithubCommunity
4+
5+ class UnknownAction < ShiftError
6+ end
7+
8+ class ValidationError < ShiftErrors
9+ end
10+
11+ def self . execute ( arguments )
12+ raise UnknownAction . new ( { message : "You should provide a valid action." } ) unless !arguments [ 0 ] . nil?
13+ case arguments [ 0 ]
14+ when :validate
15+ GithubCommunity . validate
16+ else
17+ raise UnknownAction . new ( { message : "Unknown action: #{ arguments [ 0 ] } ." } )
18+ end
19+ end
20+
21+ def self . validate
22+ errors = [ ]
23+ errors . push ( { severity : :error , message : "README.md is missing." } ) if ! File . exists? ( "README.md" )
24+ GithubCommunity . validate_markdown ( "README.md" , errors ) if File . exists? ( "README.md" )
25+ errors . push ( { severity : :error , message : "CONTRIBUTING.md is missing." } ) if ! File . exists? ( "CONTRIBUTING.md" )
26+ GithubCommunity . validate_markdown ( "CONTRIBUTING.md" , errors ) if File . exists? ( "CONTRIBUTING.md" )
27+ errors . push ( { severity : :warning , message : "MANIFESTO.md is missing." } ) if ! File . exists? ( "MANIFESTO.md" )
28+ GithubCommunity . validate_markdown ( "MANIFESTO.md" , errors ) if File . exists? ( "MANIFESTO.md" )
29+ errors . push ( { severity : :warning , message : "LICENSE is missing." } ) if ! File . exists? ( "LICENSE" )
30+ errors . push ( { severity : :warning , message : "CODE_OF_CONDUCT.md is missing." } ) if ! File . exists? ( "CODE_OF_CONDUCT.md" )
31+ GithubCommunity . validate_markdown ( "CODE_OF_CONDUCT.md" , errors ) if File . exists? ( "CODE_OF_CONDUCT.md" )
32+ errors . push ( { severity : :error , message : ".github is missing." } ) if ! Dir . exist? ( ".github" )
33+ errors . push ( { severity : :error , message : "ISSUE_TEMPLATE is missing." } ) if ( ( ! Dir . exist? ( ".github/ISSUE_TEMPLATE" ) || Dir . empty? ( ".github/ISSUE_TEMPLATE" ) ) &&
34+ ( ! Dir . exist? ( ".github/issue_template" ) || Dir . empty? ( ".github/issue_template" ) ) &&
35+ ( ! File . exists? ( ".github/ISSUE_TEMPLATE.md" ) ) &&
36+ ( ! File . exists? ( ".github/issue_template.md" ) ) )
37+ errors . push ( { severity : :error , message : "PULL_REQUEST_TEMPLATE is missing." } ) if ( ( ! Dir . exist? ( ".github/PULL_REQUEST_TEMPLATE" ) || Dir . empty? ( ".github/PULL_REQUEST_TEMPLATE" ) ) &&
38+ ( ! Dir . exist? ( ".github/pull_request_template" ) || Dir . empty? ( ".github/pull_request_template" ) ) &&
39+ ( ! File . exists? ( ".github/PULL_REQUEST_TEMPLATE.md" ) ) &&
40+ ( ! File . exists? ( ".github/pull_request_template.md" ) ) )
41+ raise ValidationError . new ( errors ) if errors . count > 0
42+ end
43+
44+ private
45+
46+ def self . validate_markdown ( file_path , errors )
47+ begin
48+ BuiltIn ::Markdown . validate ( file_path )
49+ rescue MarkdownError => markdown_error
50+ errors . push ( { severity : :error , message : markdown_error . message } )
51+ end
52+ end
53+ end
54+ end
55+ end
0 commit comments